feat: Add base project structure with API and web components

This commit is contained in:
Ke Sun
2025-12-02 20:28:01 +08:00
parent f3de6d6cc9
commit c1adc62ec6
817 changed files with 111226 additions and 106 deletions

View File

@@ -0,0 +1,35 @@
# from typing import Any, Dict, List, Optional
# from langchain_core.runnables import RunnableSerializable
# from app.core.models.base import RedBearModelConfig
# class RedBearRerank(RunnableSerializable[str, List[float]]):
# """ Rerank → 作为 Runnable 插入任意 LCEL 链"""
# def __init__(self, config: RedBearModelConfig):
# super().__init__(self, config)
# def invoke(self, input: Dict[str, Any], config: Optional[Dict] = None) -> List[float]:
# query, docs = input["query"], input["documents"]
# url = (self.config.base_url or "https://api.cohere.ai/v1") + "/rerank"
# body = {
# "query": query,
# "documents": docs,
# "model": self.config.model_name,
# "top_n": len(docs),
# }
# js = self._sync_post(url, body)
# scores = [0.0] * len(docs)
# for item in js["results"]:
# scores[item["index"]] = item["relevance_score"]
# return scores
# async def ainvoke(self, input: Dict[str, Any], config: Optional[Dict] = None) -> List[float]:
# query, docs = input["query"], input["documents"]
# url = (self.config.base_url or "https://api.cohere.ai/v1") + "/rerank"
# body = {"query": query, "documents": docs, "model": self.config.model_name, "top_n": len(docs)}
# js = await self._async_post(url, body)
# scores = [0.0] * len(docs)
# for item in js["results"]:
# scores[item["index"]] = item["relevance_score"]
# return scores