-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_chat.py
More file actions
54 lines (46 loc) · 1.68 KB
/
_chat.py
File metadata and controls
54 lines (46 loc) · 1.68 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import dotenv
import instructor
from instructor import Image
import openai
from rich.console import Console
from atomic_agents.lib.components.agent_memory import AgentMemory
from atomic_agents.agents.base_agent import BaseAgent, BaseAgentConfig, BaseAgentInputSchema, BaseAgentOutputSchema
# Initialize console for pretty outputs
console = Console()
# Memory setup
memory = AgentMemory()
dotenv.load_dotenv()
# Initialize memory with an initial message from the assistant
initial_message = BaseAgentOutputSchema(chat_message="Hello! How can I assist you today?")
memory.add_message("assistant", initial_message)
# OpenAI client setup using the Instructor library
client = instructor.from_openai(
openai.OpenAI(
base_url="https://api.studio.nebius.com/v1",
api_key=os.getenv("NEBIUS_API_KEY")
)
)
# Agent setup with specified configuration
agent = BaseAgent(
config=BaseAgentConfig(
client=client,
model="Qwen/Qwen3-30B-A3B",
memory=memory,
)
)
# Start a loop to handle user inputs and agent responses
while True:
# Prompt the user for input
user_input = console.input("[bold blue]You:[/bold blue] ")
# Check if the user wants to exit the chat
if user_input.lower() in ["/exit", "/quit"]:
console.print("Exiting chat...")
break
memory.add_message("user", BaseAgentInputSchema(chat_message=user_input))
# Process the user's input through the agent and get the response
input_schema = BaseAgentInputSchema(chat_message=user_input)
response = agent.run(input_schema)
memory.add_message("assistant", response)
# Display the agent's response
console.print("Agent: ", response.chat_message)