mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-06-29 00:08:04 +08:00
28 lines
980 B
Python
28 lines
980 B
Python
import zhipuai
|
|
|
|
zhipuai.api_key = "83f977afedc7f414dea579a2551298c2.sydItr1sZT8UPXWb"
|
|
|
|
def service(prompt,history = ""):
|
|
if history == "":
|
|
response = zhipuai.model_api.invoke(
|
|
model="chatglm_turbo",
|
|
prompt=[
|
|
{"role": "user", "content": prompt},
|
|
]
|
|
)
|
|
else:
|
|
response = zhipuai.model_api.invoke(
|
|
model="chatglm_turbo",
|
|
prompt=[
|
|
{"role": "user", "content": history[1]["user"]},
|
|
{"role": "assistant", "content": history[1]["bot"]},
|
|
{"role": "user", "content": history[0]["user"]},
|
|
{"role": "assistant", "content": history[0]["bot"]},
|
|
{"role": "user", "content": prompt},
|
|
]
|
|
)
|
|
if response["code"] == 200:
|
|
return 200, response["data"]["choices"][0]["content"], response["data"]["usage"]['total_tokens']
|
|
else:
|
|
return 50 , response["code"]+response["msg"], 0
|