fix CC: map system->user, content string->array, strip tools, fix threadId UUID
This commit is contained in:
Binary file not shown.
@@ -719,11 +719,34 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
def _handle_command_code(self, body, model, stream):
|
||||
input_data = body.get("input", "")
|
||||
raw_msgs = oa_input_to_messages(input_data)
|
||||
|
||||
instructions = body.get("instructions", "").strip()
|
||||
messages = cc_input_to_messages(input_data)
|
||||
cc_msgs = []
|
||||
if instructions:
|
||||
sys_msg = {"role": "system", "content": instructions}
|
||||
messages.insert(0, sys_msg)
|
||||
cc_msgs.append({"role": "user", "content": [{"type": "text", "text": instructions}]})
|
||||
for m in raw_msgs:
|
||||
role = m.get("role", "user")
|
||||
if role == "system":
|
||||
role = "user"
|
||||
content = m.get("content", "")
|
||||
if isinstance(content, str):
|
||||
content = [{"type": "text", "text": content}]
|
||||
elif content is None:
|
||||
content = [{"type": "text", "text": ""}]
|
||||
cc_msgs.append({"role": role, "content": content})
|
||||
for tc in m.get("tool_calls") or []:
|
||||
fn = tc.get("function", {})
|
||||
cc_msgs.append({"role": "assistant", "content": [{"type": "text", "text": ""}],
|
||||
"tool_calls": [{"id": tc.get("id", uid("tc")), "type": "function",
|
||||
"function": {"name": fn.get("name", ""), "arguments": fn.get("arguments", "{}")}}]})
|
||||
if m.get("tool_call_id"):
|
||||
cc_msgs.append({"role": "tool", "tool_call_id": m["tool_call_id"],
|
||||
"content": [{"type": "text", "text": m.get("content", "")}]})
|
||||
|
||||
thread_id = body.get("request_id") or body.get("id") or uid("thread")
|
||||
if len(thread_id) < 32:
|
||||
thread_id = uid("thread")
|
||||
|
||||
cc_body = {
|
||||
"config": _cc_config(),
|
||||
@@ -734,11 +757,11 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
"stream": True,
|
||||
"max_tokens": body.get("max_output_tokens", 64000),
|
||||
"temperature": body.get("temperature", 0.3),
|
||||
"messages": messages,
|
||||
"messages": cc_msgs,
|
||||
"model": model,
|
||||
"tools": cc_convert_tools(body.get("tools")) or [],
|
||||
"tools": [],
|
||||
},
|
||||
"threadId": body.get("request_id") or uid("thread"),
|
||||
"threadId": thread_id,
|
||||
}
|
||||
|
||||
target = upstream_target(TARGET_URL, "/alpha/generate")
|
||||
|
||||
Reference in New Issue
Block a user