-
-
Save elijahbenizzy/f8f60fd0c06b6c99780f3b285c33dad9 to your computer and use it in GitHub Desktop.
trace_decorator.py
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
@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