类功能
功能描述
建立客户端对接语言大模型服务,提供大模型交互功能,当前只支持兼容OpenAI接口/v1/chat/completions。该类继承实现了langchain.llms.base.LLM。
函数原型
from mx_rag.llm import Text2TextLLM # 所有参数需通过关键字参数传递 Text2TextLLM(base_url, model_name, llm_config, client_param)
输入参数说明
参数名 |
数据类型 |
可选/必选 |
说明 |
---|---|---|---|
base_url |
str |
必选 |
大模型服务地址。长度取值范围[1, 128]。 |
model_name |
str |
必选 |
LLM模型名称。长度取值范围[1, 128]。 |
llm_config |
LLMParameterConfig |
可选 |
通过langchain调用时生效,描述参见LLMParameterConfig类;非langchain方式调用通过chat和chat_streamly方法传入参数,参见chat和chat_streamly。 |
client_param |
ClientParam |
可选 |
https客户端配置参数,默认值为“ClientParam()”,具体描述请参见ClientParam类。 |
调用示例
from mx_rag.llm import Text2TextLLM, LLMParameterConfig from mx_rag.utils import ClientParam llm = Text2TextLLM(base_url="https://{ip}:{port}/v1/chat/completions", model_name="qianwen-7b", llm_config=LLMParameterConfig(max_tokens=512), client_param=ClientParam(ca_file="/path/to/ca.crt") ) res = llm.chat("请介绍下北京") print(res) for res in llm.chat_streamly("请介绍下北京"): print(res)
父主题: Text2TextLLM类