MCPcopy
hub / github.com/zai-org/GLM-4 / process_input

Function process_input

demo/composite_demo/src/client.py:37–57  ·  view source on GitHub ↗
(history: list[dict], tools: list[dict], role_name_replace: dict = None)

Source from the content-addressed store, hash-verified

35
36
37def process_input(history: list[dict], tools: list[dict], role_name_replace: dict = None) -> list[dict]:
38 chat_history = []
39 # if len(tools) > 0:
40 chat_history.append({"role": "system", "content": build_system_prompt(list(ALL_TOOLS), tools)})
41
42 for conversation in history:
43 role = str(conversation.role).removeprefix("<|").removesuffix("|>")
44 if role_name_replace:
45 role = role_name_replace.get(role, role)
46 item = {
47 "role": role,
48 "content": conversation.content,
49 }
50 if conversation.metadata:
51 item["metadata"] = conversation.metadata
52 # Only append image for user
53 if role == "user" and conversation.image:
54 item["image"] = conversation.image
55 chat_history.append(item)
56
57 return chat_history
58
59
60def process_response(output, history):

Callers 3

generate_streamMethod · 0.90
generate_streamMethod · 0.90
generate_streamMethod · 0.90

Calls 1

build_system_promptFunction · 0.90

Tested by

no test coverage detected