当前位置: 首页 > news >正文

服务器部署一个千问2.5-14B、32B并发布为接口

模型:

Qwen/Qwen2.5-14B:魔搭社区

Qwen/Qwen2.5-32B:魔搭社区

其实在下载前我想试试魔塔的接口调用稳不稳定

from openai import OpenAIclient = OpenAI(base_url='https://api-inference.modelscope.cn/v1/',api_key='<MODELSCOPE_SDK_TOKEN>', # ModelScope Token
)# set extra_body for thinking control
extra_body = {# enable thinking, set to False to disable"enable_thinking": True,# use thinking_budget to contorl num of tokens used for thinking# "thinking_budget": 4096
}response = client.chat.completions.create(model='Qwen/Qwen3-32B',  # ModelScope Model-Idmessages=[{'role': 'user','content': '9.9和9.11谁大'}],stream=True,extra_body=extra_body
)
done_thinking = False
for chunk in response:thinking_chunk = chunk.choices[0].delta.reasoning_contentanswer_chunk = chunk.choices[0].delta.contentif thinking_chunk != '':print(thinking_chunk, end='', flush=True)elif answer_chunk != '':if not done_thinking:print('\n\n === Final Answer ===\n')done_thinking = Trueprint(answer_chunk, end='', flush=True)
from openai import OpenAIclient = OpenAI(base_url='https://api-inference.modelscope.cn/v1/',api_key='<MODELSCOPE_SDK_TOKEN>', # ModelScope Token
)# set extra_body for thinking control
extra_body = {# enable thinking, set to False to disable"enable_thinking": True,# use thinking_budget to contorl num of tokens used for thinking# "thinking_budget": 4096
}response = client.chat.completions.create(model='Qwen/Qwen3-14B',  # ModelScope Model-Idmessages=[{'role': 'user','content': '9.9和9.11谁大'}],stream=True,extra_body=extra_body
)
done_thinking = False
for chunk in response:thinking_chunk = chunk.choices[0].delta.reasoning_contentanswer_chunk = chunk.choices[0].delta.contentif thinking_chunk != '':print(thinking_chunk, end='', flush=True)elif answer_chunk != '':if not done_thinking:print('\n\n === Final Answer ===\n')done_thinking = Trueprint(answer_chunk, end='', flush=True)

我预计跑的数据为3k条左右,接口可用,就是有个问题,意思是你所使用的 Qwen/Qwen3-14B 模型仅支持流式模式(stream mode),你必须启用 stream 参数才能访问该模型。

🔁Qwen14B反馈如下: {'error': "Error: Error code: 400 - {'error': {'code': 'invalid_parameter_error', 'message': 'This model only support stream mode, please enable the stream parameter to access the model. ', 'param': None, 'type': 'invalid_request_error'}, 'request_id': 'e44ce9cc-2731-4956-86ff-0bce173ae68d'}"}

后面改了一下代码,流式输出已经能继续处理了。接下来就是看3k条数据跑完后是否有报错与遗漏,来看看接口的稳定性

def validate_explanation(term1, term2, prompt, score, explanation):print("🔎 正在调用Qwen14B 验证解释...")try:# set extra_body for thinking controlextra_body = {# enable thinking, set to False to disable"enable_thinking": True,# use thinking_budget to contorl num of tokens used for thinking# "thinking_budget": 4096}glm4_response = zhipu_client.chat.completions.create(model="Qwen/Qwen3-14B",messages=[{"role": "system","content": ("你的角色是 DeepSeek 使用”提示词“中的附加材料情况的监督者,负责审查用户输入内容,并严格按照以下格式输出分析结果:"},{"role": "user","content": f"术语1: {term1}, 术语2: {term2}, 提示词: {prompt}, 分数: {score}, 解释: {explanation}"}],stream=True,extra_body=extra_body)full_output = ""done_thinking = Falsefor chunk in glm4_response:thinking_chunk = chunk.choices[0].delta.reasoning_contentoutput = chunk.choices[0].delta.contentprint(f"🧠Qwen14B返回:{output}")if thinking_chunk != '':print(thinking_chunk, end='', flush=True)elif output != '':if not done_thinking:print('\n\n === Final Answer ===\n')done_thinking = Truefull_output += outputif full_output.startswith("```json"):full_output = full_output[7:-3].strip()match = re.search(r'{\s*"a":\s*(true|false),\s*"b":\s*(true|false),\s*"c":\s*(true|false),\s*"flag":\s*(true|false),\s*"reply":\s*"(.*?)"\s*}',full_output, re.DOTALL)if match:a, b, c, flag, reply = match.groups()return {"a": a == "true","b": b == "true","c": c == "true","flag": flag == "true","reply": reply.strip()}else:return {"error": "InvalidQwen14B response format: Unable to extract fields."}except Exception as e:return {"error": f"Error: {e}"}

http://www.xdnf.cn/news/282907.html

相关文章:

  • CPU缓存
  • JavaScript基础-顺序流程控制
  • 函数栈帧的创建和销毁
  • 架构进阶:75页架构规划方法课件 【附全文阅读】
  • ARM寻址方式
  • USB3.0 延长线-线序
  • 模板特化详解与示例代码
  • vue-cropper实现图片裁剪
  • WordPress不支持中文TAG标签出现404的解决方法
  • [python]非零基础上手之文件操作
  • JAVA:使用 MapStruct 实现高效对象映射的技术指南
  • AI功能测试源码AI聊天AI视觉AI图像AI视频AI画外音写作助手AI测试多语言无加密源码
  • 第20节:深度学习基础-反向传播算法详解
  • Linux环境下的进程创建-fork函数的使用, 进程退出exit和_exit的区别,以及进程等待waitpid和status数据的提取方法
  • 一款免费的现场大屏幕知识竞赛抢答软件
  • SpringBoot校园失物招领平台源码开发实现
  • 永磁同步电机无速度算法--基于ESO-PLL的永磁同步电机无位置传感器控制
  • 适配器模式(Adapter Pattern)
  • 内容中台的AI中枢是什么?
  • LeetCode 热题 100 48. 旋转图像
  • lombok详解
  • cline或业务系统集成n8n的工作流(MCP Server Trigger、Call n8n Workflow Tool node)
  • 【力扣刷题记录】hot100错题本(一)
  • MySQL--索引精通详解
  • QT6(33)4.6滑动组件QSlider 与QProgressBar:理论,例题的界面搭建,与功能的代码实现
  • PATHWAYS: 用于机器学习的异步分布式数据流
  • Python Cookbook-6.20 精确和安全地使用协作的超类调用
  • 【AI提示词】黑天鹅模型专家
  • 从图文到声纹:DeepSeek 多模态技术的深度解析与实战应用
  • 气泡图、桑基图的绘制