更新最新代码
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
from zhipuai import ZhipuAI
|
||||
def gml_chat(prompt):
|
||||
client = ZhipuAI(api_key="92a0e4868cda21d22fe6fd0f4c0bf6fb.oZ4IE9PPDOhsLKPp")
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="glm-3-turbo",
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": prompt
|
||||
}
|
||||
],
|
||||
top_p=0.7,
|
||||
temperature=0.95,
|
||||
max_tokens=1024,
|
||||
stream=True,
|
||||
)
|
||||
content = ""
|
||||
for trunk in response:
|
||||
# print(trunk.choices[0].delta)
|
||||
content = content + trunk.choices[0].delta.content
|
||||
print(trunk)
|
||||
return content
|
||||
gml_chat("我刚才告诉你我的名字了")
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import re
|
||||
|
||||
str = "这是一段测试字符串,@机器人,请回答。"
|
||||
|
||||
pattern = r"@机器人"
|
||||
matches = re.findall(pattern, str)
|
||||
print(len(matches))
|
||||
result = re.sub(pattern, "", str)
|
||||
print(result)
|
||||
@@ -0,0 +1,25 @@
|
||||
import time
|
||||
from zhipuai import ZhipuAI
|
||||
|
||||
client = ZhipuAI(api_key="92a0e4868cda21d22fe6fd0f4c0bf6fb.oZ4IE9PPDOhsLKPp") # 请填写您自己的APIKey
|
||||
|
||||
response = client.chat.asyncCompletions.create(
|
||||
model="glm-4", # 填写需要调用的模型名称
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "请你作为童话故事大王,写一篇短篇童话故事,故事的主题是要永远保持一颗善良的心,要能够激发儿童的学习兴趣和想象力,同时也能够帮助儿童更好地理解和接受故事中所蕴含的道理和价值观。"
|
||||
}
|
||||
],
|
||||
)
|
||||
task_id = response.id
|
||||
task_status = ''
|
||||
get_cnt = 0
|
||||
|
||||
while task_status != 'SUCCESS' and task_status != 'FAILED' and get_cnt <= 40:
|
||||
result_response = client.chat.asyncCompletions.retrieve_completion_result(id=task_id)
|
||||
print(result_response)
|
||||
task_status = result_response.task_status
|
||||
|
||||
time.sleep(2)
|
||||
get_cnt += 1
|
||||
Reference in New Issue
Block a user