当前位置:   article > 正文

使用chatglm3本地部署形成的api给上一篇得到的网页信息text_content做内容提取_chatglm3 openai-api 工具调用

chatglm3 openai-api 工具调用

使用chatglm3本地部署形成的api给上一篇得到的网页信息text_content做内容提取,

chatglm3的api调用见:chatglm3的api调用_启动chatglm3的api服务报错-CSDN博客

  1. import os
  2. from openai import OpenAI
  3. base_url = "http://localhost:5000/v1/"
  4. client = OpenAI(api_key="EMPTY", base_url=base_url)
  5. def simple_chat(use_stream=True,use_content="你好,带在华政搞计算机有前途么"):
  6. messages = [
  7. {
  8. "role": "system",
  9. "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.",
  10. },
  11. {
  12. "role": "user",
  13. "content":"简化成4句话"+ use_content
  14. }
  15. ]
  16. response = client.chat.completions.create(
  17. model="chatglm3-6b",
  18. messages=messages,
  19. stream=use_stream,
  20. max_tokens=256,
  21. temperature=0.8,
  22. presence_penalty=1.1,
  23. top_p=0.8)
  24. if response:
  25. if use_stream:
  26. for chunk in response:
  27. print(chunk.choices[0].delta.content)
  28. else:
  29. content = response.choices[0].message.content
  30. print(content)
  31. else:
  32. print("Error:", response.status_code)
  33. if __name__ == "__main__":
  34. simple_chat(use_stream=False,use_content=text_content)

执行效果如下:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/814291
推荐阅读
相关标签
  

闽ICP备14008679号