Skip to content

Commit

Permalink
refactor(webui): 降级 httpx==0.27.2
Browse files Browse the repository at this point in the history
- 解决 Client.__init__() got an unexpected keyword argument 'proxies' 报错
  • Loading branch information
linyqh committed Dec 6, 2024
1 parent d2f7242 commit 36e6018
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
26 changes: 18 additions & 8 deletions app/utils/qwenvl_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,38 @@
class QwenAnalyzer:
"""千问视觉分析器类"""

def __init__(self, model_name: str = "qwen-vl-max-latest", api_key: str = None):
def __init__(self, model_name: str = "qwen-vl-max-latest", api_key: str = None, base_url: str = None):
"""
初始化千问视觉分析器
Args:
model_name: 模型名称,默认使用 qwen-vl-max-latest
api_key: 阿里云API密钥
base_url: API基础URL,如果为None则使用默认值
"""
if not api_key:
raise ValueError("必须提供API密钥")

self.model_name = model_name
self.api_key = api_key
self.base_url = base_url or "https://dashscope.aliyuncs.com/compatible-mode/v1"

# 配置API客户端
self._configure_client()

def _configure_client(self):
"""配置API客户端"""
self.client = OpenAI(
api_key=self.api_key,
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
"""
配置API客户端
使用最简化的参数配置,避免不必要的参数
"""
try:
self.client = OpenAI(
api_key=self.api_key,
base_url=self.base_url
)
except Exception as e:
logger.error(f"初始化OpenAI客户端失败: {str(e)}")
raise

def _image_to_base64(self, image: PIL.Image.Image) -> str:
"""
Expand Down Expand Up @@ -141,7 +151,7 @@ async def analyze_images(self,

while retry_count < 3:
try:
# 在每个批次处理前添加小延迟
# 在每个批次处理前��加小延迟
if i > 0:
await asyncio.sleep(2)

Expand Down Expand Up @@ -199,7 +209,7 @@ def save_results_to_txt(self, results: List[Dict], output_dir: str):
for i, result in enumerate(results):
response_text = result['response']

# 如果有图片路径信息,使用它来生成文件名
# 如果有图片路径信息,���用它来生成文件名
if result.get('image_paths'):
image_paths = result['image_paths']
img_name_start = Path(image_paths[0]).stem.split('_')[-1]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ tenacity>=9.0.0
tiktoken==0.8.0
yt-dlp==2024.11.18
pysrt==1.1.2
httpx==0.27.2
19 changes: 18 additions & 1 deletion webui/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@


def create_vision_analyzer(provider, api_key, model, base_url):
"""
创建视觉分析器实例
Args:
provider: 提供商名称 ('gemini' 或 'qwenvl')
api_key: API密钥
model: 模型名称
base_url: API基础URL
Returns:
VisionAnalyzer 或 QwenAnalyzer 实例
"""
if provider == 'gemini':
return gemini_analyzer.VisionAnalyzer(model_name=model, api_key=api_key)
elif provider == 'qwenvl':
return qwenvl_analyzer.QwenAnalyzer(model_name=model, api_key=api_key)
# 只传入必要的参数
return qwenvl_analyzer.QwenAnalyzer(
model_name=model,
api_key=api_key,
base_url=base_url
)
else:
raise ValueError(f"不支持的视觉分析提供商: {provider}")

Expand Down

0 comments on commit 36e6018

Please sign in to comment.