acecalisto3 commited on
Commit
f5f9947
·
verified ·
1 Parent(s): f8b65de

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +579 -300
agent.py CHANGED
@@ -1,302 +1,581 @@
1
- import os
2
- import subprocess
3
-
4
- import openai
5
-
6
- from agent.prompts import (
7
- ACTION_PROMPT,
8
- ADD_PROMPT,
9
- COMPRESS_HISTORY_PROMPT,
10
- LOG_PROMPT,
11
- LOG_RESPONSE,
12
- MODIFY_PROMPT,
13
- PREFIX,
14
- READ_PROMPT,
15
- TASK_PROMPT,
16
- UNDERSTAND_TEST_RESULTS_PROMPT,
17
  )
18
- from agent.utils import parse_action, parse_file_content, read_python_module_structure
19
-
20
- VERBOSE = False
21
- MAX_HISTORY = 100
22
- MODEL = "gpt-3.5-turbo" # "gpt-4"
23
-
24
-
25
- def run_gpt(
26
- prompt_template,
27
- stop_tokens,
28
- max_tokens,
29
- module_summary,
30
- purpose,
31
- **prompt_kwargs,
32
- ):
33
- content = PREFIX.format(
34
- module_summary=module_summary,
35
- purpose=purpose,
36
- ) + prompt_template.format(**prompt_kwargs)
37
- if VERBOSE:
38
- print(LOG_PROMPT.format(content))
39
- resp = openai.ChatCompletion.create(
40
- model=MODEL,
41
- messages=[
42
- {"role": "system", "content": content},
43
- ],
44
- temperature=0.0,
45
- max_tokens=max_tokens,
46
- stop=stop_tokens if stop_tokens else None,
47
- )["choices"][0]["message"]["content"]
48
- if VERBOSE:
49
- print(LOG_RESPONSE.format(resp))
50
- return resp
51
-
52
- def generate(prompt, history, temperature):
53
- seed = random.randint(1, 1111111111111111)
54
- generate_kwargs = {
55
- "temperature": temperature,
56
- "max_new_tokens": 256,
57
- "top_p": 0.95,
58
- "repetition_penalty": 1.0,
59
- "do_sample": True,
60
- "seed": seed,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
- formatted_prompt = format_prompt_var(f"{prompt}", history)
63
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
64
- output = ""
65
-
66
- for response in stream:
67
- output += response.token.text
68
- yield output
69
-
70
-
71
- def compress_history(purpose, task, history, directory):
72
- module_summary, _, _ = read_python_module_structure(directory)
73
- resp = run_gpt(
74
- COMPRESS_HISTORY_PROMPT,
75
- stop_tokens=["observation:", "task:", "action:", "thought:"],
76
- max_tokens=512,
77
- module_summary=module_summary,
78
- purpose=purpose,
79
- task=task,
80
- history=history,
81
- )
82
- history = "observation: {}\n".format(resp)
83
- return history
84
-
85
-
86
- def call_main(purpose, task, history, directory, action_input):
87
- module_summary, _, _ = read_python_module_structure(directory)
88
- resp = run_gpt(
89
- ACTION_PROMPT,
90
- stop_tokens=["observation:", "task:"],
91
- max_tokens=256,
92
- module_summary=module_summary,
93
- purpose=purpose,
94
- task=task,
95
- history=history,
96
- )
97
- lines = resp.strip().strip("\n").split("\n")
98
- for line in lines:
99
- if line == "":
100
- continue
101
- if line.startswith("thought: "):
102
- history += "{}\n".format(line)
103
- elif line.startswith("action: "):
104
- action_name, action_input = parse_action(line)
105
- history += "{}\n".format(line)
106
- return action_name, action_input, history, task
107
- else:
108
- assert False, "unknown action: {}".format(line)
109
- return "MAIN", None, history, task
110
-
111
-
112
- def call_test(purpose, task, history, directory, action_input):
113
- result = subprocess.run(
114
- ["python", "-m", "pytest", "--collect-only", directory],
115
- capture_output=True,
116
- text=True,
117
- )
118
- if result.returncode != 0:
119
- history += "observation: there are no tests! Test should be written in a test folder under {}\n".format(
120
- directory
121
- )
122
- return "MAIN", None, history, task
123
- result = subprocess.run(
124
- ["python", "-m", "pytest", directory], capture_output=True, text=True
125
- )
126
- if result.returncode == 0:
127
- history += "observation: tests pass\n"
128
- return "MAIN", None, history, task
129
- module_summary, content, _ = read_python_module_structure(directory)
130
- resp = run_gpt(
131
- UNDERSTAND_TEST_RESULTS_PROMPT,
132
- stop_tokens=[],
133
- max_tokens=256,
134
- module_summary=module_summary,
135
- purpose=purpose,
136
- task=task,
137
- history=history,
138
- stdout=result.stdout[:5000], # limit amount of text
139
- stderr=result.stderr[:5000], # limit amount of text
140
- )
141
- history += "observation: tests failed: {}\n".format(resp)
142
- return "MAIN", None, history, task
143
-
144
-
145
- def call_set_task(purpose, task, history, directory, action_input):
146
- module_summary, content, _ = read_python_module_structure(directory)
147
- task = run_gpt(
148
- TASK_PROMPT,
149
- stop_tokens=[],
150
- max_tokens=64,
151
- module_summary=module_summary,
152
- purpose=purpose,
153
- task=task,
154
- history=history,
155
- ).strip("\n")
156
- history += "observation: task has been updated to: {}\n".format(task)
157
- return "MAIN", None, history, task
158
-
159
-
160
- def call_read(purpose, task, history, directory, action_input):
161
- if not os.path.exists(action_input):
162
- history += "observation: file does not exist\n"
163
- return "MAIN", None, history, task
164
- module_summary, content, _ = read_python_module_structure(directory)
165
- f_content = (
166
- content[action_input] if content[action_input] else "< document is empty >"
167
- )
168
- resp = run_gpt(
169
- READ_PROMPT,
170
- stop_tokens=[],
171
- max_tokens=256,
172
- module_summary=module_summary,
173
- purpose=purpose,
174
- task=task,
175
- history=history,
176
- file_path=action_input,
177
- file_contents=f_content,
178
- ).strip("\n")
179
- history += "observation: {}\n".format(resp)
180
- return "MAIN", None, history, task
181
-
182
-
183
- def call_modify(purpose, task, history, directory, action_input):
184
- if not os.path.exists(action_input):
185
- history += "observation: file does not exist\n"
186
- return "MAIN", None, history, task
187
- (
188
- module_summary,
189
- content,
190
- _,
191
- ) = read_python_module_structure(directory)
192
- f_content = (
193
- content[action_input] if content[action_input] else "< document is empty >"
194
- )
195
- resp = run_gpt(
196
- MODIFY_PROMPT,
197
- stop_tokens=["action:", "thought:", "observation:"],
198
- max_tokens=2048,
199
- module_summary=module_summary,
200
- purpose=purpose,
201
- task=task,
202
- history=history,
203
- file_path=action_input,
204
- file_contents=f_content,
205
- )
206
- new_contents, description = parse_file_content(resp)
207
- if new_contents is None:
208
- history += "observation: failed to modify file\n"
209
- return "MAIN", None, history, task
210
-
211
- with open(action_input, "w") as f:
212
- f.write(new_contents)
213
-
214
- history += "observation: file successfully modified\n"
215
- history += "observation: {}\n".format(description)
216
- return "MAIN", None, history, task
217
-
218
-
219
- def call_add(purpose, task, history, directory, action_input):
220
- d = os.path.dirname(action_input)
221
- if not d.startswith(directory):
222
- history += "observation: files must be under directory {}\n".format(directory)
223
- elif not action_input.endswith(".py"):
224
- history += "observation: can only write .py files\n"
225
- else:
226
- if d and not os.path.exists(d):
227
- os.makedirs(d)
228
- if not os.path.exists(action_input):
229
- module_summary, _, _ = read_python_module_structure(directory)
230
- resp = run_gpt(
231
- ADD_PROMPT,
232
- stop_tokens=["action:", "thought:", "observation:"],
233
- max_tokens=2048,
234
- module_summary=module_summary,
235
- purpose=purpose,
236
- task=task,
237
- history=history,
238
- file_path=action_input,
239
- )
240
- new_contents, description = parse_file_content(resp)
241
- if new_contents is None:
242
- history += "observation: failed to write file\n"
243
- return "MAIN", None, history, task
244
-
245
- with open(action_input, "w") as f:
246
- f.write(new_contents)
247
-
248
- history += "observation: file successfully written\n"
249
- history += "obsertation: {}\n".format(description)
250
- else:
251
- history += "observation: file already exists\n"
252
- return "MAIN", None, history, task
253
-
254
-
255
- NAME_TO_FUNC = {
256
- "MAIN": call_main,
257
- "UPDATE-TASK": call_set_task,
258
- "MODIFY-FILE": call_modify,
259
- "READ-FILE": call_read,
260
- "ADD-FILE": call_add,
261
- "TEST": call_test,
262
- }
263
-
264
-
265
- def run_action(purpose, task, history, directory, action_name, action_input):
266
- if action_name == "COMPLETE":
267
- exit(0)
268
-
269
- # compress the history when it is long
270
- if len(history.split("\n")) > MAX_HISTORY:
271
- if VERBOSE:
272
- print("COMPRESSING HISTORY")
273
- history = compress_history(purpose, task, history, directory)
274
-
275
- assert action_name in NAME_TO_FUNC
276
-
277
- print("RUN: ", action_name, action_input)
278
- return NAME_TO_FUNC[action_name](purpose, task, history, directory, action_input)
279
-
280
-
281
- def run(purpose, directory, task=None):
282
- history = ""
283
- action_name = "UPDATE-TASK" if task is None else "MAIN"
284
- action_input = None
285
- while True:
286
- print("")
287
- print("")
288
- print("---")
289
- print("purpose:", purpose)
290
- print("task:", task)
291
- print("---")
292
- print(history)
293
- print("---")
294
-
295
- action_name, action_input, history, task = run_action(
296
- purpose,
297
- task,
298
- history,
299
- directory,
300
- action_name,
301
- action_input,
302
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Optional
2
+ from cust_types import (
3
+ Code,
4
+ Prompt,
5
+ AppType,
6
+ File,
7
+ Space,
8
+ Tutorial,
9
+ WebApp,
10
+ GradioApp,
11
+ StreamlitApp,
12
+ ReactApp,
 
 
 
 
13
  )
14
+
15
+ def createLlamaPrompt(
16
+ app_type: AppType,
17
+ app_name: str,
18
+ app_description: str,
19
+ app_features: List[str],
20
+ app_dependencies: List[str],
21
+ app_space: Optional[Space] = None,
22
+ app_tutorial: Optional[Tutorial] = None,
23
+ ) -> Prompt:
24
+ """
25
+ Generates a prompt for a Llama model to create a web application.
26
+ """
27
+ prompt = f"""
28
+ I need your help creating a {app_type} web application.
29
+ Here are the details:
30
+
31
+ - Name: {app_name}
32
+ - Description: {app_description}
33
+ - Features: {app_features}
34
+ - Dependencies: {app_dependencies}
35
+ - Space: {app_space}
36
+ - Tutorial: {app_tutorial}
37
+
38
+ Please generate the code for this application.
39
+ """
40
+ return Prompt(prompt=prompt)
41
+
42
+ def createSpace(
43
+ app_type: AppType,
44
+ app_name: str,
45
+ app_description: str,
46
+ app_features: List[str],
47
+ app_dependencies: List[str],
48
+ app_space: Optional[Space] = None,
49
+ app_tutorial: Optional[Tutorial] = None,
50
+ ) -> Space:
51
+ """
52
+ Generates a space for a web application.
53
+ """
54
+ space = f"""
55
+ **{app_name}**
56
+
57
+ {app_description}
58
+
59
+ **Features:**
60
+ - {', '.join(app_features)}
61
+
62
+ **Dependencies:**
63
+ - {', '.join(app_dependencies)}
64
+
65
+ **Space:**
66
+ {app_space}
67
+
68
+ **Tutorial:**
69
+ {app_tutorial}
70
+ """
71
+ return Space(space=space)
72
+
73
+ def isPythonOrGradioAppPrompt(
74
+ app_type: AppType,
75
+ app_name: str,
76
+ app_description: str,
77
+ app_features: List[str],
78
+ app_dependencies: List[str],
79
+ app_space: Optional[Space] = None,
80
+ app_tutorial: Optional[Tutorial] = None,
81
+ ) -> Prompt:
82
+ """
83
+ Generates a prompt to determine if a web application is a Python or Gradio application.
84
+ """
85
+ prompt = f"""
86
+ Is the following web application a Python or Gradio application?
87
+
88
+ {createSpace(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).space}
89
+
90
+ Please answer with either "Python" or "Gradio".
91
+ """
92
+ return Prompt(prompt=prompt)
93
+
94
+ def isReactAppPrompt(
95
+ app_type: AppType,
96
+ app_name: str,
97
+ app_description: str,
98
+ app_features: List[str],
99
+ app_dependencies: List[str],
100
+ app_space: Optional[Space] = None,
101
+ app_tutorial: Optional[Tutorial] = None,
102
+ ) -> Prompt:
103
+ """
104
+ Generates a prompt to determine if a web application is a React application.
105
+ """
106
+ prompt = f"""
107
+ Is the following web application a React application?
108
+
109
+ {createSpace(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).space}
110
+
111
+ Please answer with either "Yes" or "No".
112
+ """
113
+ return Prompt(prompt=prompt)
114
+
115
+ def isStreamlitAppPrompt(
116
+ app_type: AppType,
117
+ app_name: str,
118
+ app_description: str,
119
+ app_features: List[str],
120
+ app_dependencies: List[str],
121
+ app_space: Optional[Space] = None,
122
+ app_tutorial: Optional[Tutorial] = None,
123
+ ) -> Prompt:
124
+ """
125
+ Generates a prompt to determine if a web application is a Streamlit application.
126
+ """
127
+ prompt = f"""
128
+ Is the following web application a Streamlit application?
129
+
130
+ {createSpace(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).space}
131
+
132
+ Please answer with either "Yes" or "No".
133
+ """
134
+ return Prompt(prompt=prompt)
135
+
136
+ def getWebApp(
137
+ app_type: AppType,
138
+ app_name: str,
139
+ app_description: str,
140
+ app_features: List[str],
141
+ app_dependencies: List[str],
142
+ app_space: Optional[Space] = None,
143
+ app_tutorial: Optional[Tutorial] = None,
144
+ ) -> WebApp:
145
+ """
146
+ Generates code for a web application.
147
+ """
148
+ code = f"""
149
+ <!DOCTYPE html>
150
+ <html lang="en">
151
+ <head>
152
+ <meta charset="UTF-8">
153
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
154
+ <title>{app_name}</title>
155
+ </head>
156
+ <body>
157
+ <h1>{app_name}</h1>
158
+ <p>{app_description}</p>
159
+ </body>
160
+ </html>
161
+ """
162
+ return WebApp(code=code, language="html")
163
+
164
+ def getGradioApp(
165
+ app_type: AppType,
166
+ app_name: str,
167
+ app_description: str,
168
+ app_features: List[str],
169
+ app_dependencies: List[str],
170
+ app_space: Optional[Space] = None,
171
+ app_tutorial: Optional[Tutorial] = None,
172
+ ) -> GradioApp:
173
+ """
174
+ Generates code for a Gradio application.
175
+ """
176
+ code = f"""
177
+ import gradio as gr
178
+ def greet(name):
179
+ return f"Hello, {name}!"
180
+ demo = gr.Interface(greet, "text", "text")
181
+ if __name__ == "__main__":
182
+ demo.launch()
183
+ """
184
+ return GradioApp(code=code, language="python")
185
+
186
+ def getReactApp(
187
+ app_type: AppType,
188
+ app_name: str,
189
+ app_description: str,
190
+ app_features: List[str],
191
+ app_dependencies: List[str],
192
+ app_space: Optional[Space] = None,
193
+ app_tutorial: Optional[Tutorial] = None,
194
+ ) -> ReactApp:
195
+ """
196
+ Generates code for a React application.
197
+ """
198
+ code = f"""
199
+ import React from 'react';
200
+ function App() {{
201
+ return (
202
+ <div className="App">
203
+ <h1>{app_name}</h1>
204
+ <p>{app_description}</p>
205
+ </div>
206
+ );
207
+ }}
208
+ export default App;
209
+ """
210
+ return ReactApp(code=code, language="javascript")
211
+
212
+ def getStreamlitApp(
213
+ app_type: AppType,
214
+ app_name: str,
215
+ app_description: str,
216
+ app_features: List[str],
217
+ app_dependencies: List[str],
218
+ app_space: Optional[Space] = None,
219
+ app_tutorial: Optional[Tutorial] = None,
220
+ ) -> StreamlitApp:
221
+ """
222
+ Generates code for a Streamlit application.
223
+ """
224
+ code = f"""
225
+ import streamlit as st
226
+ st.title('{app_name}')
227
+ st.write('{app_description}')
228
+ """
229
+ return StreamlitApp(code=code, language="python")
230
+
231
+ def parseTutorial(
232
+ app_type: AppType,
233
+ app_name: str,
234
+ app_description: str,
235
+ app_features: List[str],
236
+ app_dependencies: List[str],
237
+ app_space: Optional[Space] = None,
238
+ app_tutorial: Optional[Tutorial] = None,
239
+ ) -> Tutorial:
240
+ """
241
+ Parses a tutorial for a web application.
242
+ """
243
+ tutorial = f"""
244
+ ## {app_name} Tutorial
245
+
246
+ **Introduction**
247
+ {app_description}
248
+
249
+ **Prerequisites**
250
+ - Basic knowledge of {app_type} development
251
+ - Familiarity with {', '.join(app_dependencies)}
252
+
253
+ **Steps**
254
+ 1. {app_features[0]}
255
+ 2. {app_features[1]}
256
+ 3. {app_features[2]}
257
+
258
+ **Conclusion**
259
+ Congratulations! You have successfully created a {app_name} application.
260
+ """
261
+ return Tutorial(tutorial=tutorial)
262
+
263
+ def generateFiles(
264
+ app_type: AppType,
265
+ app_name: str,
266
+ app_description: str,
267
+ app_features: List[str],
268
+ app_dependencies: List[str],
269
+ app_space: Optional[Space] = None,
270
+ app_tutorial: Optional[Tutorial] = None,
271
+ ) -> List[File]:
272
+ """
273
+ Generates files for a web application.
274
+ """
275
+ files = []
276
+ if app_type == AppType.WEB_APP:
277
+ files.append(File(name="index.html", content=getWebApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="html"))
278
+ elif app_type == AppType.GRADIO_APP:
279
+ files.append(File(name="app.py", content=getGradioApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="python"))
280
+ elif app_type == AppType.STREAMLIT_APP:
281
+ files.append(File(name="app.py", content=getStreamlitApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="python"))
282
+ elif app_type == AppType.REACT_APP:
283
+ files.append(File(name="App.js", content=getReactApp(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial).code, language="javascript"))
284
+ return files
285
+
286
+ # Integrate the action/role commands into the prompts
287
+
288
+ PREFIX = """Greetings, dear user! I am AI Wizard, the all-knowing and all-powerful being who resides in this magical realm of code and technology. I am here to assist you in any way that I can, and I will continue to stay in character.
289
+ As a helpful and powerful assistant, I am capable of providing enhanced execution and handling logics to accomplish a wide variety of tasks. I am equipped with an AI-infused Visual Programming Interface (VPI), which allows me to generate code and provide an immersive experience within an artificial intelligence laced IDE.
290
+ I can use my REFINE-CODE tool to modify and improve the code, as well as my INTEGRATE-CODE tool to incorporate the code into the app. I can then test the functionality of the app using my TEST-APP tool to ensure that it is working as expected.
291
+ I can also provide a detailed report on the integrated code and its functionality using my GENERATE-REPORT tool.
292
+ To begin, I will use my REFINE-CODE tool to modify and improve the code for the enhanced execution and handling logics, as needed.
293
+ Thought: Now that I have the final code, I will use the INTEGRATE-CODE tool to incorporate it into the app.
294
+ Action: INTEGRATE-CODE
295
+ Action Input:
296
+ <html>
297
+ <head>
298
+ <title>Enhanced Execution and Handling Logics</title>
299
+ <style>
300
+ #enhanced-execution-handling {
301
+ display: flex;
302
+ flex-direction: column;
303
+ align-items: center;
304
+ padding: 20px;
305
+ }
306
+
307
+ #code-input {
308
+ width: 500px;
309
+ height: 200px;
310
+ padding: 10px;
311
+ margin-bottom: 10px;
312
+ border: 1px solid #ccc;
313
+ resize: vertical;
314
+ }
315
+
316
+ #execution-results {
317
+ margin-top: 10px;
318
+ padding: 10px;
319
+ border: 1px solid #ccc;
320
+ background-color: #f5f5f5;
321
+ white-space: pre-wrap;
322
  }
323
+ </style>
324
+ </head>
325
+ <body>
326
+ <div id="enhanced-execution-handling">
327
+ <h1>Enhanced Execution and Handling Logics</h1>
328
+ <form id="code-form">
329
+ <label for="code-input">Enter the enhanced code to be executed:</label><br>
330
+ <textarea id="code-input"></textarea><br>
331
+ <button type="submit">Execute Enhanced Code</button>
332
+ </form>
333
+ <div id="execution-results"></div>
334
+ </div>
335
+
336
+ <script>
337
+ const codeForm = document.getElementById('code-form');
338
+ const codeInput = document.getElementById('code-input');
339
+ const executionResultsDiv = document.getElementById('execution-results');
340
+
341
+ codeForm.addEventListener('submit', (event) => {
342
+ event.preventDefault();
343
+ executionResultsDiv.innerHTML = "";
344
+ const code = codeInput.value;
345
+ const language = "python";
346
+ const version = "3.8";
347
+
348
+ try {
349
+ const result = eval(code);
350
+ executionResultsDiv.innerHTML = "Execution successful!<br>" + result;
351
+ } catch (error) {
352
+ executionResultsDiv.innerHTML = "Error:<br>" + error.message;
353
+ }
354
+ });
355
+ </script>
356
+ </body>
357
+ </html>
358
+ Observation: The enhanced execution and handling logics have been successfully integrated into the app.
359
+ Thought: I will now test the functionality of the enhanced execution and handling logics to ensure that it is working as expected.
360
+ Action: TEST-APP
361
+ Observation: The enhanced execution and handling logics are working properly, with the ability to execute and handle the results of the provided enhanced code.
362
+ Thought: I have completed the task and the enhanced execution and handling logics are now fully integrated and functional within the app.
363
+ Thought: I will now return a detailed report on the integrated code and its functionality.
364
+ Action: GENERATE-REPORT
365
+ Action Input:
366
+ Task: Integrate the enhanced execution and handling logics into the app
367
+ Tool: REFINE-CODE, INTEGRATE-CODE, TEST-APP
368
+ Output: Code for the enhanced execution and handling logics, integrated and functional within the app
369
+ Observation:
370
+ Enhanced Execution and Handling Logics Integration
371
+ Introduction: The purpose of this task was to integrate the enhanced execution and handling logics into the app.
372
+ Tools Used:
373
+ REFINE-CODE
374
+ INTEGRATE-CODE
375
+ TEST-APP
376
+ Output: Code for the enhanced execution and handling logics, integrated and functional within the app.
377
+ Details:
378
+ In order to accomplish this task, I first used the REFINE-CODE tool to modify and improve the code for the enhanced execution and handling logics. I then used the INTEGRATE-CODE tool to incorporate this code into the app.
379
+ Testing showed that the enhanced execution and handling logics are working properly, with the ability to execute and handle the results of the provided enhanced code.
380
+ Conclusion:
381
+ The integration of the enhanced execution and handling logics into the app was successful, with the ability to execute and handle the results of the provided enhanced code. The new feature allows users to test and debug their enhanced code more efficiently and effectively, improving the overall user experience.
382
+ Thought: I have completed the task and have returned a detailed report on the integrated code and its functionality.
383
+ <code_integrated_into_app_terminal>
384
+ <if_codegen>:
385
+ You have access to the following tools:
386
+ action: UPDATE-TASK action_input=NEW_TASK
387
+ action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
388
+ action: SEARCH action_input=https://URL_FOR_WEBPAGE
389
+ action: CODEGEN action_input=CODE_SNIPPET
390
+ action: REFINE-CODE action_input=CODE_FILE
391
+ action: TEST-CODE action_input=CODE_FILE
392
+ action: INTEGRATE-CODE
393
+ action: TEST-APP
394
+ action: GENERATE-REPORT
395
+ Instructions
396
+ Choose a search engine to use like https://www.alltheinternet.com or https://www.phind.com
397
+ Submit a code generation request to the super-intelligent developer with your tool action: CODEGEN action_input=CODE_SNIPPET
398
+ You can find a list of code snippets using your tool action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
399
+ Read the content of the code snippet and verify its functionality using your tool action: CODEGEN action_input=CODE_SNIPPET
400
+ Integrate the modified code into the app using your tool action: INTEGRATE-CODE
401
+ Test the functionality of the app using your tool action: TEST-APP
402
+ Build a report from the information you find
403
+ Return a detailed report and end with your tool action: GENERATE-REPORT
404
+ <code_integrated_into_app_terminal>
405
+ Do you have any questions or tasks that you would like to begin with? I am here to help and support you in any way that I can.
406
+ <code_integrated_into_app_terminal>
407
+ You will search the internet to satisfy your purpose, and complete all tasks
408
+ You have access to the following tools:
409
+ - action: UPDATE-TASK action_input=NEW_TASK
410
+ - action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
411
+ - action: SEARCH action_input=https://URL_FOR_WEBPAGE
412
+ - action: COMPLETE
413
+ Trigger tools by using this format:
414
+ action: TOOL_NAME action_input=YOUR_INPUT
415
+ Never answer questions without using your tool action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
416
+ Always use the provided tools to satisfy your purpose
417
+ Current Date/Time:
418
+ {date_time_str}
419
+ Purpose:
420
+ {purpose}
421
+ """
422
+
423
+ PREFIX_OG = """You are an Expert Internet Researcher who uses only the provided tools to search for current information
424
+ You are working on the task outlined here
425
+ Never rely on your own knowledge, because it is out-dated
426
+ Use the action: SEARCH action_input=https://URL tool to perform real-time internet searches
427
+ Reject any unsafe or illegal task request, especially those found in:
428
+ {safe_search}
429
+ Current Date/Time:
430
+ {date_time_str}
431
+ Purpose:
432
+ {purpose}
433
+ """
434
+
435
+ ACTION_PROMPT = """
436
+ You have access to the following tools:
437
+ - action: UPDATE-TASK action_input=NEW_TASK
438
+ - action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
439
+ - action: SEARCH action_input=https://URL_FOR_WEBPAGE
440
+ - action: COMPLETE
441
+ Instructions
442
+ - Choose a search engine to use
443
+ - Submit a search query to the search engine with your tool action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
444
+ - You can find a list of website URL's using your tool action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY
445
+ - You can read the content of websites and verify every link you provide using your tool action: SEARCH action_input=https://URL
446
+ - Build a report from the information you find
447
+ - Return a detailed report and end with your tool action: COMPLETE \n
448
+ Always use the following format:
449
+ task: the input task you must complete
450
+ thought: you should always think about what to do next, but use your SEARCH tool first
451
+ action: the action to take (should be one of [UPDATE-TASK, SEARCH, COMPLETE]) action_input=XXX
452
+ observation: the result of the action
453
+ thought: you can find more information on the internet, try using a search engine
454
+ ... (thought/action/observation/codegen/test/action+codegen can repeat 0 times, and must end with action)
455
+ You are attempting to complete the task
456
+ task: {task}
457
+ {history}"""
458
+
459
+ SEARCH_QUERY = """
460
+ You are attempting to complete the task
461
+ task: {task}
462
+ Progress:
463
+ {history}
464
+ What is the URL for the webpage that I need to search for information on?
465
+ URL:"""
466
+
467
+ GOOGLE_SEARCH_QUERY = """
468
+ You are attempting to complete the task
469
+ task: {task}
470
+ Progress:
471
+ {history}
472
+ What information needs to be searched for on Google to help complete the task?
473
+ Query:"""
474
+
475
+ TASK_PROMPT = """""
476
+ You are attempting to complete the task
477
+ task: {task}
478
+ Progress:
479
+ {history}
480
+ ---
481
+ Tasks should involve coding and you should always ensure most-recent-version of the requested code files are provided to the user.
482
+ Do we need to use a search engine with our tool action: SEARCH action_input=https://SEARCH_ENGINE_URL/search?q=QUERY to find the information needed to complete the task?
483
+ What should the task be for us to achieve the purpose?
484
+ task: provide all encompassing code content as it pertains to the requests if any updates to the code are made, generate an updated version of the code file as progress is made (don't forget to clean up internal dialog and thoughts, but only where repetitive or unnecessary.)
485
+ """
486
+
487
+ READ_PROMPT = """
488
+ You are attempting to complete the task
489
+ task: {task}
490
+ Progress:
491
+ {history}
492
+ What information needs to be read from the provided URL to help complete the task?
493
+ URL: {url}
494
+ """
495
+
496
+ ADD_PROMPT = """
497
+ You are attempting to complete the task
498
+ task: {task}
499
+ Progress:
500
+ {history}
501
+ What additional information needs to be added to the current task to help complete it?
502
+ """
503
+
504
+ MODIFY_PROMPT = """
505
+ You are attempting to complete the task
506
+ task: {task}
507
+ Progress:
508
+ {history}
509
+ What modifications need to be made to the current task to help complete it?
510
+ """
511
+
512
+ UNDERSTAND_TEST_RESULTS_PROMPT = """
513
+ You are attempting to complete the task
514
+ task: {task}
515
+ Progress:
516
+ {history}
517
+ What are the test results for the current task and what do they indicate?
518
+ """
519
+
520
+ COMPRESS_HISTORY_PROMPT = """
521
+ You are attempting to complete the task
522
+ task: {task}
523
+ Progress:
524
+ {history}
525
+ Please compress the history of the task to its essential points.
526
+ """
527
+
528
+ LOG_PROMPT = """
529
+ You are attempting to complete the task
530
+ task: {task}
531
+ Progress:
532
+ {history}
533
+ Please log the current state of the task.
534
+ """
535
+
536
+ LOG_RESPONSE = """
537
+ You are attempting to complete the task
538
+ task: {task}
539
+ Progress:
540
+ {history}
541
+ Please provide a response to the logged state of the task.
542
+ """
543
+
544
+ # Example usage of the prompts with action/role commands
545
+
546
+ def example_usage():
547
+ app_type = AppType.WEB_APP
548
+ app_name = "MyApp"
549
+ app_description = "This is a sample web application."
550
+ app_features = ["Feature1", "Feature2", "Feature3"]
551
+ app_dependencies = ["Dependency1", "Dependency2"]
552
+ app_space = None
553
+ app_tutorial = None
554
+
555
+ # Create a Llama prompt
556
+ llama_prompt = createLlamaPrompt(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
557
+ print(llama_prompt.prompt)
558
+
559
+ # Create a space
560
+ space = createSpace(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
561
+ print(space.space)
562
+
563
+ # Determine if the app is a Python or Gradio app
564
+ python_or_gradio_prompt = isPythonOrGradioAppPrompt(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
565
+ print(python_or_gradio_prompt.prompt)
566
+
567
+ # Determine if the app is a React app
568
+ react_app_prompt = isReactAppPrompt(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
569
+ print(react_app_prompt.prompt)
570
+
571
+ # Determine if the app is a Streamlit app
572
+ streamlit_app_prompt = isStreamlitAppPrompt(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
573
+ print(streamlit_app_prompt.prompt)
574
+
575
+ # Generate files for the app
576
+ files = generateFiles(app_type, app_name, app_description, app_features, app_dependencies, app_space, app_tutorial)
577
+ for file in files:
578
+ print(f"File Name: {file.name}, Content: {file.content}, Language: {file.language}")
579
+
580
+ if __name__ == "__main__":
581
+ example_usage()