2024-12-04 16:41:30 -08:00
|
|
|
from app.commons.globals import handler_map
|
|
|
|
|
from app.model_handler.function_calling import Message
|
2024-10-18 13:25:39 -07:00
|
|
|
|
2024-12-04 16:41:30 -08:00
|
|
|
|
|
|
|
|
test_input_history = [
|
|
|
|
|
{"role": "user", "content": "how is the weather in chicago for next 5 days?"},
|
2024-10-18 13:25:39 -07:00
|
|
|
{
|
2024-12-04 16:41:30 -08:00
|
|
|
"role": "assistant",
|
|
|
|
|
"model": "Arch-Function",
|
|
|
|
|
"tool_calls": [
|
|
|
|
|
{
|
|
|
|
|
"id": "call_3394",
|
|
|
|
|
"type": "function",
|
|
|
|
|
"function": {
|
|
|
|
|
"name": "weather_forecast",
|
|
|
|
|
"arguments": {"city": "Chicago", "days": 5},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
],
|
2024-10-18 13:25:39 -07:00
|
|
|
},
|
2024-12-04 16:41:30 -08:00
|
|
|
{"role": "tool", "content": "--", "tool_call_id": "call_3394"},
|
|
|
|
|
{"role": "assistant", "content": "--", "model": "gpt-3.5-turbo-0125"},
|
|
|
|
|
{"role": "user", "content": "how is the weather in chicago for next 5 days?"},
|
2024-10-18 13:25:39 -07:00
|
|
|
{
|
2024-12-04 16:41:30 -08:00
|
|
|
"role": "assistant",
|
|
|
|
|
"tool_calls": [
|
|
|
|
|
{
|
|
|
|
|
"id": "call_5306",
|
|
|
|
|
"type": "function",
|
|
|
|
|
"function": {
|
|
|
|
|
"name": "weather_forecast",
|
|
|
|
|
"arguments": {"city": "Chicago", "days": 5},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
],
|
2024-10-18 13:25:39 -07:00
|
|
|
},
|
2024-12-04 16:41:30 -08:00
|
|
|
{"role": "tool", "content": "--", "tool_call_id": "call_5306"},
|
|
|
|
|
]
|
2024-10-18 13:25:39 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_fc_history():
|
|
|
|
|
message_history = []
|
2024-12-04 16:41:30 -08:00
|
|
|
|
|
|
|
|
for h in test_input_history:
|
2024-10-18 13:25:39 -07:00
|
|
|
message_history.append(Message(**h))
|
|
|
|
|
|
2024-12-04 16:41:30 -08:00
|
|
|
updated_history = handler_map["Arch-Function"]._process_messages(message_history)
|
|
|
|
|
assert len(updated_history) == 7
|
2024-10-18 13:25:39 -07:00
|
|
|
# ensure that tool role does not exist anymore
|
|
|
|
|
assert all([h["role"] != "tool" for h in updated_history])
|