feat: update new model examples (#66)
This commit is contained in:
parent
6f108c8ef8
commit
bf4b405605
6 changed files with 16 additions and 16 deletions
|
|
@ -105,7 +105,7 @@ client = ZhipuAiClient(api_key="your-api-key")
|
||||||
|
|
||||||
# Create chat completion
|
# Create chat completion
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7",
|
model="glm-5",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "Hello, Z.ai!"}
|
{"role": "user", "content": "Hello, Z.ai!"}
|
||||||
]
|
]
|
||||||
|
|
@ -279,7 +279,7 @@ client = ZaiClient(api_key="your-api-key")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7",
|
model="glm-5",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "Hello, Z.ai!"}
|
{"role": "user", "content": "Hello, Z.ai!"}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ client = ZhipuAiClient(api_key="your-api-key")
|
||||||
|
|
||||||
# Create chat completion
|
# Create chat completion
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7",
|
model="glm-5",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "Hello, Z.ai!"}
|
{"role": "user", "content": "Hello, Z.ai!"}
|
||||||
]
|
]
|
||||||
|
|
@ -286,7 +286,7 @@ client = ZaiClient(api_key="your-api-key") # 请填写您自己的APIKey
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7",
|
model="glm-5",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "你好, Z.ai !"}
|
{"role": "user", "content": "你好, Z.ai !"}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ def completion():
|
||||||
|
|
||||||
# Create chat completion
|
# Create chat completion
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
||||||
temperature=1.0,
|
temperature=1.0,
|
||||||
)
|
)
|
||||||
|
|
@ -19,7 +19,7 @@ def completion_with_stream():
|
||||||
|
|
||||||
# Create chat completion
|
# Create chat completion
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
messages=[
|
messages=[
|
||||||
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
||||||
{'role': 'user', 'content': 'Tell me a story about AI.'},
|
{'role': 'user', 'content': 'Tell me a story about AI.'},
|
||||||
|
|
@ -38,7 +38,7 @@ def completion_with_websearch():
|
||||||
|
|
||||||
# Create chat completion
|
# Create chat completion
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
messages=[
|
messages=[
|
||||||
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
||||||
{'role': 'user', 'content': 'What is artificial intelligence?'},
|
{'role': 'user', 'content': 'What is artificial intelligence?'},
|
||||||
|
|
@ -66,7 +66,7 @@ def completion_with_mcp_server_url():
|
||||||
|
|
||||||
# Create chat completion with MCP server URL
|
# Create chat completion with MCP server URL
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
stream=False,
|
stream=False,
|
||||||
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
|
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
|
||||||
tools=[
|
tools=[
|
||||||
|
|
@ -95,7 +95,7 @@ def completion_with_mcp_server_label():
|
||||||
|
|
||||||
# Create chat completion with MCP server label
|
# Create chat completion with MCP server label
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
stream=False,
|
stream=False,
|
||||||
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
|
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
|
||||||
tools=[
|
tools=[
|
||||||
|
|
@ -217,7 +217,7 @@ def ofZai():
|
||||||
client = ZaiClient()
|
client = ZaiClient()
|
||||||
print(client.base_url)
|
print(client.base_url)
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
)
|
)
|
||||||
|
|
@ -227,7 +227,7 @@ def ofZhipu():
|
||||||
client = ZhipuAiClient()
|
client = ZhipuAiClient()
|
||||||
print(client.base_url)
|
print(client.base_url)
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model='glm-4.7',
|
model='glm-5',
|
||||||
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ def parse_function_call(model_response, messages):
|
||||||
"tool_call_id": tool_call.id
|
"tool_call_id": tool_call.id
|
||||||
})
|
})
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7", # Specify the model name to use
|
model="glm-5", # Specify the model name to use
|
||||||
messages=messages,
|
messages=messages,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
)
|
)
|
||||||
|
|
@ -99,7 +99,7 @@ messages.append({"role": "system", "content": "Do not assume or guess the values
|
||||||
messages.append({"role": "user", "content": "Help me check the flights from Beijing to Guangzhou on January 23."})
|
messages.append({"role": "user", "content": "Help me check the flights from Beijing to Guangzhou on January 23."})
|
||||||
|
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7", # Specify the model name to use
|
model="glm-5", # Specify the model name to use
|
||||||
messages=messages,
|
messages=messages,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
)
|
)
|
||||||
|
|
@ -110,7 +110,7 @@ parse_function_call(response, messages)
|
||||||
|
|
||||||
messages.append({"role": "user", "content": "What is the price of flight 8321?"})
|
messages.append({"role": "user", "content": "What is the price of flight 8321?"})
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7", # Specify the model name to use
|
model="glm-5", # Specify the model name to use
|
||||||
messages=messages,
|
messages=messages,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class ZaiSampler(SamplerBase):
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
model: str = "glm-4.7",
|
model: str = "glm-5",
|
||||||
api_key: str = '',
|
api_key: str = '',
|
||||||
system_message: Optional[str] = None,
|
system_message: Optional[str] = None,
|
||||||
temperature: float = 0.0,
|
temperature: float = 0.0,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ def main():
|
||||||
client = ZhipuAiClient()
|
client = ZhipuAiClient()
|
||||||
# create chat completion with tool calls and streaming
|
# create chat completion with tool calls and streaming
|
||||||
response = client.chat.completions.create(
|
response = client.chat.completions.create(
|
||||||
model="glm-4.7",
|
model="glm-5",
|
||||||
messages=[
|
messages=[
|
||||||
{"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."},
|
{"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue