Spaces:
Runtime error
Runtime error
Salvatore Rossitto
commited on
Commit
·
4190d92
1
Parent(s):
9778c3b
...
Browse files- RBotReloaded.py +11 -12
RBotReloaded.py
CHANGED
@@ -69,11 +69,11 @@ def validate_and_fix_params(tool_name, params_list):
|
|
69 |
def create_llm(model_id=f"{MODELS_DIR}/mistral-7b-instruct-v0.1.Q4_K_M.gguf", load_4bit=False, load_8bit=False, ctx_len = 8192, temperature=0.5, top_p=0.95):
|
70 |
if (model_id.startswith("http")):
|
71 |
print(f"Creating TextGen LLM base_url:{model_id}")
|
72 |
-
return TextGen(model_url=model_id, callbacks=[StreamingStdOutCallbackHandler()])
|
73 |
if (os.path.exists(model_id)):
|
74 |
try:
|
75 |
print(f"Creating LlamaCpp LLM model_id:{model_id}")
|
76 |
-
return LlamaCpp(model_path=model_id, verbose=True, n_batch=521, alpha_value=1,rope_freq_base=10000,compress_pos_emb=ctx_len / 4096, n_ctx=ctx_len, load_in_4bit=load_4bit, load_in_8bit=load_8bit, temperature=temperature,top_p=top_p)
|
77 |
except Exception as ex:
|
78 |
try:
|
79 |
print(f"Creating CTransformers LLM model_id:{model_id}")
|
@@ -84,7 +84,7 @@ def create_llm(model_id=f"{MODELS_DIR}/mistral-7b-instruct-v0.1.Q4_K_M.gguf", lo
|
|
84 |
"top_p":top_p,
|
85 |
"temperature":temperature
|
86 |
}
|
87 |
-
return CTransformers(model=model_id, model_type='llama', config=config)
|
88 |
|
89 |
except Exception as ex:
|
90 |
print(f"Load Error {str(ex)}")
|
@@ -269,15 +269,14 @@ AI: SearchAndReply("recent cryptocurrency news")
|
|
269 |
USER: Can you calculate the factorial of 5?
|
270 |
AI: Calculator("factorial(5)")
|
271 |
|
272 |
-
###
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
276 |
{formatted_history}
|
277 |
USER: {input}
|
278 |
-
SYS: Please reply last user message directly or invoking a valid action from the following list:
|
279 |
-
{self.tools_prompt()}
|
280 |
-
|
281 |
AI:
|
282 |
"""
|
283 |
observations = []
|
@@ -335,11 +334,11 @@ AI:
|
|
335 |
|
336 |
print(f"Action Output: {res}")
|
337 |
observations.append(f"Action Output: {res}")
|
338 |
-
prompt = prompt + f"Action: {tool.name}({action_input})\
|
339 |
if (i+1 == self.max_iterations):
|
340 |
print(f"MAX ITERATIONS REACHED. PLEASE PROVIDE A FINAL RESPONSE!")
|
341 |
prompt = prompt + "\nMAX ITERATIONS REACHED. PLEASE PROVIDE A FINAL RESPONSE!\nAI:"
|
342 |
-
output = str(self.llm(prompt,stop=["USER:","AI:","SYS:","[INST]","[/INST]"])).strip()
|
343 |
final_response = "\n*Reasoning: ".join(observations) + f"\n{output}" if len(observations) > 0 else f"\n{output}"
|
344 |
return { "output": final_response }
|
345 |
else:
|
|
|
69 |
def create_llm(model_id=f"{MODELS_DIR}/mistral-7b-instruct-v0.1.Q4_K_M.gguf", load_4bit=False, load_8bit=False, ctx_len = 8192, temperature=0.5, top_p=0.95):
|
70 |
if (model_id.startswith("http")):
|
71 |
print(f"Creating TextGen LLM base_url:{model_id}")
|
72 |
+
return TextGen(model_url=model_id, seed=79, callbacks=[StreamingStdOutCallbackHandler()])
|
73 |
if (os.path.exists(model_id)):
|
74 |
try:
|
75 |
print(f"Creating LlamaCpp LLM model_id:{model_id}")
|
76 |
+
return LlamaCpp(model_path=model_id, verbose=True, n_batch=521, seed=79, alpha_value=1,rope_freq_base=10000,compress_pos_emb=ctx_len / 4096, n_ctx=ctx_len, load_in_4bit=load_4bit, load_in_8bit=load_8bit, temperature=temperature,top_p=top_p)
|
77 |
except Exception as ex:
|
78 |
try:
|
79 |
print(f"Creating CTransformers LLM model_id:{model_id}")
|
|
|
84 |
"top_p":top_p,
|
85 |
"temperature":temperature
|
86 |
}
|
87 |
+
return CTransformers(model=model_id, model_type='llama', seed=79, config=config)
|
88 |
|
89 |
except Exception as ex:
|
90 |
print(f"Load Error {str(ex)}")
|
|
|
269 |
USER: Can you calculate the factorial of 5?
|
270 |
AI: Calculator("factorial(5)")
|
271 |
|
272 |
+
### REAL CONVERSATION:
|
273 |
+
[INST]
|
274 |
+
SYSTEM: You are {AI_NAME} a smart and helpful AI assistant with access to external tools and knowledge.
|
275 |
+
Today is {str(datetime.now().date())}, please reply last user message directly or invoking a valid action from the following list:
|
276 |
+
{self.tools_prompt()}
|
277 |
+
[/INST]
|
278 |
{formatted_history}
|
279 |
USER: {input}
|
|
|
|
|
|
|
280 |
AI:
|
281 |
"""
|
282 |
observations = []
|
|
|
334 |
|
335 |
print(f"Action Output: {res}")
|
336 |
observations.append(f"Action Output: {res}")
|
337 |
+
prompt = prompt + f"Action: {tool.name}({action_input})\SYSTEM:{res}"
|
338 |
if (i+1 == self.max_iterations):
|
339 |
print(f"MAX ITERATIONS REACHED. PLEASE PROVIDE A FINAL RESPONSE!")
|
340 |
prompt = prompt + "\nMAX ITERATIONS REACHED. PLEASE PROVIDE A FINAL RESPONSE!\nAI:"
|
341 |
+
output = str(self.llm(prompt,stop=["USER:","AI:","SYS:","SYSTEM:","[INST]","[/INST]"])).strip()
|
342 |
final_response = "\n*Reasoning: ".join(observations) + f"\n{output}" if len(observations) > 0 else f"\n{output}"
|
343 |
return { "output": final_response }
|
344 |
else:
|