快速开始
准备工作
在开始使用之前,您需开通服务创建大模型 API 服务,并创建 API Key。
-
访问融云控制台的大模型 API 服务页面,切换到您的应用。注:目前仅北京数据中心可开通大模型 API 服务。
-
开启大模型 API 服务。
-
选择去配置: API KEY 配置或者访问融云控制台的 API Key 管理页面,去创建 API Key。
-
通过选择创建 API Key 和指定 API Key 的名字,创建您的 API Key。
通过 REST 接口进行服务调用
以下为不同开发语言的调用示例,调用前:
- 将
<token>
替换为实际获取的 API key。 - 将
<ai-api-base-url>
替换为您的 API Key 所属数据中心的域名。目前仅支持北京数据中心的域名:https://ai.rong-api.com
。
代码示例
- cURL
- Python
- JavaScript
bash
curl --request POST \
--url <ai-api-base-url>/llm/v1/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "Qwen/QwQ-32B",
"messages": [
{
"role": "user",
"content": "融云 IM 服务有哪些优势?"
}
],
"stream": false,
"max_tokens": 512,
"enable_thinking": false,
"thinking_budget": 4096,
"min_p": 0.05,
"stop": null,
"temperature": 0.7,
"top_p": 0.7,
"top_k": 50,
"frequency_penalty": 0.5,
"n": 1,
"response_format": {
"type": "text"
},
"tools": [
{
"type": "function",
"function": {
"description": "<string>",
"name": "<string>",
"parameters": {},
"strict": false
}
}
]
}'
python
import requests
url = "<ai-api-base-url>/llm/v1/chat/completions"
payload = {
"model": "Qwen/QwQ-32B",
"messages": [
{
"role": "user",
"content": "融云 IM 服务有哪些优势?"
}
],
"stream": False,
"max_tokens": 512,
"enable_thinking": False,
"thinking_budget": 4096,
"min_p": 0.05,
"stop": None,
"temperature": 0.7,
"top_p": 0.7,
"top_k": 50,
"frequency_penalty": 0.5,
"n": 1,
"response_format": {"type": "text"},
"tools": [
{
"type": "function",
"function": {
"description": "<string>",
"name": "<string>",
"parameters": {},
"strict": False
}
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
JavaScript
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: '{"model":"Qwen/QwQ-32B","messages":[{"role":"user","content":"融云 IM 服务有哪些优势?"}],"stream":false,"max_tokens":512,"enable_thinking":false,"thinking_budget":4096,"min_p":0.05,"stop":null,"temperature":0.7,"top_p":0.7,"top_k":50,"frequency_penalty":0.5,"n":1,"response_format":{"type":"text"},"tools":[{"type":"function","function":{"description":"<string>","name":"<string>","parameters":{},"strict":false}}]}'
};
fetch('<ai-api-base-url>/llm/v1/chat/completions', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
通过 OpenAI 接口调用
当前大语言模型部分支持以 openai 库进行调用,您可以通过 OpenAI 的 Python 库来调用融云 AI 平台的服务,目前平台支持 OpenAI 相关的大多数参数。以下是使用 OpenAI 库进行调用的步骤和示例代码。
环境要求
安装 Python 3.7.1 或更高版本,并创建虚拟环境。
安装 OpenAI 库
从终端 / 命令行执行以下命令:
bash
pip install --upgrade openai
安装完成后,您可以通过 pip list
显示您在当前环境中安装的 Python 库,确认 OpenAI Python 库已成功安装。 安装成功后,您可通过 OpenAI 的相关接口进行调用。
以下为代码示例,调用前:
- 将
<token>
替换为实际获取的 API key。 - 将
<ai-api-base-url>
替换为您的 API Key 所属数据中心的域名。目前仅支持北京数据中心的域名:https://ai.rong-api.com
。
代码示例
python
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="<ai-api-base-url>/v1/1")
response = client.chat.completions.create(
model='deepseek-ai/DeepSeek-R1',
messages=[
{'role': 'user',
'content': "融云 IM 服务有哪些优势?"}
],
stream=True
)
for chunk in response:
if not chunk.choices:
continue
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.choices[0].delta.reasoning_content:
print(chunk.choices[0].delta.reasoning_content, end="", flush=True)