问题描述
使用 Azure Bot Service 来部署机器人服务,如何把大模型嵌入其中?
比如在对话消息时候,能让大模型来提供回答?

问题解答
其实很简单,在 Bot 代码中添加大模型的调用就行。
以 Python 代码为例,首先是准备好调用 LLM 的请求代码
示例说明: 示例中使用的是 Azure OpenAI 的模型
import requests # Azure OpenAI 客户端
def get_openai_answer(prompt):
api_key = "your api key"
endpoint = "your deployment endpoint, like: https://<your azure ai name>.openai.azure.com/openai/deployments/<LLM Name>/chat/completions?api-version=2025-01-01-preview"
if not api_key or not endpoint:
raise ValueError("请配置 Azure OpenAI 信息")
headers = {
"Content-Type": "application/json",
"api-key": api_key
}
systemprompt = f"""您是一个有趣的聊天智能体,能愉快的和人类聊天"""
data = {
"messages": [
{"role": "system", "content": systemprompt},
{"role": "user", "content": prompt}
],
"max_tokens": 5000,
"temperature": 0.7
}
response = requests.post(endpoint, headers=headers, json=data)
response.raise_for_status()
result = response.json()
return result["choices"][][][]
__name__ == :
prompt =
(get_openai_answer(prompt))



