forked from julep-ai/julep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-TripPlanner_With_Weather_And_WikiInfo.py
123 lines (102 loc) · 2.84 KB
/
04-TripPlanner_With_Weather_And_WikiInfo.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import uuid
import yaml
from julep import Client
# Global UUID is generated for agent and task
AGENT_UUID = uuid.uuid4()
TASK_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 = "The original AI conscious the Iron Man."
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,
}
agent = client.agents.create_or_update(
agent_id=AGENT_UUID,
name=name,
about=about,
model="gpt-4o",
)
# Defining a Task
task_def = yaml.safe_load("""
name: Tourist Plan With Weather And Attractions
input_schema:
type: object
properties:
locations:
type: array
items:
type: string
description: The locations to search for.
tools:
- name: wikipedia
type: integration
integration:
provider: wikipedia
- name: weather
type: integration
integration:
provider: weather
setup:
openweathermap_api_key: "YOUR_API_KEY"
main:
- over: inputs[0].locations
map:
tool: weather
arguments:
location: _
- over: inputs[0].locations
map:
tool: wikipedia
arguments:
query: "_ + ' tourist attractions'"
- evaluate:
zipped: "list(zip(inputs[0].locations, [output['result'] for output in outputs[0]], [output['documents'][0]['page_content'] for output in outputs[1]]))" # [(location, weather, attractions)]
- over: _['zipped']
parallelism: 3
map:
prompt:
- role: system
content: >-
You are a travel assistant. Your task is to create a detailed itinerary for visiting tourist attractions in "{{_[0]}}" based on the weather conditions and the top tourist attractions provided.
Current weather condition at "{{_[0]}}":
"{{_[1]}}"
Top tourist attractions in "{{_[0]}}":
"{{_[2]}}"
Suggest outdoor or indoor activities based on the above information.
unwrap: true
""")
# Creating/Updating a task
task = client.tasks.create_or_update(
task_id=TASK_UUID,
agent_id=AGENT_UUID,
**task_def
)
# Creating an Execution
execution = client.executions.create(
task_id=task.id,
input={
"locations": ["New York", "London", "Paris", "Tokyo", "Sydney"]
}
)
print(f"Execution ID: {execution.id}")
# Getting the execution details
execution = client.executions.get(execution.id)
print("Execution Output:")
print(execution.output)
# List all steps of the executed task
print("Execution Steps:")
for item in client.executions.transitions.list(execution_id=execution.id).items:
print(item)
# Stream the execution steps in real-time
print("Streaming Execution Steps:")
for step in client.executions.transitions.stream(execution_id=execution.id):
print(step)