File size: 1,601 Bytes
ac87f90 b3849df ac87f90 8044af2 ac87f90 8044af2 ac87f90 b3849df ac87f90 b3849df ac87f90 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import os
from dotenv import load_dotenv
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
from langchain_core.runnables import RunnablePassthrough
import schemas
from prompts import (
raw_prompt,
format_context,
)
# from data_indexing import DataIndexer
load_dotenv()
# data_indexer = DataIndexer()
MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
llm = HuggingFaceEndpoint(
model=MODEL_ID,
huggingfacehub_api_token=os.environ['HF_TOKEN'],
max_new_tokens=512,
stop_sequences=["[EOS]", "<|end_of_text|>"],
streaming=True,
)
chat_model = ChatHuggingFace(llm=llm)
simple_chain = (raw_prompt | chat_model).with_types(input_type=schemas.UserQuestion)
# # TODO: create formatted_chain by piping raw_prompt_formatted and the LLM endpoint.
# formatted_chain = None
# # TODO: use history_prompt_formatted and HistoryInput to create the history_chain
# history_chain = None
# # TODO: Let's construct the standalone_chain by piping standalone_prompt_formatted with the LLM
# standalone_chain = None
# input_1 = RunnablePassthrough.assign(new_question=standalone_chain)
# input_2 = {
# 'context': lambda x: format_context(data_indexer.search(x['new_question'])),
# 'standalone_question': lambda x: x['new_question']
# }
# input_to_rag_chain = input_1 | input_2
# # TODO: use input_to_rag_chain, rag_prompt_formatted,
# # HistoryInput and the LLM to build the rag_chain.
# rag_chain = None
# # TODO: Implement the filtered_rag_chain. It should be the
# # same as the rag_chain but with hybrid_search = True.
# filtered_rag_chain = None
|