yaicli 0.6.3__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yaicli
3
- Version: 0.6.3
3
+ Version: 0.7.0
4
4
  Summary: A simple CLI tool to interact with LLM
5
5
  Project-URL: Homepage, https://github.com/belingud/yaicli
6
6
  Project-URL: Repository, https://github.com/belingud/yaicli
@@ -208,7 +208,7 @@ License: Apache License
208
208
  See the License for the specific language governing permissions and
209
209
  limitations under the License.
210
210
  License-File: LICENSE
211
- Keywords: ai,ai-assistant,ai-chat,ai-interaction,anthropic,chatgpt,claude,cli,cohere,command-line,completion,console-application,conversation,gemini,gpt,groq,inference,interactive,language-model,llm,llms,mistral,nlp,openai,prompt,python-tool,shell-integration,terminal,terminal-interface,text-generation
211
+ Keywords: ai,ai-assistant,ai-chat,ai-interaction,anthropic,chatglm,chatgpt,claude,cli,cohere,command-line,completion,console-application,conversation,deepseek,gemini,gpt,groq,huggingface,inference,interactive,language-model,llm,llms,mistral,modelscope,nlp,ollama,openai,prompt,python-tool,sambanova,shell-integration,siliconflow,terminal,terminal-interface,text-generation,vertexai,xai
212
212
  Classifier: License :: OSI Approved :: Apache Software License
213
213
  Classifier: Operating System :: OS Independent
214
214
  Classifier: Programming Language :: Python :: 3
@@ -226,6 +226,7 @@ Requires-Dist: typer>=0.16.0
226
226
  Provides-Extra: all
227
227
  Requires-Dist: cohere>=5.15.0; extra == 'all'
228
228
  Requires-Dist: google-genai>=1.20.0; extra == 'all'
229
+ Requires-Dist: huggingface-hub>=0.33.0; extra == 'all'
229
230
  Requires-Dist: ollama>=0.5.1; extra == 'all'
230
231
  Requires-Dist: volcengine-python-sdk>=3.0.15; extra == 'all'
231
232
  Provides-Extra: cohere
@@ -234,6 +235,8 @@ Provides-Extra: doubao
234
235
  Requires-Dist: volcengine-python-sdk>=3.0.15; extra == 'doubao'
235
236
  Provides-Extra: gemini
236
237
  Requires-Dist: google-genai>=1.20.0; extra == 'gemini'
238
+ Provides-Extra: huggingface
239
+ Requires-Dist: huggingface-hub>=0.33.0; extra == 'huggingface'
237
240
  Provides-Extra: ollama
238
241
  Requires-Dist: ollama>=0.5.1; extra == 'ollama'
239
242
  Description-Content-Type: text/markdown
@@ -262,6 +265,7 @@ generate and execute shell commands, or get quick answers without leaving your w
262
265
  > [!NOTE]
263
266
  > YAICLI is actively developed. While core functionality is stable, some features may evolve in future releases.
264
267
 
268
+ > We support MCP since v0.7.0!
265
269
  > We support Function Call since v0.5.0!
266
270
 
267
271
  ## ✨ Key Features
@@ -326,14 +330,8 @@ Yaicli has several optional dependencies group, you can copy below commands to i
326
330
  # install all denpendencies
327
331
  pip install 'yaicli[all]'
328
332
 
329
- # install with ollama support
330
- pip instsall 'yaicli[ollama]'
331
-
332
- # install with cohere support
333
- pip install 'yaicli[cohere]'
334
-
335
- # install with doubao support
336
- pip install 'yaicli[doubao]'
333
+ # install with specific provider support
334
+ pip instsall 'yaicli[ollama,cohere,doubao,huggingface,gemini]'
337
335
  ```
338
336
 
339
337
  Install by `uv`.
@@ -342,14 +340,8 @@ Install by `uv`.
342
340
  # install all denpendencies
343
341
  uv tool install 'yaicli[all]'
344
342
 
345
- # install with ollama support
346
- uv tool instsall 'yaicli[ollama]'
347
-
348
- # install with cohere support
349
- uv tool install 'yaicli[cohere]'
350
-
351
- # install with doubao support
352
- uv tool install 'yaicli[doubao]'
343
+ # install with specific provider support
344
+ uv tool instsall 'yaicli[ollama,cohere,doubao,huggingface,gemini]'
353
345
  ```
354
346
 
355
347
  ### Install from Source
@@ -360,6 +352,31 @@ cd yaicli
360
352
  pip install .
