为 GLM-4.7 系列创建上游真实 chat 会话。
(
self,
*,
prompt: str,
model: str,
token: str,
headers: Dict[str, str],
enable_thinking: bool,
web_search: bool,
user_message_id: Optional[str] = None,
files: Optional[List[Dict[str, Any]]] = None,
feature_entries: Optional[List[Dict[str, Any]]] = None,
mcp_servers: Optional[List[str]] = None,
)
| 765 | ) |
| 766 | |
| 767 | async def _create_upstream_chat( |
| 768 | self, |
| 769 | *, |
| 770 | prompt: str, |
| 771 | model: str, |
| 772 | token: str, |
| 773 | headers: Dict[str, str], |
| 774 | enable_thinking: bool, |
| 775 | web_search: bool, |
| 776 | user_message_id: Optional[str] = None, |
| 777 | files: Optional[List[Dict[str, Any]]] = None, |
| 778 | feature_entries: Optional[List[Dict[str, Any]]] = None, |
| 779 | mcp_servers: Optional[List[str]] = None, |
| 780 | ) -> str: |
| 781 | """为 GLM-4.7 系列创建上游真实 chat 会话。""" |
| 782 | init_content = prompt[:CHAT_BOOTSTRAP_MAX_CONTENT_LEN] |
| 783 | if len(prompt) > CHAT_BOOTSTRAP_MAX_CONTENT_LEN: |
| 784 | init_content = init_content + "..." |
| 785 | |
| 786 | message_id = user_message_id or generate_uuid() |
| 787 | timestamp_seconds = int(time.time()) |
| 788 | chat_features = ( |
| 789 | [dict(item) for item in feature_entries] |
| 790 | if feature_entries |
| 791 | else [ |
| 792 | { |
| 793 | "type": "tool_selector", |
| 794 | "server": "tool_selector_h", |
| 795 | "status": "hidden", |
| 796 | } |
| 797 | ] |
| 798 | ) |
| 799 | body = { |
| 800 | "chat": { |
| 801 | "id": "", |
| 802 | "title": "新聊天", |
| 803 | "models": [model], |
| 804 | "params": {}, |
| 805 | "history": { |
| 806 | "messages": { |
| 807 | message_id: { |
| 808 | "id": message_id, |
| 809 | "parentId": None, |
| 810 | "childrenIds": [], |
| 811 | "role": "user", |
| 812 | "content": init_content, |
| 813 | **({"files": [dict(item) for item in files]} if files else {}), |
| 814 | "timestamp": timestamp_seconds, |
| 815 | "models": [model], |
| 816 | } |
| 817 | }, |
| 818 | "currentId": message_id, |
| 819 | }, |
| 820 | "tags": [], |
| 821 | "flags": [], |
| 822 | "features": chat_features, |
| 823 | "mcp_servers": list(mcp_servers or []), |
| 824 | "enable_thinking": enable_thinking, |
no test coverage detected