Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,12 +49,7 @@ def format_prompt(message, mod, system):
|
|
| 49 |
return prompt
|
| 50 |
def generate(prompt,history,mod=2,tok=4000,seed=1,role="ASSISTANT",data=None):
|
| 51 |
#print("#####",history,"######")
|
| 52 |
-
|
| 53 |
-
file_list = fs.ls(f'spaces/{user_}{repo_}',detail=False)
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(e)
|
| 56 |
-
file_list=["NO FILES YET"]
|
| 57 |
-
print('file list\n',file_list)
|
| 58 |
gen_images=False
|
| 59 |
client=InferenceClient(clients[int(mod)]['name'])
|
| 60 |
client_tok=clients[int(mod)]['max_tokens']
|
|
@@ -72,10 +67,10 @@ def generate(prompt,history,mod=2,tok=4000,seed=1,role="ASSISTANT",data=None):
|
|
| 72 |
system_prompt = prompts.MANAGER.replace("**TIMELINE**",data[4]).replace("**HISTORY**",str(history))
|
| 73 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 74 |
elif role == "PATHMAKER":
|
| 75 |
-
system_prompt = prompts.PATH_MAKER.replace("**FILE_LIST**",str(
|
| 76 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 77 |
elif role == "CREATE_FILE":
|
| 78 |
-
system_prompt = prompts.CREATE_FILE.replace("**FILE_LIST**",str(
|
| 79 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 80 |
elif role == "SEARCH":
|
| 81 |
system_prompt = prompts.SEARCH.replace("**DATA**",data)
|
|
@@ -231,7 +226,12 @@ def agent(prompt_in,history,mod=2):
|
|
| 231 |
MAX_DATA=int(clients[int(mod)]['max_tokens'])*2
|
| 232 |
if not history:history=[{'role':'user','content':prompt_in['text']}]
|
| 233 |
while go == True:
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
|
| 237 |
seed = random.randint(1,9999999999999)
|
|
@@ -241,7 +241,9 @@ def agent(prompt_in,history,mod=2):
|
|
| 241 |
history = [history[-2:]]
|
| 242 |
print('history',history)
|
| 243 |
role="PATHMAKER"
|
|
|
|
| 244 |
outph= list(generate(prompt,history,mod,2400,seed,role,in_data))[0]
|
|
|
|
| 245 |
in_data[4]=outph
|
| 246 |
print(outph)
|
| 247 |
history.extend([{'role':'assistant','content':str(outph)}])
|
|
@@ -269,6 +271,7 @@ def agent(prompt_in,history,mod=2):
|
|
| 269 |
in_data[1]=com
|
| 270 |
temp1=file_template(com)
|
| 271 |
in_data[2]=temp1
|
|
|
|
| 272 |
out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
|
| 273 |
out_w=list(out_o)
|
| 274 |
ret1,ret2 = parse_json(out_w[2].split('<|im_end|>')[0])
|
|
|
|
| 49 |
return prompt
|
| 50 |
def generate(prompt,history,mod=2,tok=4000,seed=1,role="ASSISTANT",data=None):
|
| 51 |
#print("#####",history,"######")
|
| 52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
gen_images=False
|
| 54 |
client=InferenceClient(clients[int(mod)]['name'])
|
| 55 |
client_tok=clients[int(mod)]['max_tokens']
|
|
|
|
| 67 |
system_prompt = prompts.MANAGER.replace("**TIMELINE**",data[4]).replace("**HISTORY**",str(history))
|
| 68 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 69 |
elif role == "PATHMAKER":
|
| 70 |
+
system_prompt = prompts.PATH_MAKER.replace("**FILE_LIST**",str(data[3])).replace("**CURRENT_OR_NONE**",str(data[4])).replace("**PROMPT**",json.dumps(data[0],indent=4)).replace("**HISTORY**",str(history))
|
| 71 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 72 |
elif role == "CREATE_FILE":
|
| 73 |
+
system_prompt = prompts.CREATE_FILE.replace("**FILE_LIST**",str(data[3])).replace("**TIMELINE**",data[4]).replace("**FILENAME**",str(data[1])).replace("**TEMPLATE_OR_NONE**",str(data[2]))
|
| 74 |
formatted_prompt = format_prompt(prompt, mod, system_prompt)
|
| 75 |
elif role == "SEARCH":
|
| 76 |
system_prompt = prompts.SEARCH.replace("**DATA**",data)
|
|
|
|
| 226 |
MAX_DATA=int(clients[int(mod)]['max_tokens'])*2
|
| 227 |
if not history:history=[{'role':'user','content':prompt_in['text']}]
|
| 228 |
while go == True:
|
| 229 |
+
try:
|
| 230 |
+
file_list = fs.ls(f'spaces/{user_}{repo_}',detail=False)
|
| 231 |
+
except Exception as e:
|
| 232 |
+
print(e)
|
| 233 |
+
file_list=["NO FILES YET"]
|
| 234 |
+
print('file list\n',file_list)
|
| 235 |
|
| 236 |
|
| 237 |
seed = random.randint(1,9999999999999)
|
|
|
|
| 241 |
history = [history[-2:]]
|
| 242 |
print('history',history)
|
| 243 |
role="PATHMAKER"
|
| 244 |
+
in_data[3]=file_list
|
| 245 |
outph= list(generate(prompt,history,mod,2400,seed,role,in_data))[0]
|
| 246 |
+
|
| 247 |
in_data[4]=outph
|
| 248 |
print(outph)
|
| 249 |
history.extend([{'role':'assistant','content':str(outph)}])
|
|
|
|
| 271 |
in_data[1]=com
|
| 272 |
temp1=file_template(com)
|
| 273 |
in_data[2]=temp1
|
| 274 |
+
in_data[3]=file_list
|
| 275 |
out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
|
| 276 |
out_w=list(out_o)
|
| 277 |
ret1,ret2 = parse_json(out_w[2].split('<|im_end|>')[0])
|