File size: 737 Bytes
0a026c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from openai import AzureOpenAI
import os
class GPTAgent:
def __init__(self, model_name):
self.client = AzureOpenAI(
api_key=os.getenv('AZURE_OPENAI_KEY'),
api_version=os.getenv('AZURE_OPENAI_VERSION'),
azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT')
)
self.deployment_name = model_name
def invoke(self, text, **kwargs):
response = self.client.chat.completions.create(
model=self.deployment_name,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": text}
],
**kwargs
)
return response.choices[0].message.content
|