| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import os
- from foundation.base.config import config_handler
- from foundation.logger.loggering import server_logger
- from openai import OpenAI
- class BaseApiPlatform:
- def __init__(self):
- self.api_key = os.getenv("API_KEY")
- self.headers = {
- "Authorization": f"Bearer {self.api_key}",
- "Content-Type": "application/json"
- }
-
- def get_openai_client(self , model_server_url , api_key):
- """
- 获取openai模型 client
- """
- server_logger.info(f"get_openai_client -> model_server_url:{model_server_url},api_key:{api_key}")
- # 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
- client = OpenAI(
- api_key=api_key,
- base_url=model_server_url,
- )
- return client
- def get_chat_model(self):
- """
- 获取chat模型
- :return:
- """
- raise NotImplementedError
-
- def get_embeddings(self, texts: list[str]):
- """
- 向量化文本
- :param texts: 文本列表
- :return: 向量列表
- """
- raise NotImplementedError
- def rerank(self, input_query: str, documents: list, top_n: int = 5, return_documents: bool = True):
- """
- 使用 BGE 重排序模型进行相关性打分
- 使用重排序模型对候选文档进行排序
- :param query: 用户查询语句
- :param documents: 候选文本列表
- :param top_n: 返回前 N 个结果
- :return: 排序后的结果列表,包含文本和相似度分数
- """
- raise NotImplementedError
-
-
|