"""
Embedding模型异步连接管理
"""
import os
import logging
from typing import Optional
from langchain_openai import OpenAIEmbeddings

# 导入配置
from app.core.config import config_handler

logger = logging.getLogger(__name__)



def get_embedding_config() -> dict:
    """获取Embedding配置"""
    config = {
        'base_url': config_handler.get("admin_app", "EMBEDDING_BASE_URL", "http://192.168.91.253:9003/v1"),
        'model': config_handler.get("admin_app", "EMBEDDING_MODEL", "Qwen3-Embedding-8B"),
        'api_key': config_handler.get("admin_app", "EMBEDDING_API_KEY", "dummy"),
        'timeout': 30
    }
    return config


def get_embedding_model():
    """获取Embedding模型客户端"""
    config = get_embedding_config()
    embedding_client = OpenAIEmbeddings(
        base_url=config['base_url'],
        model=config['model'],
        api_key=config['api_key'],  # 本地模型使用虚拟API key
    )
    return embedding_client