Skip to content

Instantly share code, notes, and snippets.

@elijahbenizzy
Last active July 6, 2024 16:00
Show Gist options
  • Save elijahbenizzy/d9e1904e122e242460ac73d8639b511c to your computer and use it in GitHub Desktop.
Save elijahbenizzy/d9e1904e122e242460ac73d8639b511c to your computer and use it in GitHub Desktop.
def llm_client() -> openai.AsyncOpenAI:
return openai.AsyncOpenAI()
def joke_prompt(topic: str) -> str:
return (
f"Tell me a short joke about {topic}"
)
def joke_messages(
joke_prompt: str) -> List[dict]:
return [{"role": "user",
"content": joke_prompt}]
async def joke_response(
llm_client: openai.AsyncOpenAI,
joke_messages: List[dict]) -> str:
response = await (
llm_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=joke_messages,
)
)
return response.choices[0].message.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment