'commit'
This commit is contained in:
@@ -7,7 +7,7 @@ import json
|
||||
import aiohttp
|
||||
import logging
|
||||
import base64
|
||||
from openai import OpenAI, BadRequestError
|
||||
from openai import AsyncOpenAI, BadRequestError
|
||||
from Config.Config import (
|
||||
ALY_LLM_API_KEY, VL_MODEL_NAME, VL_MODEL_NAME_AD
|
||||
)
|
||||
@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReadImageKit:
|
||||
_client = OpenAI(
|
||||
_client = AsyncOpenAI(
|
||||
api_key=ALY_LLM_API_KEY,
|
||||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
)
|
||||
@@ -199,8 +199,7 @@ class ReadImageKit:
|
||||
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
|
||||
try:
|
||||
response = await asyncio.to_thread(
|
||||
cls._client.chat.completions.create,
|
||||
response = await cls._client.chat.completions.create(
|
||||
model=VL_MODEL_NAME,
|
||||
messages=[
|
||||
{
|
||||
@@ -226,14 +225,20 @@ class ReadImageKit:
|
||||
|
||||
# 兼容性处理:如果返回的是对象且包含列表字段,提取列表
|
||||
if isinstance(data, dict):
|
||||
for key in ["price_list", "prices", "schedule", "data"]:
|
||||
for key in ["price_list", "prices", "schedule", "data", "items"]:
|
||||
if key in data and isinstance(data[key], list):
|
||||
return data[key]
|
||||
# 如果本身就是个包含列表的字典,也可能需要根据实际情况调整
|
||||
# 这里假设 prompt 引导它返回一个包含列表的对象或直接是列表
|
||||
if "items" in data: return data["items"]
|
||||
|
||||
# 如果字典本身就是一个价格项(包含 start 和 price),将其包装成列表
|
||||
if "start" in data and ("price" in data or "total_price" in data):
|
||||
return [data]
|
||||
|
||||
return data
|
||||
# 如果是列表,直接返回
|
||||
if isinstance(data, list):
|
||||
return data
|
||||
|
||||
# 兜底:确保返回的是列表
|
||||
return [data] if data else []
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calling VL model for price detail: {e}")
|
||||
@@ -252,8 +257,7 @@ class ReadImageKit:
|
||||
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
|
||||
try:
|
||||
response = await asyncio.to_thread(
|
||||
cls._client.chat.completions.create,
|
||||
response = await cls._client.chat.completions.create(
|
||||
model=VL_MODEL_NAME,
|
||||
messages=[
|
||||
{
|
||||
@@ -300,8 +304,7 @@ class ReadImageKit:
|
||||
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
|
||||
try:
|
||||
response = await asyncio.to_thread(
|
||||
cls._client.chat.completions.create,
|
||||
response = await cls._client.chat.completions.create(
|
||||
model=VL_MODEL_NAME,
|
||||
messages=[
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user