Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,31 +82,13 @@ def convert_to_xlam_tool(tools):
|
|
| 82 |
else:
|
| 83 |
return tools
|
| 84 |
|
| 85 |
-
def
|
| 86 |
-
parsed_history = []
|
| 87 |
-
for step_data in conversation_history:
|
| 88 |
-
parsed_history.append({
|
| 89 |
-
"step_id": step_data["step_id"],
|
| 90 |
-
"thought": step_data["thought"],
|
| 91 |
-
"tool_calls": step_data["tool_calls"],
|
| 92 |
-
"next_observation": step_data["next_observation"],
|
| 93 |
-
"user_input": step_data['user_input']
|
| 94 |
-
})
|
| 95 |
-
|
| 96 |
-
history_string = json.dumps(parsed_history)
|
| 97 |
-
return f"\n[BEGIN OF HISTORY STEPS]\n{history_string}\n[END OF HISTORY STEPS]\n"
|
| 98 |
-
|
| 99 |
-
def build_prompt(task_instruction: str, format_instruction: str, tools: list, query: str, conversation_history: list):
|
| 100 |
prompt = f"[BEGIN OF TASK INSTRUCTION]\n{task_instruction}\n[END OF TASK INSTRUCTION]\n\n"
|
| 101 |
prompt += f"[BEGIN OF AVAILABLE TOOLS]\n{json.dumps(tools)}\n[END OF AVAILABLE TOOLS]\n\n"
|
| 102 |
prompt += f"[BEGIN OF FORMAT INSTRUCTION]\n{format_instruction}\n[END OF FORMAT INSTRUCTION]\n\n"
|
| 103 |
prompt += f"[BEGIN OF QUERY]\n{query}\n[END OF QUERY]\n\n"
|
| 104 |
-
|
| 105 |
-
if conversation_history and len(conversation_history) > 0:
|
| 106 |
-
prompt += build_conversation_history_prompt(conversation_history)
|
| 107 |
return prompt
|
| 108 |
|
| 109 |
-
@spaces.GPU
|
| 110 |
def generate_response(tools_input, query):
|
| 111 |
try:
|
| 112 |
tools = json.loads(tools_input)
|
|
@@ -114,7 +96,7 @@ def generate_response(tools_input, query):
|
|
| 114 |
return "Error: Invalid JSON format for tools input."
|
| 115 |
|
| 116 |
xlam_format_tools = convert_to_xlam_tool(tools)
|
| 117 |
-
content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query
|
| 118 |
|
| 119 |
messages = [
|
| 120 |
{'role': 'user', 'content': content}
|
|
|
|
| 82 |
else:
|
| 83 |
return tools
|
| 84 |
|
| 85 |
+
def build_prompt(task_instruction: str, format_instruction: str, tools: list, query: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
prompt = f"[BEGIN OF TASK INSTRUCTION]\n{task_instruction}\n[END OF TASK INSTRUCTION]\n\n"
|
| 87 |
prompt += f"[BEGIN OF AVAILABLE TOOLS]\n{json.dumps(tools)}\n[END OF AVAILABLE TOOLS]\n\n"
|
| 88 |
prompt += f"[BEGIN OF FORMAT INSTRUCTION]\n{format_instruction}\n[END OF FORMAT INSTRUCTION]\n\n"
|
| 89 |
prompt += f"[BEGIN OF QUERY]\n{query}\n[END OF QUERY]\n\n"
|
|
|
|
|
|
|
|
|
|
| 90 |
return prompt
|
| 91 |
|
|
|
|
| 92 |
def generate_response(tools_input, query):
|
| 93 |
try:
|
| 94 |
tools = json.loads(tools_input)
|
|
|
|
| 96 |
return "Error: Invalid JSON format for tools input."
|
| 97 |
|
| 98 |
xlam_format_tools = convert_to_xlam_tool(tools)
|
| 99 |
+
content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query)
|
| 100 |
|
| 101 |
messages = [
|
| 102 |
{'role': 'user', 'content': content}
|