361
353
  ```
362
354
 
355
+ ## Buildin Supported Providers
356
+
357
+ - AI21
358
+ - Chatglm
359
+ - Chuts
360
+ - Cohere
361
+ - Cohere Badrock
362
+ - Cohere Sagemaker
363
+ - Deepseek
364
+ - Doubao
365
+ - Gemini
366
+ - Groq
367
+ - Huggingface
368
+ - Minimax
369
+ - ModelScope
370
+ - Ollama
371
+ - Openai
372
+ - Sambanova
373
+ - Siliconflow
374
+ - Targon
375
+ - Vertex ai
376
+ - X AI
377
+ - Yi
378
+ - Unlimited OpenAI-compatible providers
379
+
363
380
  ## ⚙️ Configuration
364
381
 
365
382
  YAICLI uses a simple configuration file to store your preferences and API keys.
@@ -422,6 +439,10 @@ ROLE_MODIFY_WARNING=true
422
439
  ENABLE_FUNCTIONS=true
423
440
  # Set to false to disable showing function output in the response
424
441
  SHOW_FUNCTION_OUTPUT=true
442
+
443
+ # MCP settings
444
+ ENABLE_MCP=false
445
+ SHOW_MCP_OUTPUT=false
425
446
  ```
426
447
 
427
448
  ### Configuration Options Reference
@@ -452,7 +473,10 @@ SHOW_FUNCTION_OUTPUT=true
452
473
  | `MAX_SAVED_CHATS` | Max saved chats | `20` | `YAI_MAX_SAVED_CHATS` |
453
474
  | `ROLE_MODIFY_WARNING` | Warn user when modifying role | `true` | `YAI_ROLE_MODIFY_WARNING` |
454
475
  | `ENABLE_FUNCTIONS` | Enable function calling | `true` | `YAI_ENABLE_FUNCTIONS` |
455
- | `SHOW_FUNCTION_OUTPUT` | Show function output in response | `true` | `YAI_SHOW_FUNCTION_OUTPUT` |
476
+ | `SHOW_FUNCTION_OUTPUT` | Show function output when calling function | `true` | `YAI_SHOW_FUNCTION_OUTPUT` |
477
+ | `ENABLE_MCP` | Enable MCP tools | `false` | `YAI_ENABLE_MCP` |
478
+ | `SHOW_MCP_OUTPUT` | Show MCP output when calling mcp | `true` | `YAI_SHOW_MCP_OUTPUT` |
479
+
456
480
 
457
481
  ### LLM Provider Configuration
458
482
 
@@ -497,6 +521,15 @@ API_KEY=
497
521
  MODEL=gpt-4o
498
522
  ```
499
523
 
524
+ Extra params:
525
+
526
+ ```ini
527
+ # REASONING_EFFORT: [high, midium, low]
528
+ REASONING_EFFORT=
529
+ ```
530
+
531
+ See official for more details: https://platform.openai.com/docs/guides/reasoning?api-mode=chat
532
+
500
533
  #### Deepseek
501
534
 
502
535
  ```ini
@@ -513,6 +546,50 @@ API_KEY=
513
546
  MODEL=deepseek/deepseek-chat-v3-0324
514
547
  ```
515
548
 
549
+ #### Gemini
550
+
551
+ Basic config:
552
+
553
+ ```ini
554
+ PROVIDER=gemini
555
+ API_KEY=
556
+ MODEL=gemini-2.5-flash
557
+ ```
558
+
559
+ Extra params:
560
+
561
+ ```ini
562
+ TOP_K=
563
+ PRESENCE_PENALTY=
564
+ FREQUENCY_PENALTY=
565
+ SEED=
566
+ THINKING_BUDGET=
567
+ API_VERSION=
568
+ BASE_URL=
569
+ ```
570
+
571
+ #### Vertex AI
572
+
573
+ ```ini
574
+ PROVIDER=vertexai
575
+ MODEL=gemini-2.5-flash
576
+ PROJECT=
577
+ LOCATION=
578
+ ```
579
+
580
+ #### Huggingface
581
+
582
+ Default `HF_PROVIDER` is `auto`.
583
+
584
+ ```ini
585
+ HF_PROVIDER=auto
586
+ PROVIDER=huggingface
587
+ API_KEY=
588
+ MODEL=deepseek-ai/DeepSeek-R1-0528
589
+ ```
590
+
591
+ See official docs for `HF_PROVIDER`: https://huggingface.co/docs/inference-providers/index
592
+
516
593
  #### Groq
517
594
 
518
595
  ```ini
@@ -537,6 +614,15 @@ API_KEY=
537
614
  MODEL=glm-4-plus
538
615
  ```
539
616
 
617
+ Extra params:
618
+
619
+ Check offcial docs: https://bigmodel.cn/dev/api/normal-model/glm-4
620
+
621
+ ```ini
622
+ # true or false
623
+ DO_SAMPLE=
624
+ ```
625
+
540
626
  #### Chutes
541
627
 
542
628
  ```ini
