#echo #go #provider #dangerous #function #alone

app ellie

echo "It's dangerous to go alone" | ellie

1 个不稳定版本

0.1.0 2023年9月11日

6 in #dangerous

MIT 许可证

24KB
404

ellie

Build Status Latest Version

$ echo "It's dangerous to go alone" | ellie
Take this!

ellie 是一个基于Rust的命令行界面,用于访问ChatGPT,并支持通过外部提供者调用功能。

功能

功能调用通过委托给外部提供者来实现。您只需在 ~/.config/ellie/functions.toml(或在您平台的等效路径)中配置一个功能提供者。

提供者配置

要配置一个功能提供者,请将以下信息添加到 functions.toml 文件中

[[provider]]
name = "get_current_weather"
command = "python"
args = ["get_current_weather.py"]

此示例配置了一个名为 "get_current_weather" 的提供者,该提供者使用名为 "get_current_weather.py" 的Python脚本。

提供者行为

功能提供者从标准输入读取,并将结果写入标准输出。当提供额外的 spec 参数时,它会将规范写入标准输出。

例如,运行提供者并带有 spec 参数将输出以下规范

$ python get_current_weather.py spec
{
  "name": "get_current_weather",
  "description": "Get the current weather in a given location",
  "parameters": {
    "type": "object",
    "required": ["location"],
    "properties": {
      "location": {
        "type": "string",
        "description": "The city and state, e.g. San Francisco, CA"
      },
      "unit": {
        "type": "string",
        "enum": ["celsius", "fahrenheit"]
      }
    }
  }
}

要调用函数,您可以通过标准输入提供所需的输入作为JSON对象。然后提供者将以JSON对象的形式输出结果。

例如

$ echo '{"location":"Boston, MA"}' | python get_current_weather.py
{
  "location": "Boston, MA",
  "temperature": "72",
  "unit": null,
  "forecast": ["sunny", "windy"]
}

模板实现

以下是一个Python的模板实现

from sys import argv
import json

match argv[1:]:
    case []:
        print(json.dumps({
            # ...
        }))
    case ["spec"]:
        print(json.dumps({
            # ...
        }))

您可以使用任何编程语言编写功能提供者。有关功能规范的信息,请参阅 OpenAI官方指南

详细输出

TL;DR:目前使用日志。

如果您只想看到正在调用的函数,请使用 RUST_LOG=info

$ echo 'What is the weather like in Boston?' | RUST_LOG=info ellie
 INFO  ellie > get_current_weather {"location":"Boston, MA"}
The weather in Boston is currently sunny and windy with a temperature of 72 degrees.

对于调试信息(例如,确切的请求数据),请使用 RUST_LOG=debug

$ echo 'What is the weather like in Boston?' | RUST_LOG=debug ellie
 DEBUG ellie > {"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"What is the weather like in Boston?"}],"functions":[{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"properties":{"location":{"description":"The city and state, e.g. San Francisco, CA","type":"string"},"unit":{"enum":["celsius","fahrenheit"],"type":"string"}},"required":["location"],"type":"object"}}],"temperature":0.0,"max_tokens":null}
 INFO  ellie > get_current_weather {"location":"Boston, MA"}
 DEBUG ellie > {"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"What is the weather like in Boston?"},{"role":"assistant","content":"","function_call":{"name":"get_current_weather","arguments":"{\"location\":\"Boston, MA\"}"}},{"role":"function","content":"{\"forecast\":[\"sunny\",\"windy\"],\"location\":\"Boston, MA\",\"temperature\":\"72\",\"unit\":null}","name":"get_current_weather"}],"functions":[{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"properties":{"location":{"description":"The city and state, e.g. San Francisco, CA","type":"string"},"unit":{"enum":["celsius","fahrenheit"],"type":"string"}},"required":["location"],"type":"object"}}],"temperature":0.0,"max_tokens":null}
The weather in Boston is currently sunny and windy with a temperature of 72 degrees.

依赖项

~27–42MB
~530K SLoC