mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-04 15:41:15 +00:00
28 lines
912 B
Python
28 lines
912 B
Python
![]() |
import yaml
|
||
|
|
||
|
from autogen_core import CancellationToken
|
||
|
from autogen_agentchat.messages import TextMessage
|
||
|
from autogen_agentchat.agents import AssistantAgent
|
||
|
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
|
||
|
|
||
|
|
||
|
class Agent:
|
||
|
def __init__(self):
|
||
|
# Load the model client from config.
|
||
|
with open("model_config.yml", "r") as f:
|
||
|
model_config = yaml.safe_load(f)
|
||
|
model_client = AzureOpenAIChatCompletionClient.load_component(model_config)
|
||
|
self.agent = AssistantAgent(
|
||
|
name="assistant",
|
||
|
model_client=model_client,
|
||
|
system_message="You are a helpful AI assistant.",
|
||
|
)
|
||
|
|
||
|
async def chat(self, prompt: str) -> str:
|
||
|
response = await self.agent.on_messages(
|
||
|
[TextMessage(content=prompt, source="user")],
|
||
|
CancellationToken(),
|
||
|
)
|
||
|
|
||
|
return response.chat_message.content
|