acecalisto3 commited on
Commit
7382aa0
·
verified ·
1 Parent(s): e506b20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +349 -280
app.py CHANGED
@@ -1,297 +1,366 @@
1
  import os
2
  import subprocess
3
- #import openai
4
  from huggingface_hub import InferenceClient
5
  import gradio as gr
6
- import prompts
7
- client = InferenceClient(
8
- "mistralai/Mixtral-8x7B-Instruct-v0.1"
9
- )
 
 
 
 
 
 
 
 
 
 
10
 
 
11
  from agent.prompts import (
12
- ACTION_PROMPT,
13
- ADD_PROMPT,
14
- COMPRESS_HISTORY_PROMPT,
15
- LOG_PROMPT,
16
- LOG_RESPONSE,
17
- MODIFY_PROMPT,
18
- PREFIX,
19
- READ_PROMPT,
20
- TASK_PROMPT,
21
  UNDERSTAND_TEST_RESULTS_PROMPT,
22
  )
23
  from agent.utils import parse_action, parse_file_content, read_python_module_structure
24
 
25
- VERBOSE = False
26
- MAX_HISTORY = 100
27
- MODEL = "gpt-3.5-turbo" # "gpt-4"
28
-
29
-
30
- def run_gpt(
31
- prompt_template,
32
- stop_tokens,
33
- max_tokens,
34
- module_summary,
35
- purpose,
36
- **prompt_kwargs,
37
- ):
38
- content = PREFIX.format(
39
- module_summary=module_summary,
40
- purpose=purpose,
41
- ) + prompt_template.format(**prompt_kwargs)
42
- if VERBOSE:
43
- print(LOG_PROMPT.format(content))
44
-
45
-
46
- #formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
47
- stream = client.text_generation({"role": "system", "content": content}, **generate_kwargs, stream=True, details=True, return_full_text=False)["choices"][0]["message"]["content"]
48
- output = ""
49
-
50
- '''
51
- resp = openai.ChatCompletion.create(
52
- model=MODEL,
53
- messages=[
54
- {"role": "system", "content": content},
55
- ],
56
- temperature=0.0,
57
- max_tokens=max_tokens,
58
- stop=stop_tokens if stop_tokens else None,
59
- )["choices"][0]["message"]["content"]
60
- '''
61
- if VERBOSE:
62
- print(LOG_RESPONSE.format(resp))
63
- return resp
64
-
65
-
66
- def compress_history(purpose, task, history, directory):
67
- module_summary, _, _ = read_python_module_structure(directory)
68
- resp = run_gpt(
69
- COMPRESS_HISTORY_PROMPT,
70
- stop_tokens=["observation:", "task:", "action:", "thought:"],
71
- max_tokens=512,
72
- module_summary=module_summary,
73
- purpose=purpose,
74
- task=task,
75
- history=history,
76
- )
77
- history = "observation: {}\n".format(resp)
78
- return history
79
-
80
-
81
- def call_main(purpose, task, history, directory, action_input):
82
- module_summary, _, _ = read_python_module_structure(directory)
83
- resp = run_gpt(
84
- ACTION_PROMPT,
85
- stop_tokens=["observation:", "task:"],
86
- max_tokens=256,
87
- module_summary=module_summary,
88
- purpose=purpose,
89
- task=task,
90
- history=history,
91
- )
92
- lines = resp.strip().strip("\n").split("\n")
93
- for line in lines:
94
- if line == "":
95
- continue
96
- if line.startswith("thought: "):
97
- history += "{}\n".format(line)
98
- elif line.startswith("action: "):
99
- action_name, action_input = parse_action(line)
100
- history += "{}\n".format(line)
101
- return action_name, action_input, history, task
102
- else:
103
- assert False, "unknown action: {}".format(line)
104
- return "MAIN", None, history, task
105
-
106
-
107
- def call_test(purpose, task, history, directory, action_input):
108
- result = subprocess.run(
109
- ["python", "-m", "pytest", "--collect-only", directory],
110
- capture_output=True,
111
- text=True,
112
- )
113
- if result.returncode != 0:
114
- history += "observation: there are no tests! Test should be written in a test folder under {}\n".format(
115
- directory
116
  )
