"modelscope灵积的商业化模型qwen_plus调用,“每0.4s调用一次,连续调用100次,为什么至少有一次调用失败”,麻烦帮忙看一下, 详细信息如下:
OS: ubuntu 22.04.1 内核版本5.19.0-32-generic
Python/C++ Version:Python 3.10.13
Package Version:dashscope-1.13.5
Model:dashscope.Generation.Models.qwen_plus
Command:
'''
def unit_test3():
response = dashscope.Generation.call(
dashscope.Generation.Models.qwen_plus,
messages=messages,
seed=random.randint(0, 10000),
result_format=""message"",
)
if name == ""main"":
with ThreadPoolExecutor(max_workers=50) as executor:
futures = []
for i in range(100):
logging.info(f""start: {i}"")
future = executor.submit(unit_test3, i)
futures.append(future)
time.sleep(0.4)
for future in as_completed(futures):
future.result()
'''
问题描述:
每0.4s调用一次,连续调用100次,至少有一次调用失败
错误提示:
Request id: 0e8e12f7-81f0-9b6a-8710-7cb958dc299b, Status code: 500, error code: RequestTimeOut, error message: Request timed out, please try again later.
Request id: d144e141-8c10-959c-b4ca-9a627e2c9238, Status code: 500, error code: RequestTimeOut, error message: Request timed out, please try again later.
Request id: 666a38e8-19cc-933a-b83c-2a4a3bf2c154, Status code: 500, error code: RequestTimeOut, error message: Request timed out, please try again later."
根据您提供的信息,看起来问题可能是由于请求超时导致的。以下是一些可能的解决方法:
dashscope.Generation.call
函数中,查看是否有设置超时时间的参数,如果有,尝试增加该值。以下是修改后的代码示例,增加了请求超时时间和降低了并发数量:
import json
import logging
from concurrent.futures import ThreadPoolExecutor, as_completed
def unit_test3(seed):
response = dashscope.Generation.call(
dashscope.Generation.Models.qwen_plus,
messages=messages,
seed=seed,
result_format="message",
# 添加超时时间参数(如果存在的话)
timeout=10 # 示例:设置超时时间为10秒
)
if __name__ == "__main__":
with ThreadPoolExecutor(max_workers=10) as executor: # 降低并发数量
futures = []
for i in range(100):
logging.info(f"start: {i}")
future = executor.submit(unit_test3, random.randint(0, 10000))
futures.append(future)
time.sleep(0.4)
for future in as_completed(futures):
future.result()
这个示例中的timeout
参数是假设dashscope.Generation.call
函数支持设置超时时间的。请查阅相关文档或API说明,以确认如何正确设置超时时间。同时,根据实际情况调整并发数量。