Spaces:
Sleeping
Sleeping
File size: 797 Bytes
d242fb9 a43c276 d242fb9 a43c276 d242fb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import os
from typing import Optional
from openai import AsyncAzureOpenAI
from dotenv import load_dotenv
load_dotenv()
class LLMClient:
def __init__(self):
self.client = AsyncAzureOpenAI(
api_version=os.getenv("AZURE_OPENAI_API_KEY"),
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
api_key=os.getenv("AZURE_OPENAI_API_KEY")
)
async def query(self, prompt: str) -> Optional[str]:
try:
response = await self.client.chat.completions.create(
model='agile4',
messages=[{"role": "user", "content": prompt}],
)
return response.choices[0].message.content.strip()
except Exception as e:
print(f"OpenAI API error: {e}")
return None
|