Skip to content
NineOceans edited this page Jul 4, 2023 · 7 revisions

Welcome to the Terminal-Agent-X wiki! 👻

功能及示例

生成代码并执行

此功能适合较短的代码,例如在 Linux 环境中执行bash指令。

 $ tax Count the number of *.py files in the current directory and subfolder
find . -name "*.py" | wc -l

Do you want to execute the command? (y/n)  y
3

使用中文提问

$ tax 现在有多个形如 ViT-coco-64-0.2-0.5-0.15-1682613197.log 的文件,使用bash打印出每个文件的最后一行和对应的文件名
for file in ViT-coco-64-0.2-0.5-*-*.log; do echo "$(tail -1 $file) - $file"; done

Do you want to execute the command? (y/n)  y
[ 70] C: 1.7311, S: 0.0114, R: 0.0407, mAP: 0.9368, MAX mAP: 0.9374  - ViT-coco-64-0.2-0.5-0.0-1682593391.log
[ 70] C: 1.6659, S: 0.0114, R: 0.0405, mAP: 0.9351, MAX mAP: 0.9357  - ViT-coco-64-0.2-0.5-0.05-1682599979.log
[ 70] C: 1.7584, S: 0.0126, R: 0.0413, mAP: 0.9343, MAX mAP: 0.9353  - ViT-coco-64-0.2-0.5-0.1-1682606584.log
[ 70] C: 1.7151, S: 0.0111, R: 0.0411, mAP: 0.9332, MAX mAP: 0.9336  - ViT-coco-64-0.2-0.5-0.15-1682613197.log
[ 70] C: 1.7275, S: 0.0126, R: 0.0404, mAP: 0.9352, MAX mAP: 0.9356  - ViT-coco-64-0.2-0.5-0.2-1682619814.log
[ 70] C: 1.6624, S: 0.0123, R: 0.0402, mAP: 0.9330, MAX mAP: 0.9337  - ViT-coco-64-0.2-0.5-0.25-1682626378.log
[ 70] C: 1.7599, S: 0.0136, R: 0.0407, mAP: 0.9345, MAX mAP: 0.9350  - ViT-coco-64-0.2-0.5-0.3-1682632953.log

生成多行代码

$ tax write a python code for fibonacci
def fibonacci(n):
    if n <= 1:
        return n
    else:
        return(fibonacci(n-1) + fibonacci(n-2))

num_terms = int(input("Enter the number of terms: "))

if num_terms <= 0:
    print("Please enter a positive integer!")
else:
    print("Fibonacci sequence:")
    for i in range(num_terms):
        print(fibonacci(i))
$ tax 用Pytorch写一个情感分类的代码

Too Long; Don't Read. 可以查看 https://paste.ubuntu.com/p/TzV5RMZ8xN/

生成完整的markdown指引

对于一些需要多步操作的功能,可以使用以下命令输出完整的markdown操作引导。

$ tax how to install docker on ubuntu -o docker-manual.md
$ head docker-manual.md
    1. Update the apt package index

    ```console
    sudo apt-get update
    ```

    2. Install prerequisites which allow apt to use a repository over HTTPS
    
    ```console
    sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

这个过程等同于向 gpt-3.5-turbo 发送单次询问请求。

使用自己的key执行单次请求

$ tax write a python code for fibonacci --key sk-xxx

使用URL

tax 默认调用的是 openai。其他的一些示例如下:

tax <prompt>                 # 此命令同 tax <prompt> --url openai
tax <prompt> --url openai_gfw    # 如果你的环境在GFW之下,可以使用内置代理访问
tax <prompt> --url claude    # Anthropic Claude API

文件读取

$ tax -i tests/multiprocess.py 给这个python代码加上注释

常见问题

需要开启代理吗?

不需要。我搭建了反代理服务 https://api.lyulumos.space/,可以不开代理访问,但是相较于直接访问 OpenAI API,速度会慢一些。

暂时不使用官方api,因为从亚洲地区使用官方api可能会导致封号。考虑到部分使用者难以具体指定使用某地的代理,因此统一请求到自建代理服务。

[Linux] 安装后显示 bash: /home/codespace/.local/bin/tax: No such file or directory

这是因为 tax 没有添加到环境变量中,通过 whereis tax 查看 tax 的安装位置,然后 export PATH=$PATH:<tax的路径> 将其添加到环境变量中即可。

为什么需要等待很久才能看到结果?

目前经过测试大概需要10s左右,较长的代码可能需要更多的时间,同时也受网络影响,原因如问题1所示。在 GitHub CodeSpaces 的测试速度大概为4s左右。请耐心等待。

中文支持

支持。理论上还支持日文等大部分语言。

$ tax ハノイの塔を完成させるためのpythonコードを書く

[OpenAI_KEY] 出现错误:Error: OpenAI key not found. Please specify it in system environment variables or pass it as an argument.

首先你需要注册一个OpenAI账号,并在这里获取你的OpenAI_KEY。每次调用OpenAI API需要根据 token 数量支付一定费用,一般每个账号有预设的 credit,个人使用很长时间。

然后你需要将 OpenAI_KEY 添加到环境变量中,Windows系统可以请参考这里,Linux用户可以参见 README.md 中的配置部分。

[OpenAI_KEY] 出现错误:Error: Invalid API key provided. Please check that your API key is valid.

请检查你的 OpenAI_KEY 是否正确,包括账户是否有余额。

[Windows] 为什么不用 Python-requests?

目前Windows系统仅支持 cmdWSL。'Powershell' 提供了一个比较妥协的版本但是有待完善。

Windows Powershell 中的 curl 本质上是 Invoke-WebRequest 的 alias,功能非常有限。

我在之前的版本中实现了 Python-requests 的版本,但是需要等待约45s才能返回结果,出于速度考虑,目前仍选择使用 curl 发送请求。

不满意输出?

多试几次,会有不同的结果。