movie-recommender-chatbot
movie-recommender-chatbot
https://github.com/7AM7/movie-recommender-chatbot/tree/main
import logging from semantic_router import Route, RouteLayer from semantic_router.encoders import OpenAIEncoder from config import Config logger = logging.getLogger("main") class SemanticLayer: def __init__(self, retriever): self.retriever = retriever self.routes = self._initialize_routes() self.route_layer = RouteLayer( encoder=OpenAIEncoder( name=Config.Retriever.EMBEDDING_MODEL, openai_api_key=Config.OpenAI.API_KEY, score_threshold=Config.Retriever.EMBEDDING_THRESHOLD ), routes=self.routes ) def _initialize_routes(self): recommendation_route = Route( name="get_list_of_movies", utterances=[ "Show me some movies", "Do you have 2020 movies?", "I want batman movie", "I want Drama movies", ] ) return [recommendation_route] def process_query(self, query): route = self.route_layer(query) extra = "" logger.info(f"Tool name: {route.name}" ) if route.name == "get_list_of_movies": retrieved_docs = self.retriever.retrieve(query) logger.info(f"Number of retrieved documents: {len(retrieved_docs)}") formatted_docs = SemanticLayer.format_docs(retrieved_docs) extra = f"You can recommend to the user from this list only:\n{formatted_docs}" return extra @staticmethod def format_docs(docs): return "\n\n".join([d.page_content for d in docs])
Movie recommender chatbot using FastAPI, Streamlit, LangChain and semantic-router with FAISS RAG.
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。