MCPcopy Create free account
hub / github.com/antirez/ds4 / parse_responses_request

Function parse_responses_request

ds4_server.c:3696–3959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3694 chat_msgs_free(&msgs);
3695 free(tool_schemas);
3696 request_free(r);
3697 return false;
3698 }
3699 chat_msgs_free(&msgs);
3700 free(tool_schemas);
3701 return true;
3702bad:
3703 chat_msgs_free(&msgs);
3704 free(tool_schemas);
3705 snprintf(err, errlen, "invalid JSON request");
3706 request_free(r);
3707 return false;
3708}
3709
3710static bool parse_anthropic_request(ds4_engine *e, server *s, const char *body, int def_tokens,
3711 int ctx_size, request *r, char *err, size_t errlen) {
3712 request_init(r, REQ_CHAT, def_tokens);
3713 r->api = API_ANTHROPIC;
3714 r->model_syntax = server_model_syntax_for_engine(e);
3715 const char *p = body;
3716 bool got_messages = false;
3717 bool tool_choice_none = false;
3718 bool got_thinking = false;
3719 bool thinking_enabled = true;
3720 ds4_think_mode reasoning_effort = DS4_THINK_HIGH;
3721 chat_msgs msgs = {0};
3722 char *system = NULL;
3723 char *tool_schemas = NULL;
3724
3725 json_ws(&p);
3726 if (*p != '{') goto bad;
3727 p++;
3728 json_ws(&p);
3729 while (*p && *p != '}') {
3730 char *key = NULL;
3731 if (!json_string(&p, &key)) goto bad;
3732 json_ws(&p);
3733 if (*p != ':') {
3734 free(key);
3735 goto bad;
3736 }
3737 p++;
3738 if (!strcmp(key, "messages")) {
3739 chat_msgs_free(&msgs);
3740 if (!parse_anthropic_messages(&p, &msgs)) {
3741 free(key);
3742 goto bad;
3743 }
3744 got_messages = true;
3745 } else if (!strcmp(key, "system")) {
3746 char *tmp = NULL;
3747 if (!parse_anthropic_system(&p, &tmp)) {
3748 free(key);
3749 goto bad;
3750 }
3751 free(system);
3752 system = tmp;
3753 } else if (!strcmp(key, "tools")) {

Callers 1

client_mainFunction · 0.85

Calls 15

request_initFunction · 0.85
json_wsFunction · 0.85
json_stringFunction · 0.85
chat_msgs_freeFunction · 0.85
chat_msgs_pushFunction · 0.85
parse_responses_inputFunction · 0.85
json_litFunction · 0.85
parse_tools_valueFunction · 0.85
request_freeFunction · 0.85
json_skip_valueFunction · 0.85
json_intFunction · 0.85
json_numberFunction · 0.85

Tested by

no test coverage detected