Files
Auto-GPT/autogpt/call_ai_function.py
BillSchumacher 4bb7a598a5 Fix everything (#1444)
* Pi's message.

* Fix most everything.

* Blacked
2023-04-15 01:04:48 +01:00

27 lines
946 B
Python

from autogpt.config import Config
from autogpt.llm_utils import create_chat_completion
cfg = Config()
# This is a magic function that can do anything with no-code. See
# https://github.com/Torantulino/AI-Functions for more info.
def call_ai_function(function, args, description, model=None) -> str:
"""Call an AI function"""
if model is None:
model = cfg.smart_llm_model
# For each arg, if any are None, convert to "None":
args = [str(arg) if arg is not None else "None" for arg in args]
# parse args to comma separated string
args = ", ".join(args)
messages = [
{
"role": "system",
"content": f"You are now the following python function: ```# {description}"
f"\n{function}```\n\nOnly respond with your `return` value.",
},
{"role": "user", "content": args},
]
return create_chat_completion(model=model, messages=messages, temperature=0)