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測試腳本將輸出每個測試案例的結果並提供成功率。
歡迎捐款!如果您想添加更多測試用例或改進現有代碼,請隨時提交拉動請求。