-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2.py
More file actions
26 lines (24 loc) · 706 Bytes
/
test2.py
File metadata and controls
26 lines (24 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
api_key="65b0348119a6b858ee16dda43ede5a8c.DFnYvPKSZDO5ciKL",
base_url="https://open.bigmodel.cn/api/paas/v4/"
)
class FormatOutput(BaseModel):
intermediate_answer: str
final_answer: str
completion = client.beta.chat.completions.parse(
model="glm-4-flash",
response_format=FormatOutput,
messages=[
{
"role": "user",
"content": "how old are the us president?"
}
],
# stop="\nIntermediate answer:"
)
math_response = completion.choices[0].message
math_response = math_response.parsed
print(math_response.intermediate_answer)
print(math_response.final_answer)