Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,12 +23,13 @@ from utils import parse_action, parse_file_content, read_python_module_structure
|
|
23 |
from datetime import datetime
|
24 |
|
25 |
def format_prompt(message, history):
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
def run_gpt(
|
34 |
prompt_template,
|
@@ -37,6 +38,7 @@ def run_gpt(
|
|
37 |
purpose,
|
38 |
**prompt_kwargs,
|
39 |
):
|
|
|
40 |
seed = random.randint(1, 1111111111111111)
|
41 |
print(seed)
|
42 |
generate_kwargs = dict(
|
@@ -53,7 +55,7 @@ def run_gpt(
|
|
53 |
purpose=purpose,
|
54 |
safe_search=safe_search,
|
55 |
) + prompt_template.format(**prompt_kwargs)
|
56 |
-
|
57 |
if True:
|
58 |
print(LOG_PROMPT.format(content))
|
59 |
|
@@ -67,6 +69,7 @@ def run_gpt(
|
|
67 |
|
68 |
|
69 |
def compress_history(purpose, task, history, directory):
|
|
|
70 |
resp = run_gpt(
|
71 |
COMPRESS_HISTORY_PROMPT,
|
72 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
@@ -78,6 +81,7 @@ def compress_history(purpose, task, history, directory):
|
|
78 |
return resp
|
79 |
|
80 |
def call_search(purpose, task, history, directory, action_input):
|
|
|
81 |
print("CALLING SEARCH")
|
82 |
try:
|
83 |
|
@@ -98,6 +102,7 @@ def call_search(purpose, task, history, directory, action_input):
|
|
98 |
return "MAIN", None, history, task
|
99 |
|
100 |
def call_main(purpose, task, history, directory, action_input):
|
|
|
101 |
resp = run_gpt(
|
102 |
ACTION_PROMPT,
|
103 |
stop_tokens=["observation:", "task:", "action:","thought:"],
|
@@ -134,6 +139,7 @@ def call_main(purpose, task, history, directory, action_input):
|
|
134 |
|
135 |
|
136 |
def call_set_task(purpose, task, history, directory, action_input):
|
|
|
137 |
task = "COMPLETE"
|
138 |
resp = run_gpt(
|
139 |
TASK_PROMPT,
|
@@ -147,6 +153,7 @@ def call_set_task(purpose, task, history, directory, action_input):
|
|
147 |
return "MAIN", None, history, task
|
148 |
|
149 |
def end_fn(purpose, task, history, directory, action_input):
|
|
|
150 |
task = "COMPLETE"
|
151 |
return "COMPLETE", "COMPLETE", history, task
|
152 |
|
@@ -159,6 +166,7 @@ NAME_TO_FUNC = {
|
|
159 |
}
|
160 |
|
161 |
def run_action(purpose, task, history, directory, action_name, action_input):
|
|
|
162 |
print(f'action_name::{action_name}')
|
163 |
try:
|
164 |
if "RESPONSE" in action_name or "COMPLETE" in action_name:
|
@@ -185,7 +193,7 @@ def run_action(purpose, task, history, directory, action_name, action_input):
|
|
185 |
return "MAIN", None, history, task
|
186 |
|
187 |
def run(purpose,history):
|
188 |
-
|
189 |
#print(purpose)
|
190 |
#print(hist)
|
191 |
task = "COMPLETE"
|
@@ -229,6 +237,7 @@ agents =[
|
|
229 |
def generate(
|
230 |
prompt, history, agent_name=agents[0], sys_prompt="", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
231 |
):
|
|
|
232 |
seed = random.randint(1,1111111111111111)
|
233 |
|
234 |
agent=prompts.WEB_DEV
|
@@ -356,6 +365,7 @@ examples = [
|
|
356 |
]
|
357 |
|
358 |
def launch_interface():
|
|
|
359 |
gr.ChatInterface(
|
360 |
fn=run,
|
361 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel"),
|
|
|
23 |
from datetime import datetime
|
24 |
|
25 |
def format_prompt(message, history):
|
26 |
+
"""Formats the prompt by concatenating user prompts and bot responses."""
|
27 |
+
prompt = "<s>"
|
28 |
+
for user_prompt, bot_response in history:
|
29 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
30 |
+
prompt += f" {bot_response}</s> "
|
31 |
+
prompt += f"[INST] {message} [/INST]"
|
32 |
+
return prompt
|
33 |
|
34 |
def run_gpt(
|
35 |
prompt_template,
|
|
|
38 |
purpose,
|
39 |
**prompt_kwargs,
|
40 |
):
|
41 |
+
"""Runs the GPT model to generate a response."""
|
42 |
seed = random.randint(1, 1111111111111111)
|
43 |
print(seed)
|
44 |
generate_kwargs = dict(
|
|
|
55 |
purpose=purpose,
|
56 |
safe_search=safe_search,
|
57 |
) + prompt_template.format(**prompt_kwargs)
|
58 |
+
|
59 |
if True:
|
60 |
print(LOG_PROMPT.format(content))
|
61 |
|
|
|
69 |
|
70 |
|
71 |
def compress_history(purpose, task, history, directory):
|
72 |
+
"""Compresses the history using the GPT model."""
|
73 |
resp = run_gpt(
|
74 |
COMPRESS_HISTORY_PROMPT,
|
75 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
|
|
81 |
return resp
|
82 |
|
83 |
def call_search(purpose, task, history, directory, action_input):
|
84 |
+
"""Calls the search function."""
|
85 |
print("CALLING SEARCH")
|
86 |
try:
|
87 |
|
|
|
102 |
return "MAIN", None, history, task
|
103 |
|
104 |
def call_main(purpose, task, history, directory, action_input):
|
105 |
+
"""Calls the main function."""
|
106 |
resp = run_gpt(
|
107 |
ACTION_PROMPT,
|
108 |
stop_tokens=["observation:", "task:", "action:","thought:"],
|
|
|
139 |
|
140 |
|
141 |
def call_set_task(purpose, task, history, directory, action_input):
|
142 |
+
"""Sets the task."""
|
143 |
task = "COMPLETE"
|
144 |
resp = run_gpt(
|
145 |
TASK_PROMPT,
|
|
|
153 |
return "MAIN", None, history, task
|
154 |
|
155 |
def end_fn(purpose, task, history, directory, action_input):
|
156 |
+
"""Ends the function."""
|
157 |
task = "COMPLETE"
|
158 |
return "COMPLETE", "COMPLETE", history, task
|
159 |
|
|
|
166 |
}
|
167 |
|
168 |
def run_action(purpose, task, history, directory, action_name, action_input):
|
169 |
+
"""Runs the action."""
|
170 |
print(f'action_name::{action_name}')
|
171 |
try:
|
172 |
if "RESPONSE" in action_name or "COMPLETE" in action_name:
|
|
|
193 |
return "MAIN", None, history, task
|
194 |
|
195 |
def run(purpose,history):
|
196 |
+
"""Runs the main loop."""
|
197 |
#print(purpose)
|
198 |
#print(hist)
|
199 |
task = "COMPLETE"
|
|
|
237 |
def generate(
|
238 |
prompt, history, agent_name=agents[0], sys_prompt="", temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
239 |
):
|
240 |
+
"""Generates the output."""
|
241 |
seed = random.randint(1,1111111111111111)
|
242 |
|
243 |
agent=prompts.WEB_DEV
|
|
|
365 |
]
|
366 |
|
367 |
def launch_interface():
|
368 |
+
"""Launches the interface."""
|
369 |
gr.ChatInterface(
|
370 |
fn=run,
|
371 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel"),
|