AI Functions
1.0.0
例子:
function_string = "def fake_people(n: int) -> list[dict]:"
args = [ "4" ]
description_string = """Generates n examples of fake data representing people, each with a name and an age."""
result = ai_functions . ai_function ( function_string , args , description_string , model )
""" Output: [
{"name": "John Doe", "age": 35},
{"name": "Jane Smith", "age": 28},
{"name": "Alice Johnson", "age": 42},
{"name": "Bob Brown", "age": 23}
]"""使用OpenAI的GPT-4(或任何其他型号版本)来执行各种任务的AI功能易于使用。这个项目受到Ask Marvin的启发。
git clone https://github.com/YourUsername/SuperSimpleAIFunctions.gitpip install -r requirements.txtkeys.py中或将其设置为环境变量的目录中。 ai_functions.py包含以下功能:
def ai_function ( function , args , description , model = "gpt-4" ): ai_function采用以下参数:
function :描述函数签名的字符串。args :该功能的参数列表。description :描述该功能目的的字符串。model :(可选)一个指定GPT模型的字符串。默认值为“ GPT-4”。示例用法:
import ai_functions
function = "def add(a: int, b: int) -> int:"
args = [ "5" , "7" ]
description = "Adds two integers."
result = ai_functions . ai_function ( function , args , description )
print ( result ) # Output: 12 下表显示了具有不同GPT模型的AI函数的成功率:
| 描述 | GPT-4结果 | GPT-3.5-Turbo结果 | 原因 |
|---|---|---|---|
| 产生假人 | 通过 | 失败的 | 不正确的响应格式 |
| 生成随机密码 | 通过 | 通过 | N/A。 |
| 计算三角区域 | 失败的 | 失败的 | 不正确的浮点值(GPT-4),错误响应格式(GPT-3.5-Turbo) |
| 计算第n个质数 | 通过 | 通过 | N/A。 |
| 加密文字 | 通过 | 通过 | N/A。 |
| 查找丢失的数字 | 通过 | 通过 | N/A。 |
重要的是要注意,AI函数不适用于某些任务,尤其是涉及数学计算和精度的任务。正如计算三角形区域并找到第n个质量数的情况下所观察到的,GPT模型可能在提供准确的结果方面努力。在这种情况下,GPT模型的局限性主要是由于其固有的无法执行精确的算术和理解用户输入的歧义。
总之,尽管在各种情况下,AI函数可能会有所帮助,但它们可能不是需要数学准确性或特定领域知识的任务的最佳选择。对于此类用例,利用传统算法和库将产生更好的结果。
test_ai_functions.py包含ai_function的测试用例。要运行测试,请使用Python执行脚本:
python test_ai_functions.py测试脚本将输出每个测试案例的结果并提供成功率。
欢迎捐款!如果您想添加更多测试用例或改进现有代码,请随时提交拉动请求。