@@ -561,6 +647,16 @@ API_KEY=
561
647
  MODEL=DeepSeek-V3-0324
562
648
  ```
563
649
 
650
+ Only a few models support tool call as below:
651
+
652
+ - Meta-Llama-3.1-8B-Instruct
653
+ - Meta-Llama-3.1-405B-Instruct
654
+ - Meta-Llama-3.3-70B-Instruct
655
+ - Llama-4-Scout-17B-16E-Instruct
656
+ - DeepSeek-V3-0324
657
+
658
+ See official docs for more detail: https://docs.sambanova.ai/cloud/docs/capabilities/function-calling
659
+
564
660
  #### ModelScope
565
661
 
566
662
  ```ini
@@ -604,6 +700,45 @@ API_KEY=
604
700
  MODEL=command-a-03-2025
605
701
  ```
606
702
 
703
+ Check official docs: https://docs.cohere.com/docs/text-gen-quickstart
704
+
705
+ Support keys:
706
+
707
+ ```ini
708
+ ENVIRONMENT=
709
+ ```
710
+
711
+ For private deploy and Azure api, you need to set BASE_URL.
712
+
713
+ ```ini
714
+ PROVIDER=cohere
715
+ API_KEY=
716
+ MODEL=command-a-03-2025
717
+ BASE_URL=<YOUR_ENDPOINT>
718
+ ```
719
+
720
+ For Bedrock and Sagemaker cohere api, you have to set below keys:
721
+
722
+ See https://docs.cohere.com/docs/text-gen-quickstart.
723
+
724
+ ```ini
725
+ PROVIDER=cohere-bedrock
726
+ ; PROVIDER=cohere-sagemaker
727
+ API_KEY=
728
+ MODEL=command-a-03-2025
729
+
730
+ AWS_REGION=xx
731
+ AWS_ACCESS_KEY_ID=xx
732
+ AWS_SECRET_ACCESS_KEY=xx
733
+ AWS_SESSION_TOKEN=xx
734
+ ```
735
+
736
+ Note `MODEL` for Sagemaker should be endpoint name
737
+
738
+ ```ini
739
+ MODEL=<YOUR_ENDPOINT_NAME>
740
+ ```
741
+
607
742
  #### Doubao
608
743
 
609
744
  You have to install doubao dependencies, `pip install 'yaicli[doubao]'`
@@ -1127,6 +1262,83 @@ Thinking:
1127
1262
  Current directory size: 156M (using du -sh .).
1128
1263
  ```
1129
1264
 
