radio changes/progress
This commit is contained in:
33
gpt/__init__.py
Normal file
33
gpt/__init__.py
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3.12
|
||||
import os
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
class GPT:
|
||||
def __init__(self, constants):
|
||||
self.constants = constants
|
||||
self.api_key = self.constants.OPENAI_API_KEY
|
||||
self.client = AsyncOpenAI(
|
||||
api_key=self.api_key,
|
||||
timeout=10.0,
|
||||
)
|
||||
self.default_system_prompt = "You are a helpful assistant who will provide tidbits of info on songs the user may listen to."
|
||||
|
||||
async def get_completion(self, prompt: str, system_prompt: Optional[str] = None) -> None:
|
||||
if not system_prompt:
|
||||
system_prompt = self.default_system_prompt
|
||||
chat_completion = await self.client.chat.completions.create(
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": system_prompt,
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": prompt,
|
||||
}
|
||||
],
|
||||
model="gpt-4o-mini",
|
||||
)
|
||||
return chat_completion.choices[0].message.content
|
Reference in New Issue
Block a user