forked from julep-ai/julep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-Basic_Agent_Creation_and_Interaction.py
71 lines (59 loc) · 1.72 KB
/
05-Basic_Agent_Creation_and_Interaction.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import uuid
from julep import Client
# Global UUID is generated for agent
AGENT_UUID = uuid.uuid4()
# Creating Julep Client with the API Key
api_key = "" # Your API key here
client = Client(api_key=api_key, environment="dev")
# Creating an "agent"
name = "Jarvis"
about = "A friendly and knowledgeable AI assistant."
default_settings = {
"temperature": 0.7,
"top_p": 1,
"min_p": 0.01,
"presence_penalty": 0,
"frequency_penalty": 0,
"length_penalty": 1.0,
"max_tokens": 150,
}
# Create the agent
agent = client.agents.create_or_update(
agent_id=AGENT_UUID,
name=name,
about=about,
model="gpt-4-turbo",
)
print(f"Agent created with ID: {agent.id}")
# Create a session for interaction
session = client.sessions.create(
agent=agent.id,
context_overflow="adaptive"
)
print(f"Session created with ID: {session.id}")
# Function to chat with the agent
def chat_with_agent(message):
message = {
"role": "user",
"content": message,
}
# TODO: message validation error
response = client.sessions.chat(
session_id=session.id,
messages=[message],
)
return response.choices[0].message.content
# Demonstrate basic interaction
print("Agent: Hello! I'm Jarvis, your AI assistant. How can I help you today?")
while True:
user_input = input("You: ")
if user_input.lower() in ['exit', 'quit', 'bye']:
print("Agent: Goodbye! It was nice chatting with you.")
break
response = chat_with_agent(user_input)
print(f"Agent: {response}")
# Optional: Retrieve chat history
history = client.sessions.messages.list(session_id=session.id)
print("\nChat History:")
for message in history.items:
print(f"{message.role}: {message.content}")