Spaces:
Running
Running
Adding support for dynamic configuration of chosen model
Browse files
app.py
CHANGED
@@ -42,8 +42,7 @@ def export_pdf(input_text:str):
|
|
42 |
pdf.set_font("Arial", size=12, style='')
|
43 |
else:
|
44 |
pdf.multi_cell(0, 5, clean_line)
|
45 |
-
|
46 |
-
pdf.output("output.pdf")
|
47 |
return "output.pdf"
|
48 |
|
49 |
def filter_map(text_list: List[str], lat: List[str], lon: List[str]) -> go.Figure:
|
@@ -83,6 +82,7 @@ def run(
|
|
83 |
cuisine_preferences: List[str],
|
84 |
children: bool,
|
85 |
budget: int,
|
|
|
86 |
) -> Tuple[str, go.Figure]:
|
87 |
"""
|
88 |
Run the specfied query using Crew AI agents.
|
@@ -116,7 +116,7 @@ def run(
|
|
116 |
f'Origin: {origin}, Destination: {destination}, Arrival Date: {arrival_date_input},'
|
117 |
f' Age: {age}, Duration: {trip_duration},'
|
118 |
f' Interests: {interests}, Cuisines: {cuisine_preferences},'
|
119 |
-
f' Children: {children}, Daily Budget: {budget}'
|
120 |
)
|
121 |
|
122 |
# Creating a dictionary of user provided preferences and providing these to the crew agents
|
@@ -133,7 +133,7 @@ def run(
|
|
133 |
'children': children,
|
134 |
'budget': budget,
|
135 |
}
|
136 |
-
result = TravelCrew().crew().kickoff(inputs=user_preferences)
|
137 |
|
138 |
"""
|
139 |
Now we will pass the result to a address summary crew whose job is to extract position
|
@@ -143,7 +143,7 @@ def run(
|
|
143 |
|
144 |
inputs_for_address = {'text': str(result)}
|
145 |
|
146 |
-
addresses = AddressSummaryCrew().crew().kickoff(inputs=inputs_for_address)
|
147 |
|
148 |
"""
|
149 |
We have requested the crew agent to return latitude, longitude coordinates.
|
@@ -191,7 +191,7 @@ with gr.Blocks() as demo:
|
|
191 |
'Museums',
|
192 |
'Outdoor Adventures',
|
193 |
'Shopping',
|
194 |
-
'Children's Entertainment',
|
195 |
'Off the beat activities',
|
196 |
'Night Life',
|
197 |
],
|
@@ -219,8 +219,9 @@ with gr.Blocks() as demo:
|
|
219 |
gr.Slider(
|
220 |
label='Total budget of trip in USD', show_label=True, value=1000, minimum=500, maximum=10000, step=500
|
221 |
)
|
|
|
222 |
button = gr.Button("Plan your Trip")
|
223 |
-
inputs = [inp_source, inp_dest, inp_cal, inp_age, inp_days, inp_interests, inp_cuisine, inp_children, inp_budget]
|
224 |
|
225 |
with gr.Column(scale=2):
|
226 |
output_itinerary =\
|
|
|
42 |
pdf.set_font("Arial", size=12, style='')
|
43 |
else:
|
44 |
pdf.multi_cell(0, 5, clean_line)
|
45 |
+
pdf.output("output.pdf").encode('latin-1')
|
|
|
46 |
return "output.pdf"
|
47 |
|
48 |
def filter_map(text_list: List[str], lat: List[str], lon: List[str]) -> go.Figure:
|
|
|
82 |
cuisine_preferences: List[str],
|
83 |
children: bool,
|
84 |
budget: int,
|
85 |
+
model_name:str='Meta-Llama-3.1-70B-Instruct'
|
86 |
) -> Tuple[str, go.Figure]:
|
87 |
"""
|
88 |
Run the specfied query using Crew AI agents.
|
|
|
116 |
f'Origin: {origin}, Destination: {destination}, Arrival Date: {arrival_date_input},'
|
117 |
f' Age: {age}, Duration: {trip_duration},'
|
118 |
f' Interests: {interests}, Cuisines: {cuisine_preferences},'
|
119 |
+
f' Children: {children}, Daily Budget: {budget}, Model Name: {model_name}'
|
120 |
)
|
121 |
|
122 |
# Creating a dictionary of user provided preferences and providing these to the crew agents
|
|
|
133 |
'children': children,
|
134 |
'budget': budget,
|
135 |
}
|
136 |
+
result = TravelCrew(model_name).crew().kickoff(inputs=user_preferences)
|
137 |
|
138 |
"""
|
139 |
Now we will pass the result to a address summary crew whose job is to extract position
|
|
|
143 |
|
144 |
inputs_for_address = {'text': str(result)}
|
145 |
|
146 |
+
addresses = AddressSummaryCrew(model_name).crew().kickoff(inputs=inputs_for_address)
|
147 |
|
148 |
"""
|
149 |
We have requested the crew agent to return latitude, longitude coordinates.
|
|
|
191 |
'Museums',
|
192 |
'Outdoor Adventures',
|
193 |
'Shopping',
|
194 |
+
'Children\'s Entertainment',
|
195 |
'Off the beat activities',
|
196 |
'Night Life',
|
197 |
],
|
|
|
219 |
gr.Slider(
|
220 |
label='Total budget of trip in USD', show_label=True, value=1000, minimum=500, maximum=10000, step=500
|
221 |
)
|
222 |
+
inp_model = gr.Textbox(value="Meta-Llama-3.1-70B-Instruct", label='Sambanova Model Name')
|
223 |
button = gr.Button("Plan your Trip")
|
224 |
+
inputs = [inp_source, inp_dest, inp_cal, inp_age, inp_days, inp_interests, inp_cuisine, inp_children, inp_budget, inp_model]
|
225 |
|
226 |
with gr.Column(scale=2):
|
227 |
output_itinerary =\
|
crew.py
CHANGED
@@ -10,20 +10,16 @@ from crewai.project import CrewBase, agent, crew, task
|
|
10 |
# SerperDevTool: Search Internet, https://docs.crewai.com/tools/serperdevtool
|
11 |
from crewai_tools import ScrapeWebsiteTool, SerperDevTool
|
12 |
|
13 |
-
# Change the model which you want to use below.
|
14 |
-
# Currently, we use the Llama 3.1 70B model because it seems the most versatile.
|
15 |
-
llm = LLM(model='sambanova/Meta-Llama-3.1-70B-Instruct')
|
16 |
-
|
17 |
-
|
18 |
@CrewBase
|
19 |
class TravelCrew:
|
20 |
"""Crew to do travel planning"""
|
21 |
|
22 |
-
def __init__(self) -> None:
|
23 |
"""Initialize the crew."""
|
24 |
super().__init__()
|
25 |
self.agents_config = 'config/agents.yaml'
|
26 |
self.tasks_config = 'config/tasks.yaml'
|
|
|
27 |
|
28 |
@typing.no_type_check
|
29 |
@agent
|
@@ -35,7 +31,7 @@ class TravelCrew:
|
|
35 |
"""
|
36 |
return Agent(
|
37 |
config=self.agents_config['personalized_activity_planner'],
|
38 |
-
llm=llm,
|
39 |
max_iter=1,
|
40 |
tools=[SerperDevTool(), ScrapeWebsiteTool()], # Example of custom tool, loaded at the beginning of file
|
41 |
allow_delegation=False,
|
@@ -51,7 +47,7 @@ class TravelCrew:
|
|
51 |
"""
|
52 |
return Agent(
|
53 |
config=self.agents_config['restaurant_scout'],
|
54 |
-
llm=llm,
|
55 |
max_iter=1,
|
56 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
57 |
allow_delegation=False,
|
@@ -67,7 +63,7 @@ class TravelCrew:
|
|
67 |
"""
|
68 |
return Agent(
|
69 |
config=self.agents_config['interest_scout'],
|
70 |
-
llm=llm,
|
71 |
max_iter=1,
|
72 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
73 |
allow_delegation=False,
|
@@ -83,7 +79,7 @@ class TravelCrew:
|
|
83 |
"""
|
84 |
return Agent(
|
85 |
config=self.agents_config['itinerary_compiler'],
|
86 |
-
llm=llm,
|
87 |
max_iter=1,
|
88 |
allow_delegation=False,
|
89 |
)
|
@@ -98,7 +94,7 @@ class TravelCrew:
|
|
98 |
"""
|
99 |
return Task(
|
100 |
config=self.tasks_config['personalized_activity_planning_task'],
|
101 |
-
llm=llm,
|
102 |
max_iter=1,
|
103 |
agent=self.personalized_activity_planner(),
|
104 |
)
|
@@ -111,7 +107,10 @@ class TravelCrew:
|
|
111 |
|
112 |
Returns: A task
|
113 |
"""
|
114 |
-
return Task(config=self.tasks_config['interest_scout_task'],
|
|
|
|
|
|
|
115 |
|
116 |
@typing.no_type_check
|
117 |
@task
|
@@ -123,7 +122,7 @@ class TravelCrew:
|
|
123 |
"""
|
124 |
return Task(
|
125 |
config=self.tasks_config['restaurant_scenic_location_scout_task'],
|
126 |
-
llm=llm,
|
127 |
max_iter=1,
|
128 |
agent=self.restaurant_scout(),
|
129 |
)
|
@@ -137,7 +136,10 @@ class TravelCrew:
|
|
137 |
Returns: A task
|
138 |
"""
|
139 |
return Task(
|
140 |
-
config=self.tasks_config['itinerary_compilation_task'],
|
|
|
|
|
|
|
141 |
)
|
142 |
|
143 |
@typing.no_type_check
|
@@ -158,10 +160,14 @@ class TravelCrew:
|
|
158 |
@CrewBase
|
159 |
class AddressSummaryCrew:
|
160 |
"""Address Summary crew"""
|
161 |
-
|
162 |
agents_config = 'config/address_agents.yaml'
|
163 |
tasks_config = 'config/address_tasks.yaml'
|
164 |
|
|
|
|
|
|
|
|
|
|
|
165 |
@typing.no_type_check
|
166 |
@agent
|
167 |
def address_summarizer(self) -> Agent:
|
@@ -172,7 +178,7 @@ class AddressSummaryCrew:
|
|
172 |
"""
|
173 |
return Agent(
|
174 |
config=self.agents_config['address_summarizer'],
|
175 |
-
llm=llm,
|
176 |
max_iter=1,
|
177 |
allow_delegation=False,
|
178 |
)
|
@@ -187,7 +193,7 @@ class AddressSummaryCrew:
|
|
187 |
"""
|
188 |
return Task(
|
189 |
config=self.tasks_config['address_compilation_task'],
|
190 |
-
llm=llm,
|
191 |
max_iter=1,
|
192 |
agent=self.address_summarizer(),
|
193 |
)
|
|
|
10 |
# SerperDevTool: Search Internet, https://docs.crewai.com/tools/serperdevtool
|
11 |
from crewai_tools import ScrapeWebsiteTool, SerperDevTool
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
@CrewBase
|
14 |
class TravelCrew:
|
15 |
"""Crew to do travel planning"""
|
16 |
|
17 |
+
def __init__(self, model_name='Meta-Llama-3.1-70B-Instruct') -> None:
|
18 |
"""Initialize the crew."""
|
19 |
super().__init__()
|
20 |
self.agents_config = 'config/agents.yaml'
|
21 |
self.tasks_config = 'config/tasks.yaml'
|
22 |
+
self.llm = LLM(model='sambanova/%s' % model_name)
|
23 |
|
24 |
@typing.no_type_check
|
25 |
@agent
|
|
|
31 |
"""
|
32 |
return Agent(
|
33 |
config=self.agents_config['personalized_activity_planner'],
|
34 |
+
llm=self.llm,
|
35 |
max_iter=1,
|
36 |
tools=[SerperDevTool(), ScrapeWebsiteTool()], # Example of custom tool, loaded at the beginning of file
|
37 |
allow_delegation=False,
|
|
|
47 |
"""
|
48 |
return Agent(
|
49 |
config=self.agents_config['restaurant_scout'],
|
50 |
+
llm=self.llm,
|
51 |
max_iter=1,
|
52 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
53 |
allow_delegation=False,
|
|
|
63 |
"""
|
64 |
return Agent(
|
65 |
config=self.agents_config['interest_scout'],
|
66 |
+
llm=self.llm,
|
67 |
max_iter=1,
|
68 |
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
69 |
allow_delegation=False,
|
|
|
79 |
"""
|
80 |
return Agent(
|
81 |
config=self.agents_config['itinerary_compiler'],
|
82 |
+
llm=self.llm,
|
83 |
max_iter=1,
|
84 |
allow_delegation=False,
|
85 |
)
|
|
|
94 |
"""
|
95 |
return Task(
|
96 |
config=self.tasks_config['personalized_activity_planning_task'],
|
97 |
+
llm=self.llm,
|
98 |
max_iter=1,
|
99 |
agent=self.personalized_activity_planner(),
|
100 |
)
|
|
|
107 |
|
108 |
Returns: A task
|
109 |
"""
|
110 |
+
return Task(config=self.tasks_config['interest_scout_task'],
|
111 |
+
llm=self.llm,
|
112 |
+
max_iter=1,
|
113 |
+
agent=self.interest_scout())
|
114 |
|
115 |
@typing.no_type_check
|
116 |
@task
|
|
|
122 |
"""
|
123 |
return Task(
|
124 |
config=self.tasks_config['restaurant_scenic_location_scout_task'],
|
125 |
+
llm=self.llm,
|
126 |
max_iter=1,
|
127 |
agent=self.restaurant_scout(),
|
128 |
)
|
|
|
136 |
Returns: A task
|
137 |
"""
|
138 |
return Task(
|
139 |
+
config=self.tasks_config['itinerary_compilation_task'],
|
140 |
+
llm=self.llm,
|
141 |
+
max_iter=1,
|
142 |
+
agent=self.itinerary_compiler()
|
143 |
)
|
144 |
|
145 |
@typing.no_type_check
|
|
|
160 |
@CrewBase
|
161 |
class AddressSummaryCrew:
|
162 |
"""Address Summary crew"""
|
|
|
163 |
agents_config = 'config/address_agents.yaml'
|
164 |
tasks_config = 'config/address_tasks.yaml'
|
165 |
|
166 |
+
def __init__(self, model_name='Meta-Llama-3.1-70B-Instruct') -> None:
|
167 |
+
"""Initialize the crew."""
|
168 |
+
super().__init__()
|
169 |
+
self.llm = LLM(model='sambanova/%s' % model_name)
|
170 |
+
|
171 |
@typing.no_type_check
|
172 |
@agent
|
173 |
def address_summarizer(self) -> Agent:
|
|
|
178 |
"""
|
179 |
return Agent(
|
180 |
config=self.agents_config['address_summarizer'],
|
181 |
+
llm=self.llm,
|
182 |
max_iter=1,
|
183 |
allow_delegation=False,
|
184 |
)
|
|
|
193 |
"""
|
194 |
return Task(
|
195 |
config=self.tasks_config['address_compilation_task'],
|
196 |
+
llm=self.llm,
|
197 |
max_iter=1,
|
198 |
agent=self.address_summarizer(),
|
199 |
)
|