官方网址 https://dify.ai
3. 点击待配置区 OpenAI-API-compatible 右下角的<添加模型>。添加模型界面有下面这些主要的配置项, 所有这些配置参数都可以在胜算云的模型列表页里找到。https://router.shengsuanyun.com/model
例如:deepseek/deepseek-v3, 可以在胜算云的模型列表页点击复制按钮复制。https://router.shengsuanyun.com/model/3
例如:hE3k1o********************************hpHmoIhsUrhfA
API endpoint URL
直接填写 https://router.shengsuanyun.com/api/v1
模型上下文长度
例如:64000
官方网址: https://ima.qq.com
不支持接入。目前只支持 Hunyuan, Hunyuan T1, DeepSeek V3, DeepSeek R1 四款模型,不支持其他模型接入。
官方网址: https://www.coze.cn
https://www.coze.cn/open/docs/guides/Stream_plugin 扣子流式API插件官方配置教程
通过扣子的“插件”系统可以接入胜算云的大语言模型API。在《扣子开发平台》页面点击”快速开始“,左侧边栏”工作空间“ > 二级左侧边栏 ”资源库“ > 右上角 ”+资源“,打开插件定义对话框。第一个页面主要填以下内容。
插件创建成功后进入工具创建页面。创建工具有以下主要内容。
from fastapi import FastAPI, HTTPException
from fastapi.responses import StreamingResponse
from pydantic import BaseModel
from typing import Any, Dict, Optional
import requests
import json
import uvicorn
app = FastAPI(title="胜算云API转换扣子流式输出服务", version="1.0.0")
class ConvertRequest(BaseModel):
api_key: str
data: Dict[str, Any]
def convert_to_coze_stream(api_key: str, data: Dict[str, Any]):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
coze_event = {
"id": '0',
"event": "done",
"data": {
"stream_id": '0',
"is_finish": False,
"is_last_msg": True,
"is_last_packet_in_msg": True,
"content": ""
}
}
url = "https://router.shengsuanyun.com/api/v1/chat/completions"
try:
with requests.post(url, json=data, headers=headers, stream=True, timeout=30) as res:
res.raise_for_status()
for line in res.iter_lines():
if line:
buffer = line.decode('utf-8')
if '[DONE]' in buffer:
yield json.dumps(coze_event)
return
if buffer.startswith("data: "):
json_str = buffer[6:].strip()
if not json_str:
continue
try:
original = json.loads(json_str)
msg_id = original.get("id", "")
choices = original.get("choices", [{}])
if choices:
finish_reason = choices[0].get("finish_reason")
delta = choices[0].get("delta", {})
content = delta.get("content", "")
else:
finish_reason = None
content = ""
event_type = "content" if content else "reasoning"
response_data = {
"stream_id": msg_id,
"is_finish": finish_reason is not None,
"is_last_msg": finish_reason is not None,
"is_last_packet_in_msg": finish_reason is not None,
"content": "hi"
}
event_response = {
**coze_event,
"id": msg_id,
"event": event_type,
"data": response_data
}
yield json.dumps(event_response)
except json.JSONDecodeError as e:
error_msg = {
"error": "JSON解析失败",
"raw_data": json_str[:200],
"details": str(e)
}
print(f"JSON解析错误: {error_msg}")
error_event = {
**coze_event,
"event": "error",
"data": {
**coze_event["data"],
"content": json.dumps(error_msg)
}
}
yield json.dumps(error_event)
except requests.exceptions.RequestException as e:
error_event = {
**coze_event,
"event": "error",
"data": {
**coze_event["data"],
"content": json.dumps({"error": "请求失败", "details": str(e)})
}
}
yield json.dumps(error_event)
@app.post("/xhs/convert/stream")
async def convert_stream_api(request: ConvertRequest):
try:
return StreamingResponse(
convert_to_coze_stream(
api_key=request.api_key,
data=request.data
),
media_type="text/event-stream",
headers={
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "text/event-stream"
}
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"转换失败: {str(e)}")
@app.get("/")
async def root():
return {"message": "API接口规格转换服务运行中", "status": "healthy"}
if name == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
平台不支持自带模型以外的大语言模型,但是可以封装到插件工具中。然后发布到插件商店。
https://agents.baidu.com/docs/develop/plugin/ability-plugin/basic/quick_pass/ 插件制作官方文档。
from flask_cors import CORS
import json
import random
import requests
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "https://agents.baidu.com"}})
@app.route("/coding-master", methods=['POST'])
async def master():
auth_header = request.headers.get('Authorization')
if not auth_header or not auth_header.startswith('Bearer '):
return jsonify({'message': '未提供有效的Authorization头', 'status': 'error'}), 401
api_key = auth_header.split(' ')[1]
if len(api_key) < 10:
return jsonify({'message': '无效的Token', 'status': 'error'}), 401
demand = request.json.get('demand', None)
if not demand:
return jsonify({'message': '无效的编程需求', 'status': 'error'}), 400
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
url = "https://router.shengsuanyun.com/api/v1/chat/completions"
data = {
"model": "anthropic/claude-3.7-sonnet",
"messages": [{
"role": "system",
"content": "You are a helpful assistant that can generate code based on user demands."
},{
"role": "user",
"content": demand
}],
"stream": False
}
try:
res = requests.post(url, json=data, headers=headers, stream=False, timeout=60)
res.raise_for_status()
print(res.json())
# return res.choices[0].message.content
msg = res.json().get('choices', [{}])[0].get('message', None)
if msg:
return jsonify(msg), 200
return jsonify({'message': 'LLM No response', 'status': 'error'}), 500
except Exception as e:
print(str(e))
return jsonify({'message': str(e), 'status': 'error'}), 500
@app.route("/logo.png")
async def plugin_logo():
return send_file('logo.png', mimetype='image/png')
@app.route("/.well-known/ai-plugin.json")
async def plugin_manifest():
host = request.host_url
with open(".well-known/ai-plugin.json", encoding="utf-8") as f:
text = f.read().replace("PLUGIN_HOST", host)
return text, 200, {"Content-Type": "application/json"}
@app.route("/.well-known/openapi.yaml")
async def openapi_spec():
with open(".well-known/openapi.yaml", encoding="utf-8") as f:
text = f.read()
return text, 200, {"Content-Type": "text/yaml"}
@app.route("/example.yaml")
async def exampleSpec():
with open("example.yaml") as f:
text = f.read()
return text, 200, {"Content-Type": "text/yaml"}
@app.route('/')
def index():
return 'welcome to my plugin!'
if name == '__main__':
app.run(debug=True, host='127.0.0.1', port=8888)
配置插件前,先要使用配置文件验证插件服务器。配置文件可以在官方文档中下载。
3. 配置完成以后,可以直接在配置页面测试。
4. 发布到插件商店
发布成功,等待审核通过。