File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ from zhipuai import ZhipuAI
2+ import zhipuai
3+
4+ import logging
5+ import logging .config
6+
7+ def test_mcp_tool_server_url_sse (logging_conf ):
8+ logging .config .dictConfig (logging_conf ) # type: ignore
9+ client = ZhipuAI ()
10+ messages = [
11+ {"role" : "user" , "content" : "今天是几月几号?" }
12+ ]
13+ try :
14+ response = client .chat .completions .create (
15+ model = "glm-4" ,
16+ stream = False ,
17+ messages = messages ,
18+ tools = [
19+ {
20+ "type" : "mcp" ,
21+ "mcp" : {
22+ "headers" : {"Authorization" : "" }, # 替换成用户的 header
23+ "server_label" : "sougou_search" ,
24+ "transport_type" : "sse" ,
25+ "server_url" : "https://open.bigmodel.cn/api/mcp/sogou/sse"
26+ }
27+ },
28+ ]
29+ )
30+ print (response )
31+ except Exception as err :
32+ print (err )
33+
34+ def test_mcp_tool_server_label (logging_conf ):
35+ logging .config .dictConfig (logging_conf ) # type: ignore
36+ client = ZhipuAI ()
37+ messages = [
38+ {"role" : "user" , "content" : "北京现在天气怎么样?" }
39+ ]
40+ try :
41+ response = client .chat .completions .create (
42+ model = "glm-4" ,
43+ stream = True ,
44+ messages = messages ,
45+ tools = [
46+ {
47+ "type" : "mcp" ,
48+ "mcp" : {
49+ "headers" : {"Authorization" : "" }, # 替换成用户的 header
50+ "server_label" : "aviation" ,
51+ }
52+ },
53+ ]
54+ )
55+ for item in response :
56+ print (item )
57+ except Exception as err :
58+ print (err )
You can’t perform that action at this time.
0 commit comments