117
- return "MAIN", None, history, task
118
- result = subprocess.run(
119
- ["python", "-m", "pytest", directory], capture_output=True, text=True
120
- )
121
- if result.returncode == 0:
122
- history += "observation: tests pass\n"
123
- return "MAIN", None, history, task
124
- module_summary, content, _ = read_python_module_structure(directory)
125
- resp = run_gpt(
126
- UNDERSTAND_TEST_RESULTS_PROMPT,
127
- stop_tokens=[],
128
- max_tokens=256,
129
- module_summary=module_summary,
130
- purpose=purpose,
131
- task=task,
132
- history=history,
133
- stdout=result.stdout[:5000], # limit amount of text
134
- stderr=result.stderr[:5000], # limit amount of text
135
- )
136
- history += "observation: tests failed: {}\n".format(resp)
137
- return "MAIN", None, history, task
138
-
139
-
140
- def call_set_task(purpose, task, history, directory, action_input):
141
- module_summary, content, _ = read_python_module_structure(directory)
142
- task = run_gpt(
143
- TASK_PROMPT,
144
- stop_tokens=[],
145
- max_tokens=64,
146
- module_summary=module_summary,
147
- purpose=purpose,
148
- task=task,
149
- history=history,
150
- ).strip("\n")
151
- history += "observation: task has been updated to: {}\n".format(task)
152
- return "MAIN", None, history, task
153
-
154
-
155
- def call_read(purpose, task, history, directory, action_input):
156
- if not os.path.exists(action_input):
157
- history += "observation: file does not exist\n"
158
- return "MAIN", None, history, task
159
- module_summary, content, _ = read_python_module_structure(directory)
160
- f_content = (
161
- content[action_input] if content[action_input] else "< document is empty >"
162
- )
163
- resp = run_gpt(
164
- READ_PROMPT,
165
- stop_tokens=[],
166
- max_tokens=256,
167
- module_summary=module_summary,
168
- purpose=purpose,
169
- task=task,
170
- history=history,
171
- file_path=action_input,
172
- file_contents=f_content,
173
- ).strip("\n")
174
- history += "observation: {}\n".format(resp)
175
- return "MAIN", None, history, task
176
-
177
-
178
- def call_modify(purpose, task, history, directory, action_input):
179
- if not os.path.exists(action_input):
180
- history += "observation: file does not exist\n"
181
- return "MAIN", None, history, task
182
- (
183
- module_summary,
184
- content,
185
- _,
186
- ) = read_python_module_structure(directory)
187
- f_content = (
188
- content[action_input] if content[action_input] else "< document is empty >"
189
- )
190
- resp = run_gpt(
191
- MODIFY_PROMPT,
192
- stop_tokens=["action:", "thought:", "observation:"],
193
- max_tokens=2048,
194
- module_summary=module_summary,
195
- purpose=purpose,
196
- task=task,
197
- history=history,
198
- file_path=action_input,
199
- file_contents=f_content,
200
- )
201
- new_contents, description = parse_file_content(resp)
202
- if new_contents is None:
203
- history += "observation: failed to modify file\n"
204
- return "MAIN", None, history, task
205
-
206
- with open(action_input, "w") as f:
207
- f.write(new_contents)
208
-
209
- history += "observation: file successfully modified\n"
210
- history += "observation: {}\n".format(description)
211
- return "MAIN", None, history, task
212
-
213
-
214
- def call_add(purpose, task, history, directory, action_input):
215
- d = os.path.dirname(action_input)
216
- if not d.startswith(directory):
217
- history += "observation: files must be under directory {}\n".format(directory)
218
- elif not action_input.endswith(".py"):
219
- history += "observation: can only write .py files\n"
220
- else:
221
- if d and not os.path.exists(d):
222
- os.makedirs(d)
223
  if not os.path.exists(action_input):
224
- module_summary, _, _ = read_python_module_structure(directory)
225
- resp = run_gpt(
226
- ADD_PROMPT,
227
- stop_tokens=["action:", "thought:", "observation:"],
228
- max_tokens=2048,
229
- module_summary=module_summary,
230
- purpose=purpose,
231
- task=task,
232
- history=history,
233
- file_path=action_input,
234
- )
235
- new_contents, description = parse_file_content(resp)
236
- if new_contents is None:
237
- history += "observation: failed to write file\n"
238
- return "MAIN", None, history, task
239
-
240
- with open(action_input, "w") as f:
241
- f.write(new_contents)
242
-
243
- history += "observation: file successfully written\n"
244
- history += "obsertation: {}\n".format(description)
245
- else:
246
- history += "observation: file already exists\n"
247
- return "MAIN", None, history, task
248
 
 
 
