Skip to content

Instantly share code, notes, and snippets.

@sergenes
Created December 10, 2023 15:08
Show Gist options
  • Save sergenes/65e89ff6eba722cb077055610210eed5 to your computer and use it in GitHub Desktop.
Save sergenes/65e89ff6eba722cb077055610210eed5 to your computer and use it in GitHub Desktop.
Open AI API completion function
import openai
openai.api_key = os.getenv('OPENAI_API_KEY_1')
def get_open_ai_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
open_ai_response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0.2,
)
return open_ai_response.choices[0].message["content"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment