当前位置:   article > 正文

Langchain-chatchat的chat接口调用示例_chatchat 示例

chatchat 示例

多轮对话时可选择加入history,history是一个数组,格式如下:

hisotyr = [{'role': 'user', 'content': user_content},
	{'role': 'assistant', 'content': assistant_content}]
  • 1
  • 2

调用的代码如下:

import requests


# 调用langchain-chatchat的chat接口
def chat(param: str, history: list) -> str:
    url = 'http://ip:端口/chat/chat'
    response = requests.post(url,
                             headers={
                                 'Authorization': '',
                                 'Content-Type': 'application/json'
                             },
                             json={
                                 "query": param,
                                 "history": history,
                                 "model_name": "chatglm2-6b",
                                 "temperature": 0.7,
                                 "prompt_name": "llm_chat"
                             },
                             )
    if response.status_code == 200:
        return response.text
    return ''
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

如有错误,还望指正。

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

闽ICP备14008679号