249
 
250
- NAME_TO_FUNC = {
251
- "MAIN": call_main,
252
- "UPDATE-TASK": call_set_task,
253
- "MODIFY-FILE": call_modify,
254
- "READ-FILE": call_read,
255
- "ADD-FILE": call_add,
256
- "TEST": call_test,
257
- }
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
- def run_action(purpose, task, history, directory, action_name, action_input):
261
- if action_name == "COMPLETE":
262
- exit(0)
263
 
264
- # compress the history when it is long
265
- if len(history.split("\n")) > MAX_HISTORY:
266
- if VERBOSE:
267
- print("COMPRESSING HISTORY")
268
- history = compress_history(purpose, task, history, directory)
269
-
270
- assert action_name in NAME_TO_FUNC
271
-
272
- print("RUN: ", action_name, action_input)
273
- return NAME_TO_FUNC[action_name](purpose, task, history, directory, action_input)
274
-
275
-
276
- def run(purpose, directory, task=None):
277
- history = ""
278
- action_name = "UPDATE-TASK" if task is None else "MAIN"
279
- action_input = None
280
- while True:
281
- print("")
282
- print("")
283
- print("---")
284
- print("purpose:", purpose)
285
- print("task:", task)
286
- print("---")
287
- print(history)
288
- print("---")
289
-
290
- action_name, action_input, history, task = run_action(
291
- purpose,
292
- task,
293
- history,
294
- directory,
295
- action_name,
296
- action_input,
297
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import subprocess
 
3
  from huggingface_hub import InferenceClient
4
  import gradio as gr
5
+ import random
6
+ import time
7
+ from typing import List, Dict
8
+
9
+ # Simulated agent and tool libraries
10
+ AGENT_TYPES = ["Task Executor", "Information Retriever", "Decision Maker", "Data Analyzer"]
11
+ TOOL_TYPES = ["Web Scraper", "Database Connector", "API Caller", "File Handler", "Text Processor"]
12
+
13
+ # Initialize Hugging Face client
14
+ client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
15
+
16
+ VERBOSE = False
17
+ MAX_HISTORY = 100
18
+ MODEL = "mistralai/Mixtral-8x7B-Instruct-v0.1"
19
 
20
+ # Import necessary prompts and functions from the existing code
21
  from agent.prompts import (
22
+ ACTION_PROMPT, ADD_PROMPT, COMPRESS_HISTORY_PROMPT, LOG_PROMPT,
23
+ LOG_RESPONSE, MODIFY_PROMPT, PREFIX, READ_PROMPT, TASK_PROMPT,
 
 
 
 
 
 
 
24
  UNDERSTAND_TEST_RESULTS_PROMPT,
25
  )
26
  from agent.utils import parse_action, parse_file_content, read_python_module_structure
27
 
28
+ class Agent:
29
+ def __init__(self, name: str, agent_type: str, complexity: int):
30
+ self.name = name
31
+ self.type = agent_type
32
+ self.complexity = complexity
33
+ self.tools = []
34
+
35
+ def add_tool(self, tool):
36
+ self.tools.append(tool)
37
+
38
+ def __str__(self):
39
+ return f"{self.name} ({self.type}) - Complexity: {self.complexity}"
40
+
41
+ class Tool:
42
+ def __init__(self, name: str, tool_type: str):
43
+ self.name = name
44
+ self.type = tool_type
45
+
46
+ def __str__(self):
47
+ return f"{self.name} ({self.type})"
48
+
49
+ class Pypelyne:
50
+ def __init__(self):
51
+ self.agents: List[Agent] = []
52
+ self.tools: List[Tool] = []
53
+ self.history = ""
54
+ self.task = None
55
+ self.purpose = None
56
+ self.directory = None
57
+
58
+ def add_agent(self, agent: Agent):
59
+ self.agents.append(agent)
60
+
61
+ def add_tool(self, tool: Tool):
62
+ self.tools.append(tool)
63
+
64
+ def generate_chat_app(self):
65
+ time.sleep(2) # Simulate processing time
66
+ return f"Chat app generated with {len(self.agents)} agents and {len(self.tools)} tools."
67
+
68
+ def run_gpt(self, prompt_template, stop_tokens, max_tokens, **prompt_kwargs):
69
+ content = PREFIX.format(
70
+ module_summary=read_python_module_structure(self.directory)[0],
71
+ purpose=self.purpose,
72
+ ) + prompt_template.format(**prompt_kwargs)
73
+
74
+ if VERBOSE:
75
+ print(LOG_PROMPT.format(content))
76
+
77
+ stream = client.text_generation(
78
+ prompt=content,
79
+ max_new_tokens=max_tokens,
80
+ stop_sequences=stop_tokens if stop_tokens else None,
81
+ do_sample=True,
82
+ temperature=0.7,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  )
84
+
85
+ resp = "".join(token for token in stream)
86
+
87
+ if VERBOSE:
88
+ print(LOG_RESPONSE.format(resp))
89
+ return resp
90
+
91
+ def compress_history(self):
92
+ resp = self.run_gpt(
93
+ COMPRESS_HISTORY_PROMPT,
94
+ stop_tokens=["observation:", "task:", "action:", "thought:"],
95
+ max_tokens=512,
96
+ task=self.task,
97
+ history=self.history,
98
+ )
99
+ self.history = f"observation: {resp}\n"
100
+
101
+ def run_action(self, action_name, action_input):
102
+ if action_name == "COMPLETE":
103
+ return "Task completed."
104
+
105
+ if len(self.history.split("\n")) > MAX_HISTORY:
106
+ if VERBOSE:
107
+ print("COMPRESSING HISTORY")
108
+ self.compress_history()
109
+
110
+ action_funcs = {
111
+ "MAIN": self.call_main,
112
+ "UPDATE-TASK": self.call_set_task,
113
+ "MODIFY-FILE": self.call_modify,
114
+ "READ-FILE": self.call_read,
115
+ "ADD-FILE": self.call_add,
116
+ "TEST": self.call_test,
117
+ }
118
+
119
+ if action_name not in action_funcs:
120
+ return f"Unknown action: {action_name}"
121
+
122
+ print(f"RUN: {action_name} {action_input}")
123
+ return action_funcs[action_name](action_input)
124
+
125
+ def call_main(self, action_input):
126
+ resp = self.run_gpt(
127
+ ACTION_PROMPT,
128
+ stop_tokens=["observation:", "task:"],
129
+ max_tokens=256,
130
+ task=self.task,
131
+ history=self.history,
132
+ )
133
+ lines = resp.strip().strip("\n").split("\n")
134
+ for line in lines:
135
+ if line == "":
136
+ continue
137
+ if line.startswith("thought: "):
138
+ self.history += f"{line}\n"
139
+ elif line.startswith("action: "):
140
+ action_name, action_input = parse_action(line)
141
+ self.history += f"{line}\n"
142
+ return self.run_action(action_name, action_input)
143
+ return "No valid action found."
144
+
145
+ def call_set_task(self, action_input):
146
+ self.task = self.run_gpt(
147
+ TASK_PROMPT,
148
+ stop_tokens=[],
149
+ max_tokens=64,
150
+ task=self.task,
151
+ history=self.history,
152
+ ).strip("\n")
153
+ self.history += f"observation: task has been updated to: {self.task}\n"
154
+ return f"Task updated: {self.task}"
155
+
156
+ def call_modify(self, action_input):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  if not os.path.exists(action_input):
158
+ self.history += "observation: file does not exist\n"
159
+ return "File does not exist."
160
+
161
+ content = read_python_module_structure(self.directory)[1]
162
+ f_content = content[action_input] if content[action_input] else "< document is empty >"
163
+
164
+ resp = self.run_gpt(
165
+ MODIFY_PROMPT,
166
+ stop_tokens=["action:", "thought:", "observation:"],
167
+ max_tokens=2048,
168
+ task=self.task,
169
+ history=self.history,
170
+ file_path=action_input,
171
+ file_contents=f_content,
172
+ )
173
+ new_contents, description = parse_file_content(resp)
174
+ if new_contents is None:
175
+ self.history += "observation: failed to modify file\n"
176
+ return "Failed to modify file."
 
 
 
 
 
177
 
178
+ with open(action_input, "w") as f:
179
+ f.write(new_contents)
180
 
181
+ self.history += f"observation: file successfully modified\n"
182
+ self.history += f"observation: {description}\n"
183
+ return f"File modified: {action_input}"
 
 
 
 
 
184
 
185
+ def call_read(self, action_input):
186
+ if not os.path.exists(action_input):
187
+ self.history += "observation: file does not exist\n"
188
+ return "File does not exist."
189
+
190
+ content = read_python_module_structure(self.directory)[1]
191
+ f_content = content[action_input] if content[action_input] else "< document is empty >"
192
+
193
+ resp = self.run_gpt(
194
+ READ_PROMPT,
195
+ stop_tokens=[],
196
+ max_tokens=256,
197
+ task=self.task,
198
+ history=self.history,
199
+ file_path=action_input,
200
+ file_contents=f_content,
201
+ ).strip("\n")
202
+ self.history += f"observation: {resp}\n"
203
+ return f"File read: {action_input}"
204
+
205
+ def call_add(self, action_input):
206
+ d = os.path.dirname(action_input)
207
+ if not d.startswith(self.directory):
208
+ self.history += f"observation: files must be under directory {self.directory}\n"
209
+ return f"Invalid directory: {d}"
210
+ elif not action_input.endswith(".py"):
211
+ self.history += "observation: can only write .py files\n"
212
+ return "Only .py files are allowed."
213
+ else:
214
+ if d and not os.path.exists(d):
215
+ os.makedirs(d)
216
+ if not os.path.exists(action_input):
217
+ resp = self.run_gpt(
218
+ ADD_PROMPT,
219
+ stop_tokens=["action:", "thought:", "observation:"],
220
+ max_tokens=2048,
221
+ task=self.task,
222
+ history=self.history,
223
+ file_path=action_input,
224
+ )
225
+ new_contents, description = parse_file_content(resp)
226
+ if new_contents is None:
227
+ self.history += "observation: failed to write file\n"
228
+ return "Failed to write file."
229
+
230
+ with open(action_input, "w") as f:
231
+ f.write(new_contents)
232
+
233
+ self.history += "observation: file successfully written\n"
234
+ self.history += f"observation: {description}\n"
235
+ return f"File added: {action_input}"
236
+ else:
237
+ self.history += "observation: file already exists\n"
238
+ return "File already exists."
239
+
240
+ def call_test(self, action_input):
241
+ result = subprocess.run(
242
+ ["python", "-m", "pytest", "--collect-only", self.directory],
243
+ capture_output=True,
244
+ text=True,
245
+ )
246
+ if result.returncode != 0:
247
+ self.history += f"observation: there are no tests! Test should be written in a test folder under {self.directory}\n"
248
+ return "No tests found."
249
+ result = subprocess.run(
250
+ ["python", "-m", "pytest", self.directory], capture_output=True, text=True
251
+ )
252
+ if result.returncode == 0:
253
+ self.history += "observation: tests pass\n"
254
+ return "All tests passed."
255
+
256
+ resp = self.run_gpt(
257
+ UNDERSTAND_TEST_RESULTS_PROMPT,
258
+ stop_tokens=[],
259
+ max_tokens=256,
260
+ task=self.task,
261
+ history=self.history,
262
+ stdout=result.stdout[:5000],
263
+ stderr=result.stderr[:5000],
264
+ )
265
+ self.history += f"observation: tests failed: {resp}\n"
266
+ return f"Tests failed: {resp}"
267
 
268
+ pypelyne = Pypelyne()
 
 
269
 
270
+ def create_agent(name: str, agent_type: str, complexity: int) -> str:
271
+ agent = Agent(name, agent_type, complexity)
272
+ pypelyne.add_agent(agent)
273
+ return f"Agent created: {agent}"
274
+
275
+ def create_tool(name: str, tool_type: str) -> str:
276
+ tool = Tool(name, tool_type)
277
+ pypelyne.add_tool(tool)
278
+ return f"Tool created: {tool}"
279
+
280
+ def assign_tool(agent_name: str, tool_name: str) -> str:
281
+ agent = next((a for a in pypelyne.agents if a.name == agent_name), None)
282
+ tool = next((t for t in pypelyne.tools if t.name == tool_name), None)
283
+
284
+ if agent and tool:
285
+ agent.add_tool(tool)
286
+ return f"Tool '{tool.name}' assigned to agent '{agent.name}'"
287
+ else:
288
+ return "Agent or tool not found."
289
+
290
+ def generate_chat_app() -> str:
291
+ return pypelyne.generate_chat_app()
292
+
293
+ def list_agents() -> str:
294
+ return "\n".join(str(agent) for agent in pypelyne.agents) or "No agents created yet."
295
+
296
+ def list_tools() -> str:
297
+ return "\n".join(str(tool) for tool in pypelyne.tools) or "No tools created yet."
298
+
299
+ def chat_with_pypelyne(message: str) -> str:
300
+ return pypelyne.run_action("MAIN", message)
301
+
302
+ def set_purpose_and_directory(purpose: str, directory: str) -> str:
303
+ pypelyne.purpose = purpose
304
+ pypelyne.directory = directory
305
+ return f"Purpose set to: {purpose}\nWorking directory set to: {directory}"
306
+
307
+ with gr.Blocks() as app:
308
+ gr.Markdown("# Welcome to Pypelyne")
309
+ gr.Markdown("Create your custom pipeline with agents and tools, then chat with it!")
310
+
311
+ with gr.Tab("Setup"):
312
+ purpose_input = gr.Textbox(label="Set Purpose")
313
+ directory_input = gr.Textbox(label="Set Working Directory")
314
+ setup_btn = gr.Button("Set Purpose and Directory")
315
+ setup_output = gr.Textbox(label="Setup Output")
316
+ setup_btn.click(set_purpose_and_directory, inputs=[purpose_input, directory_input], outputs=setup_output)
317
+
318
+ with gr.Tab("Create Agents"):
319
+ agent_name = gr.Textbox(label="Agent Name")
320
+ agent_type = gr.Dropdown(choices=AGENT_TYPES, label="Agent Type")
321
+ agent_complexity = gr.Slider(minimum=1, maximum=10, step=1, label="Agent Complexity")
322
+ create_agent_btn = gr.Button("Create Agent")
323
+ agent_output = gr.Textbox(label="Output")
324
+ create_agent_btn.click(create_agent, inputs=[agent_name, agent_type, agent_complexity], outputs=agent_output)
325
+
326
+ with gr.Tab("Create Tools"):
327
+ tool_name = gr.Textbox(label="Tool Name")
328
+ tool_type = gr.Dropdown(choices=TOOL_TYPES, label="Tool Type")
329
+ create_tool_btn = gr.Button("Create Tool")
330
+ tool_output = gr.Textbox(label="Output")
331
+ create_tool_btn.click(create_tool, inputs=[tool_name, tool_type], outputs=tool_output)
332
+
333
+ with gr.Tab("Assign Tools"):
334
+ agent_select = gr.Dropdown(choices=[], label="Select Agent")
335
+ tool_select = gr.Dropdown(choices=[], label="Select Tool")
336
+ assign_tool_btn = gr.Button("Assign Tool")
337
+ assign_output = gr.Textbox(label="Output")
338
+ assign_tool_btn.click(assign_tool, inputs=[agent_select, tool_select], outputs=assign_output)
339
+
340
+ with gr.Tab("Generate Chat App"):
341
+ generate_btn = gr.Button("Generate Chat App")
342
+ generate_output = gr.Textbox(label="Output")
343
+ generate_btn.click(generate_chat_app, outputs=generate_output)
344
+
345
+ with gr.Tab("Chat with Pypelyne"):
346
+ chat_input = gr.Textbox(label="Your Message")
347
+ chat_output = gr.Textbox(label="Pypelyne's Response")
348
+ chat_btn = gr.Button("Send")
349
+ chat_btn.click(chat_with_pypelyne, inputs=chat_input, outputs=chat_output)
350
+
351
+ with gr.Tab("View Pypelyne"):
352
+ view_agents_btn = gr.Button("View Agents")
353
+ view_tools_btn = gr.Button("View Tools")
354
+ view_output = gr.Textbox(label="Pypelyne Components")
355
+ view_agents_btn.click(list_agents, outputs=view_output)
356
+ view_tools_btn.click(list_tools, outputs=view_output)
357
+
358
+ def update_dropdowns():
359
+ return gr.Dropdown.update(choices=[agent.name for agent in pypelyne.agents]), \
360
+ gr.Dropdown.update(choices=[tool.name for tool in pypelyne.tools])
361
+
362
+ create_agent_btn.click(update_dropdowns, outputs=[agent_select, tool_select])
363
+ create_tool_btn.click(update_dropdowns, outputs=[agent_select, tool_select])
364
+
365
+ if __name__ == "__main__":
366
+ app.launch()