1265
+ ### MCP
1266
+
1267
+ Add your MCP config in `~/.config/yaicli/mcp.json` (`C:\Users\<user>\.config\yaicli\mcp.json` on Windows.).
1268
+
1269
+ `--enable-mcp` option is corresponds to the configuration key `ENABLE_MCP`.
1270
+
1271
+ Example:
1272
+
1273
+ ```shell
1274
+ ai 'What is the latest exchange rate between the BTC and the US dollar?' --enable-mcp --show-mcp-output
1275
+
1276
+ Assistant:
1277
+
1278
+ @Mcp call: bing_search({"query": "latest exchange rate between BTC and US dollar"})
1279
+ ╭─ Mcp output ──────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
1280
+ │ [ │
1281
+ │ { │
1282
+ │ "id": "result_1751024997243_0", │
1283
+ │ "title": "BTC to USD - Bitcoin to US Dollar Conversion - Exchange Rates", │
1284
+ │ "link": "https://www.exchange-rates.org/converter/btc-usd", │
1285
+ │ "snippet": "11 小时之前 · 1 Bitcoin = 107,304 US Dollars as of June 27, 2025 03:00 AM UTC. You can get live exchange │
1286
+ │ rates between Bitcoin and US Dollars using exchange-rates.org, which aggregates …" │
1287
+ │ }, │
1288
+ │ { │
1289
+ │ "id": "result_1751024997245_1", │
1290
+ │ "title": "Live Bitcoin to US Dollars Exchange Rate - ₿ 1 …", │
1291
+ │ "link": "https://btc.currencyrate.today/usd", │
1292
+ │ "snippet": ".b_imgcap_altitle p strong,.b_imgcap_altitle .b_factrow strong{color:#767676}#b_results │
1293
+ │ .b_imgcap_altitle{line-height:22px}.b_hList img{display:block}..." │
1294
+ │ }, │
1295
+ │ { │
1296
+ │ "id": "result_1751024997246_2", │
1297
+ │ "title": "1 BTC to USD - Bitcoins to US Dollars Exchange Rate - Xe", │
1298
+ │ "link": "https://www.xe.com/currencyconverter/convert/?From=BTC&To=USD", │
1299
+ │ "snippet": "2025年6月15日 · Get the latest 1 Bitcoin to US Dollar rate for FREE with the original Universal Currency │
1300
+ │ Converter. Set rate alerts for to and learn more about Bitcoins and US Dollars from …" │
1301
+ │ }, │
1302
+ │ { │
1303
+ │ "id": "result_1751024997246_3", │
1304
+ │ "title": "BTC to USD Exchange Rates | Best Exchange Rates", │
1305
+ │ "link": "https://bestexchangerates.com/rates/btc-to-usd", │
1306
+ │ "snippet": "Bitcoin (BTC) to US dollar (USD) market data - latest interbank exchange rate, trend, chart & historic │
1307
+ │ rates. Sell BTC → Buy USD" │
1308
+ │ }, │
1309
+ │ { │
1310
+ │ "id": "result_1751024997247_4", │
1311
+ │ "title": "BTC to USD | Bitcoin to US Dollar - Investing.com", │
1312
+ │ "link": "https://www.investing.com/crypto/bitcoin/btc-usd", │
1313
+ │ "snippet": "Bitcoin Eyes 120k as Fed Rate Cuts Hopes Rise, US Dollar Falls to Multi-Year Lows BTC hovers around │
1314
+ │ 107.5k after attempts at 108k Fed rate cut optimism rises USD falls to its lowest level …" │
1315
+ │ } │
1316
+ │ ] │
1317
+ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
1318
+ Here are some current exchange rates for Bitcoin (BTC) to US Dollar (USD):
1319
+
1320
+ 1 Exchange-Rates.org:
1321
+ ₿1 Bitcoin = 💵107,304 US Dollars (as of June 27, 2025, 03:00 AM UTC).
1322
+ Link
1323
+ 2 BTC.CurrencyRate.Today:
1324
+ Live Bitcoin to US Dollars exchange rate.
1325
+ Link
1326
+ 3 Xe.com:
1327
+ Latest conversion rate and information about Bitcoin to US Dollars.
1328
+ Link
1329
+ 4 BestExchangeRates.com:
1330
+ Current BTC to USD market data, including charts and historic rates.
1331
+ Link
1332
+ 5 Investing.com:
1333
+ Bitcoin price analysis and live BTC to USD updates.
1334
+ Link
1335
+
1336
+ For the most accurate and up-to-date rate, I recommend checking one of these sources directly.
1337
+ ```
1338
+
1339
+ ![mcp](artwork/mcp_example.png)
1340
+
1341
+
1130
1342
  ## 💻 Technical Details
1131
1343
 
1132
1344
  ### Architecture
