| 507 | } |
| 508 | |
| 509 | json RestHandler::build_nstream_response(std::string response_text) { |
| 510 | // Get tool info |
| 511 | NonStreamResult result = auto_chat_engine->parse_nstream_content(response_text); |
| 512 | |
| 513 | json message; |
| 514 | message["role"] = "assistant"; |
| 515 | |
| 516 | bool is_reasoning = !result.reasoning_content.empty(); |
| 517 | bool is_tool_call = !result.tool_name.empty(); |
| 518 | |
| 519 | if (is_reasoning) { |
| 520 | message["reasoning_content"] = result.reasoning_content; |
| 521 | } |
| 522 | |
| 523 | if (is_tool_call) { |
| 524 | message["tool_calls"] = json::array({ |
| 525 | { |
| 526 | {"index", 0}, |
| 527 | {"id", "call_" + std::to_string(std::time(nullptr))}, |
| 528 | {"type", "function"}, |
| 529 | {"function", { |
| 530 | {"name", result.tool_name}, |
| 531 | {"arguments", result.tool_args} |
| 532 | }} |
| 533 | } |
| 534 | }); |
| 535 | } |
| 536 | else { |
| 537 | message["content"] = result.content; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | // Construct the final choice object |
| 542 | return json::array({ |
| 543 | { |
| 544 | {"index", 0}, |
| 545 | {"message", message}, |
| 546 | {"logprobs", nullptr}, |
| 547 | {"finish_reason", is_tool_call ? "tool_calls" : "stop"} |
| 548 | } |
| 549 | }); |
| 550 | } |
| 551 | |
| 552 | ///@brief Handle the show request |
| 553 | ///@param request the request |
nothing calls this directly
no test coverage detected