Spaces:
Running
Running
Commit
·
182dc7c
1
Parent(s):
1352961
feature: show calls.
Browse files- .gitignore +3 -0
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +19 -1
- requirements.txt +2 -1
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
|
| 3 |
+
.venv
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (3.23 kB). View file
|
|
|
app.py
CHANGED
|
@@ -71,18 +71,36 @@ def respond(message, history, system_message):
|
|
| 71 |
"evaluate_math_expression": evaluate_math_expression,
|
| 72 |
}
|
| 73 |
|
|
|
|
| 74 |
while True:
|
| 75 |
response = get_model_response(conversation)
|
| 76 |
response_message = response.choices[0].message
|
| 77 |
conversation.append(response_message)
|
| 78 |
|
| 79 |
if not response_message.tool_calls and response_message.content is not None:
|
| 80 |
-
|
| 81 |
|
| 82 |
if response_message.tool_calls is not None:
|
| 83 |
for tool_call in response_message.tool_calls:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
function_response = call_function(tool_call, available_functions)
|
| 85 |
conversation.append(function_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
demo = gr.ChatInterface(
|
| 88 |
respond,
|
|
|
|
| 71 |
"evaluate_math_expression": evaluate_math_expression,
|
| 72 |
}
|
| 73 |
|
| 74 |
+
function_calls = []
|
| 75 |
while True:
|
| 76 |
response = get_model_response(conversation)
|
| 77 |
response_message = response.choices[0].message
|
| 78 |
conversation.append(response_message)
|
| 79 |
|
| 80 |
if not response_message.tool_calls and response_message.content is not None:
|
| 81 |
+
break
|
| 82 |
|
| 83 |
if response_message.tool_calls is not None:
|
| 84 |
for tool_call in response_message.tool_calls:
|
| 85 |
+
function_call = {
|
| 86 |
+
"name": tool_call.function.name,
|
| 87 |
+
"arguments": json.loads(tool_call.function.arguments)
|
| 88 |
+
}
|
| 89 |
+
function_calls.append(function_call)
|
| 90 |
function_response = call_function(tool_call, available_functions)
|
| 91 |
conversation.append(function_response)
|
| 92 |
+
function_calls.append({
|
| 93 |
+
"name": function_response["name"],
|
| 94 |
+
"result": json.loads(function_response["content"])
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
function_calls_md = "\n\n"
|
| 98 |
+
for i in range(0, len(function_calls), 2):
|
| 99 |
+
call = function_calls[i]
|
| 100 |
+
result = function_calls[i + 1] if i + 1 < len(function_calls) else None
|
| 101 |
+
function_calls_md += f"**Tool call:**\n```json\n{json.dumps({'name': call['name'], 'arguments': call['arguments'], 'result': result['result'] if result else None}, indent=2)}\n```\n"
|
| 102 |
+
|
| 103 |
+
return response_message.content + function_calls_md
|
| 104 |
|
| 105 |
demo = gr.ChatInterface(
|
| 106 |
respond,
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
huggingface_hub==0.22.2
|
| 2 |
groq
|
| 3 |
-
numexpr
|
|
|
|
|
|
| 1 |
huggingface_hub==0.22.2
|
| 2 |
groq
|
| 3 |
+
numexpr
|
| 4 |
+
gradio
|