@@ -0,0 +1,49 @@
1
+ pyproject.toml,sha256=IGnWg-I9UrjiWbtuBK0GwEnTrrsvy6ZCN3GyfAlsGSU,2756
2
+ yaicli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ yaicli/chat.py,sha256=_emvZEdgMBth2nQGaNWPf0P45oW2k3bpuIwqsxFcM5A,13676
4
+ yaicli/cli.py,sha256=s8Bj4MSQmLblh4fHBPKS-DvJoAdMmp64KC7e7BwzmOs,23322
5
+ yaicli/config.py,sha256=_xLHgyW5dDg76bL1SyTcrQCnVs4dFpXafIS3sClshK0,6563
6
+ yaicli/console.py,sha256=vARPJd-3lafutsQWrGntQVjLrYqaJD3qisN82pmuhjU,1973
7
+ yaicli/const.py,sha256=O4hNk3ztjJ1o26lMjM1GK5Jpy-oA9NF69Gy528_ccEM,8861
8
+ yaicli/entry.py,sha256=jz4sVVy2Nr7uFMqpBhodAjtV5zflxpNHhAROKFRAH58,9633
9
+ yaicli/exceptions.py,sha256=WBYg8OTJJzaj7lt6HE7ZyBoe5T6A3yZRNCRfWd4iN0c,372
10
+ yaicli/history.py,sha256=s-57X9FMsaQHF7XySq1gGH_jpd_cHHTYafYu2ECuG6M,2472
11
+ yaicli/printer.py,sha256=g1TS7aDSQlWlSrQRhvNhNqoQKlsaf1lVOyUSK6LQLNQ,7945
12
+ yaicli/render.py,sha256=k8o2P8fI44PJlyQbs7gmMiu2x2prwajdWn5JIt15BIA,505
13
+ yaicli/role.py,sha256=PfwiVJIlzg7EzlvMM-kIy6vBK0d5d_J4M1I_fIZGnWk,7399
14
+ yaicli/schemas.py,sha256=Ty2ybCvld-ritgBZoI3RR93vYfw9LUNqkR8xk8VRZ2A,762
15
+ yaicli/utils.py,sha256=vCc_HoEKakA8HJ2m7_dIiIvMAIKEFlDpv1w1Yial-EE,5552
16
+ yaicli/functions/__init__.py,sha256=o2xwGvLKrvN8Wghhf_bU1klQfFRHW3g-f2BR968g31g,1652
17
+ yaicli/functions/buildin/execute_shell_command.py,sha256=unl1-F8p6QZajeHdA0u5UpURMJM0WhdWMUWCCCHVRcI,1320
18
+ yaicli/llms/__init__.py,sha256=x78cJujrJkelXPnzHS6pzHkITZdgLYZqJMnrMHbptoc,134
19
+ yaicli/llms/client.py,sha256=yjv8-DjVORdn1PKOC6t6Ei0uB3dz5GQ2bC3zAdKGALg,5759
20
+ yaicli/llms/provider.py,sha256=jF15kmY_tZVOjlw0fbHQkEvlmOX57-HBhILzG0KvXyo,3412
21
+ yaicli/llms/providers/ai21_provider.py,sha256=1zHG1xYYL4zEA_hNa0YqmplC00evCKuZPU7r2v54Q8o,4551
22
+ yaicli/llms/providers/chatglm_provider.py,sha256=zno_AbFESsRG3E5-IVnqMc1uA-jTuE1u4u5gU0BkAkQ,7421
23
+ yaicli/llms/providers/chutes_provider.py,sha256=mtvWvRRfHPH3JFfzym87wXtPNiMpLnur3805N9acx7E,882
24
+ yaicli/llms/providers/cohere_provider.py,sha256=1UPzNqNOwM4_dsP4kvUaL9O6_bKjxm1lO6A0lM7hgS4,10959
25
+ yaicli/llms/providers/deepseek_provider.py,sha256=iIV97x2ZCcwhGkshc8wpRi-YAnAnmo0n-YRegPlaOwQ,488
26
+ yaicli/llms/providers/doubao_provider.py,sha256=Tr0EP2fDh9txI-8dp_7BVAMswMkbw0cjBtZd6gI12v8,1453
27
+ yaicli/llms/providers/gemini_provider.py,sha256=78mOQEcf4uWzNduf8-tH0uMyka7xFbHNRnQQvHu_csU,8113
28
+ yaicli/llms/providers/groq_provider.py,sha256=EiS1Yxw5jbAUBFCRYsJ57KYgZPk6oH-_gD72OfW8Oik,1358
29
+ yaicli/llms/providers/huggingface_provider.py,sha256=XigSh4HDx00aYtBivMc2rwRwW6y6Nf0XgwEiFvcil2E,1239
30
+ yaicli/llms/providers/infiniai_provider.py,sha256=8-nU6QE58PRoZL9b_HzbPp4yi6OGm7rXtfi9z7bJMOg,786
31
+ yaicli/llms/providers/minimax_provider.py,sha256=W-j3dzrYMEv14bYt2pCPvPUxvxsUs-iMAcGB9yXakFs,744
32
+ yaicli/llms/providers/modelscope_provider.py,sha256=qWM0T7r0Zf8k3pLzjj7_IFdnmnx7S3rJO0f9rRm8-_A,504
33
+ yaicli/llms/providers/ollama_provider.py,sha256=pjpYjfnHWnExweZi1KGbT07JGkcxzKPhqICo8dD82D0,6967
34
+ yaicli/llms/providers/openai_provider.py,sha256=96vqKiVScULb9rfCuzrI7e9wCgXiqjc2Lx9XP8zCf9Q,10546
35
+ yaicli/llms/providers/openrouter_provider.py,sha256=R-7FrUrCAKPZ3gbnuo0M6rPlVw1mvSBjbLGs_FtZWM0,732
36
+ yaicli/llms/providers/sambanova_provider.py,sha256=FFLrsvARt1UPAFWWgiuB6zvGzGKdtehKL58HdE1fo_M,2254
37
+ yaicli/llms/providers/siliconflow_provider.py,sha256=CW2VSt6evUyFy21vN84Nvmw1P0JpmHBLznsgiXMnHM0,496
38
+ yaicli/llms/providers/targon_provider.py,sha256=RQ808eS9lvsyvlzyKaQYcN0NimbpoNWgjHUzY1gLNs4,717
39
+ yaicli/llms/providers/vertexai_provider.py,sha256=_ddrse1LfXRChTgkvxUlexyfJlfr0sVJH-Rmno3djSI,636
40
+ yaicli/llms/providers/xai_provider.py,sha256=Q6iOvJZOXIAwRiiHMKEBgq8-W6SGVZ9QD1_532bNYfo,199
41
+ yaicli/llms/providers/yi_provider.py,sha256=EnTm9qTxHPnzERsKqgGnzRIVhXFcAEdYqtOra65pGmY,719
42
+ yaicli/tools/__init__.py,sha256=62kSqvh232jog_pb85Tsx4Pe_rI9CAODGMTxAXdKzy0,4112
43
+ yaicli/tools/function.py,sha256=1yXnpOg7Y2sw_LwTOBH7042cHeBoBCVJJMQTVyQh_Hw,2802
44
+ yaicli/tools/mcp.py,sha256=-V17cDsQvmdb2eeVnuC_ypg5Rn6f10dUjEptNK1kTxU,15004
45
+ yaicli-0.7.0.dist-info/METADATA,sha256=KnO0NulMNsdWI2Zru1iKvpspzg-8uBZqv5AeXrX1SeU,64329
46
+ yaicli-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
47
+ yaicli-0.7.0.dist-info/entry_points.txt,sha256=iYVyQP0PJIm9tQnlQheqT435kK_xdGoi5j9aswGV9hA,66
48
+ yaicli-0.7.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
49
+ yaicli-0.7.0.dist-info/RECORD,,
yaicli/tools.py DELETED
@@ -1,159 +0,0 @@
1
- import importlib.util
2
- import sys
3
- from typing import Any, Dict, List, NewType, Optional, Tuple, cast
4
-
5
- from instructor import OpenAISchema
6
- from json_repair import repair_json
7
- from rich.panel import Panel
8
-
9
- from .config import cfg
10
- from .console import get_console
11
- from .const import FUNCTIONS_DIR
12
- from .schemas import ToolCall
13
-
14
- console = get_console()
15
-
16
- FunctionName = NewType("FunctionName", str)
17
-
18
-
19
- class Function:
20
- """Function description class"""
21
-
22
- def __init__(self, function: type[OpenAISchema]):
23
- self.name = function.openai_schema["name"]
24
- self.description = function.openai_schema.get("description", "")
25
- self.parameters = function.openai_schema.get("parameters", {})
26
- self.execute = function.execute # type: ignore
27
-
28
-
29
- _func_name_map: Optional[dict[FunctionName, Function]] = None
30
-
31
-
32
- def get_func_name_map() -> dict[FunctionName, Function]:
33
- """Get function name map"""
34
- global _func_name_map
35
- if _func_name_map:
36
- return _func_name_map
37
- if not FUNCTIONS_DIR.exists():
38
- FUNCTIONS_DIR.mkdir(parents=True, exist_ok=True)
39
- return {}
40
- functions = []
41
- for file in FUNCTIONS_DIR.glob("*.py"):
42
- if file.name.startswith("_"):
43
- continue
44
- module_name = str(file).replace("/", ".").rstrip(".py")
45
- spec = importlib.util.spec_from_file_location(module_name, str(file))
46
- module = importlib.util.module_from_spec(spec) # type: ignore
47
- sys.modules[module_name] = module
48
- spec.loader.exec_module(module) # type: ignore
49
-
50
- if not issubclass(module.Function, OpenAISchema):
51
- raise TypeError(f"Function {module_name} must be a subclass of instructor.OpenAISchema")
52
- if not hasattr(module.Function, "execute"):
53
- raise TypeError(f"Function {module_name} must have an 'execute' classmethod")
54
-
55
- # Add to function list
56
- functions.append(Function(function=module.Function))
57
-
58
- # Cache the function list
59
- _func_name_map = {FunctionName(func.name): func for func in functions}
60
- return _func_name_map
61
-
62
-
63
- def list_functions() -> list[Function]:
64
- """List all available buildin functions"""
65
- global _func_name_map
66
- if not _func_name_map:
67
- _func_name_map = get_func_name_map()
68
-
69
- return list(_func_name_map.values())
70
-
71
-
72
- def get_function(name: FunctionName) -> Function:
73
- """Get a function by name
74
-
75
- Args:
76
- name: Function name
77
-
78
- Returns:
79
- Function execute method
80
-
81
- Raises:
82
- ValueError: If function not found
83
- """
84
- func_map = get_func_name_map()
85
- if name in func_map:
86
- return func_map[FunctionName(name)]
87
- raise ValueError(f"Function {name!r} not found")
88
-
89
-
90
- def get_openai_schemas() -> List[Dict[str, Any]]:
91
- """Get OpenAI-compatible function schemas
92
-
93
- Returns:
94
- List of function schemas in OpenAI format
95
- """
96
- transformed_schemas = []
97
- for function in list_functions():
98
- schema = {
99
- "type": "function",
100
- "function": {
101
- "name": function.name,
102
- "description": function.description,
103
- "parameters": function.parameters,
104
- },
105
- }
106
- transformed_schemas.append(schema)
107
- return transformed_schemas
108
-
109
-
110
- def execute_tool_call(tool_call: ToolCall) -> Tuple[str, bool]:
111
- """Execute a tool call and return the result
112
-
113
- Args:
114
- tool_call: The tool call to execute
115
-
116
- Returns:
117
- Tuple[str, bool]: (result text, success flag)
118
- """
119
- console.print(f"@Function call: {tool_call.name}({tool_call.arguments})", style="blue")
120
-
121
- # 1. Get the function
122
- try:
123
- function = get_function(FunctionName(tool_call.name))
124
- except ValueError as e:
125
- error_msg = f"Function '{tool_call.name!r}' not exists: {e}"
126
- console.print(error_msg, style="red")
127
- return error_msg, False
128
-
129
- # 2. Parse function arguments
130
- try:
131
- arguments = repair_json(tool_call.arguments, return_objects=True)
132
- if not isinstance(arguments, dict):
133
- error_msg = f"Invalid arguments type: {arguments!r}, should be JSON object"
134
- console.print(error_msg, style="red")
135
- return error_msg, False
136
- arguments = cast(dict, arguments)
137
- except Exception as e:
138
- error_msg = f"Invalid arguments from llm: {e}\nRaw arguments: {tool_call.arguments!r}"
139
- console.print(error_msg, style="red")
140
- return error_msg, False
141
-
142
- # 3. Execute the function
143
- try:
144
- function_result = function.execute(**arguments)
145
- if cfg["SHOW_FUNCTION_OUTPUT"]:
146
- panel = Panel(
147
- function_result,
148
- title="Function output",
149
- title_align="left",
150
- expand=False,
151
- border_style="blue",
152
- style="dim",
153
- )
154
- console.print(panel)
155
- return function_result, True
156
- except Exception as e:
157
- error_msg = f"Call function error: {e}\nFunction name: {tool_call.name!r}\nArguments: {arguments!r}"
158
- console.print(error_msg, style="red")
159
- return error_msg, False
@@ -1,46 +0,0 @@
1
- pyproject.toml,sha256=BfvXPlqqvIqhYBItAj3HclRLukitrn0kdwIYxdUJBgU,2531
2
- yaicli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- yaicli/chat.py,sha256=_emvZEdgMBth2nQGaNWPf0P45oW2k3bpuIwqsxFcM5A,13676
4
- yaicli/cli.py,sha256=Eu1CL9ZB8ElvXqpHqmoWoasC0Brc7-j_zd3RmPhdSEE,23310
5
- yaicli/config.py,sha256=HrWYcelLXE61XX719eVcuuo3292xxf1BNQznWdvjQFQ,6535
6
- yaicli/console.py,sha256=vARPJd-3lafutsQWrGntQVjLrYqaJD3qisN82pmuhjU,1973
7
- yaicli/const.py,sha256=Uvdm1rc5zhjE2r9ioCYiSzhk8cT4mfgO2Mm4mNs71Nk,8176
8
- yaicli/entry.py,sha256=Q1eqLE7tcHide7ooyPO7OCJpKE2YVuxR-NNFA2Pt2Hw,8693
9
- yaicli/exceptions.py,sha256=WBYg8OTJJzaj7lt6HE7ZyBoe5T6A3yZRNCRfWd4iN0c,372
10
- yaicli/history.py,sha256=s-57X9FMsaQHF7XySq1gGH_jpd_cHHTYafYu2ECuG6M,2472
11
- yaicli/printer.py,sha256=g1TS7aDSQlWlSrQRhvNhNqoQKlsaf1lVOyUSK6LQLNQ,7945
12
- yaicli/render.py,sha256=k8o2P8fI44PJlyQbs7gmMiu2x2prwajdWn5JIt15BIA,505
13
- yaicli/role.py,sha256=PfwiVJIlzg7EzlvMM-kIy6vBK0d5d_J4M1I_fIZGnWk,7399
14
- yaicli/schemas.py,sha256=Ty2ybCvld-ritgBZoI3RR93vYfw9LUNqkR8xk8VRZ2A,762
15
- yaicli/tools.py,sha256=xw8KEs_xlSf79A2Aq1rAsUWahS6A_e5QMLt7QDXL5bs,5086
16
- yaicli/utils.py,sha256=bpo3Xhozpxsaci3FtEIKZ32l4ZdyWMsrHjYGX0tB4J4,4541
17
- yaicli/functions/__init__.py,sha256=_FJooQ9GkijG8xLwuU0cr5GBrGnC9Nc6bnCeUjrsT0k,1271
18
- yaicli/functions/buildin/execute_shell_command.py,sha256=unl1-F8p6QZajeHdA0u5UpURMJM0WhdWMUWCCCHVRcI,1320
19
- yaicli/llms/__init__.py,sha256=x78cJujrJkelXPnzHS6pzHkITZdgLYZqJMnrMHbptoc,134
20
- yaicli/llms/client.py,sha256=mkE9KHSuPcJfpNQXbzF2YXGkel3jrOW8KfQ3YYpaK4M,4453
21
- yaicli/llms/provider.py,sha256=YhX6RcMQqhac4EoQTY_AXDm-jtHYfH_K7Jikqvpc3H8,3159
22
- yaicli/llms/providers/ai21_provider.py,sha256=SvgGj9_87KEqmxCMLbtsSkT8J3rUD7Mb21UF7pMWsks,3035
23
- yaicli/llms/providers/chatglm_provider.py,sha256=1xP4KVAi6SDKZ-lMi2wdzywtDydsTf6jDzh3jBBGMfA,6437
24
- yaicli/llms/providers/chutes_provider.py,sha256=mtvWvRRfHPH3JFfzym87wXtPNiMpLnur3805N9acx7E,882
25
- yaicli/llms/providers/cohere_provider.py,sha256=hc6vQxbCHz9kM2tNKK-kGkuOf4-gkskXW9ctr9V4Cxk,10837
26
- yaicli/llms/providers/deepseek_provider.py,sha256=VjGes_jFin5WGYNFxYKMoHwgAQX_eYbYhQKfjeh-9eI,438
27
- yaicli/llms/providers/doubao_provider.py,sha256=4eOdE91ITUn3uo3mvYAzdrHsuFIIBwZWib21mtZn8OY,1938
28
- yaicli/llms/providers/gemini_provider.py,sha256=iCRDqHRBFeTD_2NQwlsAlxFU7cKK4iyjimaPSp4VySM,7923
29
- yaicli/llms/providers/groq_provider.py,sha256=EiS1Yxw5jbAUBFCRYsJ57KYgZPk6oH-_gD72OfW8Oik,1358
30
- yaicli/llms/providers/infiniai_provider.py,sha256=1dseUIZiXsxYRATRtk_obFclyXMwi4glsP7l_tVtnv8,710
31
- yaicli/llms/providers/minimax_provider.py,sha256=W-j3dzrYMEv14bYt2pCPvPUxvxsUs-iMAcGB9yXakFs,744
32
- yaicli/llms/providers/modelscope_provider.py,sha256=BzBhYixiDEWB7gujQ0rcG__7nsv0psJRxdtYCYXBhdM,454
33
- yaicli/llms/providers/ollama_provider.py,sha256=pjpYjfnHWnExweZi1KGbT07JGkcxzKPhqICo8dD82D0,6967
34
- yaicli/llms/providers/openai_provider.py,sha256=yl1vVKt8QzbN_dbsW_9rY8S_xkXI3Bo3Of4Cf7W3mJc,10075
35
- yaicli/llms/providers/openrouter_provider.py,sha256=R-7FrUrCAKPZ3gbnuo0M6rPlVw1mvSBjbLGs_FtZWM0,732
36
- yaicli/llms/providers/sambanova_provider.py,sha256=FFLrsvARt1UPAFWWgiuB6zvGzGKdtehKL58HdE1fo_M,2254
37
- yaicli/llms/providers/siliconflow_provider.py,sha256=7Ir73me9jGMO5TAZDjrAbX7tbb_QBmLjTGywY0yliqc,446
38
- yaicli/llms/providers/targon_provider.py,sha256=RQ808eS9lvsyvlzyKaQYcN0NimbpoNWgjHUzY1gLNs4,717
39
- yaicli/llms/providers/vertexai_provider.py,sha256=_ddrse1LfXRChTgkvxUlexyfJlfr0sVJH-Rmno3djSI,636
40
- yaicli/llms/providers/xai_provider.py,sha256=Q6iOvJZOXIAwRiiHMKEBgq8-W6SGVZ9QD1_532bNYfo,199
41
- yaicli/llms/providers/yi_provider.py,sha256=EnTm9qTxHPnzERsKqgGnzRIVhXFcAEdYqtOra65pGmY,719
42
- yaicli-0.6.3.dist-info/METADATA,sha256=EfU2thy5G2Ge-BaCM3RT0quP2YUPz0bBWLJjKJugf_w,53677
43
- yaicli-0.6.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
44
- yaicli-0.6.3.dist-info/entry_points.txt,sha256=iYVyQP0PJIm9tQnlQheqT435kK_xdGoi5j9aswGV9hA,66
45
- yaicli-0.6.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
46
- yaicli-0.6.3.dist-info/RECORD,,
File without changes