Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions edge0-infer/tests/unit/cli/serve_protocol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ void metrics_contract() {
}
}
int main(int argc,char** argv) {
{
const auto request=Json::parse(R"({"model":"test","input":[
{"role":"user","content":"first"},
{"type":"reasoning","id":"rs_a","summary":[]},
{"role":"assistant","content":"answer"},
{"role":"user","content":"next"}]})");
auto parsed=portal::parse(request,Protocol::responses,"test");
CHECK(parsed.input.messages.size()==3);
CHECK(parsed.input.messages[1].content=="answer" && !parsed.input.messages[1].reasoning_content);
auto with_content=request;
with_content["input"][1]["content"]=Json::array({{{"type","reasoning_text"},{"text","reason"}}});
parsed=portal::parse(with_content,Protocol::responses,"test");
CHECK(parsed.input.messages.size()==3 && *parsed.input.messages[1].reasoning_content=="reason");
auto no_assistant=request;no_assistant["input"].erase(2);
parsed=portal::parse(no_assistant,Protocol::responses,"test");
CHECK(parsed.input.messages.size()==2 && parsed.input.messages[1].content=="next");
auto malformed=request;malformed["input"][1]["content"]=nullptr;
rejects(malformed,Protocol::responses);
}
metrics_contract();
CHECK(argc==2);
std::ifstream input(argv[1]);Json fixtures;input>>fixtures;
Expand Down
5 changes: 4 additions & 1 deletion edge0-infer/tools/cli/serve_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ Request parse(const Json& j, Protocol protocol, const std::string& alias) {
edge0::TextMessage msg{"tool",content(required(item,"output"),{"input_text"},"input.output")};msg.tool_call_id=str(required(item,"call_id"),"input.call_id");r.input.messages.push_back(std::move(msg));
} else if(type=="reasoning") {
keys(item,{"type","id","content","summary","status"},"input");
auto text=content(required(item,"content"),{"reasoning_text"},"input.content");auto& msg=assistant();if(!msg.reasoning_content)msg.reasoning_content="";*msg.reasoning_content+=text;
if (item.contains("content")) {
auto text=content(item["content"],{"reasoning_text"},"input.content");
auto& msg=assistant();if(!msg.reasoning_content)msg.reasoning_content="";*msg.reasoning_content+=text;
}
} else bad("input.type","Unsupported input item","unsupported_value");
}
}
Expand Down