赞
踩
使用chatglm3本地部署形成的api给上一篇得到的网页信息text_content做内容提取,
chatglm3的api调用见:chatglm3的api调用_启动chatglm3的api服务报错-CSDN博客
- import os
- from openai import OpenAI
-
- base_url = "http://localhost:5000/v1/"
- client = OpenAI(api_key="EMPTY", base_url=base_url)
- def simple_chat(use_stream=True,use_content="你好,带在华政搞计算机有前途么"):
- messages = [
- {
- "role": "system",
- "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.",
- },
- {
- "role": "user",
- "content":"简化成4句话"+ use_content
- }
- ]
- response = client.chat.completions.create(
- model="chatglm3-6b",
- messages=messages,
- stream=use_stream,
- max_tokens=256,
- temperature=0.8,
- presence_penalty=1.1,
- top_p=0.8)
- if response:
- if use_stream:
- for chunk in response:
- print(chunk.choices[0].delta.content)
- else:
- content = response.choices[0].message.content
- print(content)
- else:
- print("Error:", response.status_code)
- if __name__ == "__main__":
-
- simple_chat(use_stream=False,use_content=text_content)
执行效果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。