Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,7 +102,7 @@ def build_prompt(task_instruction: str, format_instruction: str, tools: list, qu
|
|
| 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 len(conversation_history) > 0:
|
| 106 |
prompt += build_conversation_history_prompt(conversation_history)
|
| 107 |
return prompt
|
| 108 |
|
|
@@ -114,7 +114,6 @@ 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 |
-
conversation_history = []
|
| 118 |
content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query, conversation_history)
|
| 119 |
|
| 120 |
messages = [
|
|
@@ -127,25 +126,6 @@ def generate_response(tools_input, query):
|
|
| 127 |
|
| 128 |
return agent_action
|
| 129 |
|
| 130 |
-
def generate_response(tools_input, query):
|
| 131 |
-
try:
|
| 132 |
-
tools = json.loads(tools_input)
|
| 133 |
-
except json.JSONDecodeError:
|
| 134 |
-
return "Error: Invalid JSON format for tools input."
|
| 135 |
-
|
| 136 |
-
xlam_format_tools = convert_to_xlam_tool(tools)
|
| 137 |
-
content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query)
|
| 138 |
-
|
| 139 |
-
messages = [
|
| 140 |
-
{'role': 'user', 'content': content}
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 144 |
-
outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
|
| 145 |
-
agent_action = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
|
| 146 |
-
|
| 147 |
-
return agent_action
|
| 148 |
-
|
| 149 |
# Gradio interface
|
| 150 |
with gr.Blocks() as demo:
|
| 151 |
gr.Markdown(title)
|
|
@@ -156,7 +136,7 @@ with gr.Blocks() as demo:
|
|
| 156 |
tools_input = gr.Code(
|
| 157 |
label="Available Tools (JSON format)",
|
| 158 |
lines=20,
|
| 159 |
-
value=example_tools
|
| 160 |
language='json'
|
| 161 |
)
|
| 162 |
query_input = gr.Textbox(
|
|
|
|
| 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 |
|
|
|
|
| 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, conversation_history)
|
| 118 |
|
| 119 |
messages = [
|
|
|
|
| 126 |
|
| 127 |
return agent_action
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# Gradio interface
|
| 130 |
with gr.Blocks() as demo:
|
| 131 |
gr.Markdown(title)
|
|
|
|
| 136 |
tools_input = gr.Code(
|
| 137 |
label="Available Tools (JSON format)",
|
| 138 |
lines=20,
|
| 139 |
+
value=example_tools,
|
| 140 |
language='json'
|
| 141 |
)
|
| 142 |
query_input = gr.Textbox(
|