Skip to content

Instantly share code, notes, and snippets.

@elijahbenizzy
Last active August 23, 2024 21:00
Show Gist options
  • Save elijahbenizzy/f8f60fd0c06b6c99780f3b285c33dad9 to your computer and use it in GitHub Desktop.
Save elijahbenizzy/f8f60fd0c06b6c99780f3b285c33dad9 to your computer and use it in GitHub Desktop.
trace_decorator.py
@trace()
def _get_openai_client():
return openai.Client()
@trace()
def _query_openai(
prompt: str,
model: str = "gpt-4",
chat_history: Optional[list] = None
):
chat_history = chat_history or []
client = _get_openai_client()
result = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful assistant"},
*chat_history,
{"role": "user", "content": prompt},
],
)
return result.choices[0].message.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment