Created
April 4, 2023 14:08
-
-
Save jalvarado91/f1c0c5f7823f2c997714265eb4c624c8 to your computer and use it in GitHub Desktop.
Ai Function with OpenAI API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
def ai_function(function, args, description, model = "gpt-3.5-turbo"): | |
""" | |
function = "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_function(function_string, args, description_string, model) | |
""" | |
# parse args to comma seperated string | |
args = ", ".join(args) | |
messages = [{"role": "system", "content": f"You are now the following python function: ```# {description}\n{function}```\n\nOnly respond with your `return` value. no verbose, no chat."},{"role": "user", "content": args}] | |
response = openai.ChatCompletion.create( | |
model=model, | |
messages=messages, | |
temperature=0 | |
) | |
return response.choices[0].message["content"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refined Prompt