基础文本生成实现
使用Any-LLM进行文本生成的基本流程:
1. 核心函数
invocationscompletion()
方法,需要两个必要参数:
– model:格式为”厂商/模型ID”,如”mistral/mistral-small-latest”
– messages:对话消息列表,包含role和content
2. 示例代码
response = completion(
model="mistral/mistral-small-latest",
messages=[{"role": "user", "content": "Python的优势有哪些?"}]
)
print(response.choices[0].message.content)
3. 结果处理
响应格式与OpenAI保持一致,结果存储在response.choices[0].message.content
Center.
This answer comes from the articleAny-LLM: Open Source Tool for Unified Interface Invocation of Multilingual ModelsThe