common/chat, server: refactor, move all conversion functions to common, add tests - #20690
Conversation
|
hm, give a shot for this |
|
Finally its work Thank you. Dziękuję ;) |
ngxson
left a comment
There was a problem hiding this comment.
IMO it's a bit strange to move the conversion functions to common, as they are technically only used by server.
Just wondering, it is possible to confine them inside server, maybe: server/server-chat.cpp ?
test-chat can be linked against libserver, the way as llama-cli
|
I'm in agreement with @ngxson. I would expect interface choices to be made at the API boundary, instead of propagating internally. In a way the chat completions API is our "internal" representation, for better or worse. What are we trying to solve? |
|
I'm trying to make the conversion clearer (and more testable), possibly in preparation for migration to a different system than Chat Completions as our base. Okay, I'll make a separate class in |
4d6942c to
8686b80
Compare
| using json = nlohmann::ordered_json; | ||
|
|
||
| // Convert OpenAI Responses API format to OpenAI Chat Completions API format | ||
| json common_chat_convert_responses_to_chatcmpl(const json & body); |
There was a problem hiding this comment.
| json common_chat_convert_responses_to_chatcmpl(const json & body); | |
| json server_chat_convert_responses_to_chatcmpl(const json & body); |
|
|
||
| #include "chat.h" | ||
|
|
||
| #include <nlohmann/json.hpp> |
There was a problem hiding this comment.
It should be possible to use json_fwd here, right?
fcad53c to
2438739
Compare
76212e4 to
d0bf6ac
Compare
|
Okay, errors fixed, bumping since there are already further fixes to the Anthropic API people want. |
|
This commit seems to solve the 400 error currently happening in N8N, are there plans to merge it soon? Thanks and great work! |
0a5bf62 to
531b71b
Compare
531b71b to
889121d
Compare
|
@ggml-org/maintainers need two approvals after merge please. |
|
Just had the time to properly pull and build this PR to test it and it works! All problems I had with N8N are gone. Hope it get's merged soon, thanks again for the great work! |
|
@ggml-org/maintainers bumpy bump PTAL :) |
|
@CISC could I get a reapproval pls? This has been stuck for so long now :/ |
|
@ggml-org/maintainers pretty please :) |
Upstream llama.cpp refactor (ggml-org/llama.cpp#20690) moved the OAI/Anthropic/Responses and transcription conversion helpers out of server-common.cpp into a new server-chat.cpp, and server-task.cpp and server-context.cpp now call those symbols (convert_transcriptions_to_chatcmpl, server_chat_convert_responses_to_chatcmpl, server_chat_convert_anthropic_to_oai, server_chat_msg_diff_to_json_oaicompat) via server-chat.h. grpc-server.cpp builds as a single translation unit by #include-ing the upstream .cpp files directly. Without including server-chat.cpp, the declarations are satisfied at compile time via server-chat.h but the link step fails with undefined references once LLAMA_VERSION crosses the refactor commit (134d6e54). Guard the include with __has_include so the same source stays buildable on older LLAMA_VERSION pins that predate the refactor (where prepare.sh won't copy server-chat.cpp into tools/grpc-server/). Assisted-by: Claude:claude-opus-4-7 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…it (#9511) * fix(llama-cpp): include server-chat.cpp in grpc-server translation unit Upstream llama.cpp refactor (ggml-org/llama.cpp#20690) moved the OAI/Anthropic/Responses and transcription conversion helpers out of server-common.cpp into a new server-chat.cpp, and server-task.cpp and server-context.cpp now call those symbols (convert_transcriptions_to_chatcmpl, server_chat_convert_responses_to_chatcmpl, server_chat_convert_anthropic_to_oai, server_chat_msg_diff_to_json_oaicompat) via server-chat.h. grpc-server.cpp builds as a single translation unit by #include-ing the upstream .cpp files directly. Without including server-chat.cpp, the declarations are satisfied at compile time via server-chat.h but the link step fails with undefined references once LLAMA_VERSION crosses the refactor commit (134d6e54). Guard the include with __has_include so the same source stays buildable on older LLAMA_VERSION pins that predate the refactor (where prepare.sh won't copy server-chat.cpp into tools/grpc-server/). Assisted-by: Claude:claude-opus-4-7 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(llama-cpp): bump LLAMA_VERSION to 0d0764dfd Bump to ggml-org/llama.cpp@0d0764d. Paired with the preceding grpc-server server-chat.cpp include so the refactor at 134d6e54 links cleanly. Supersedes PR #9494. Assisted-by: Claude:claude-opus-4-7 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
…n, add tests (ggml-org#20690) * Refactor conversion functions
…n, add tests (ggml-org#20690) * Refactor conversion functions
…n, add tests (ggml-org#20690) * Refactor conversion functions
…n, add tests (#20690) * Refactor conversion functions
…n, add tests (ggml-org#20690) * Refactor conversion functions
Unifies the conversion for Chat Completions, Responses and Anthropic Messages endpoints by moving the conversion functions to a dedicated conversion file in common.
Adds test for Responses API (currently one test for #20280) + fixes issue with
type: messagestring-only content.