zgddlZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZmZdd lmZddlZdd lmZddlZejejeje Z!e!"dej#ddej#ddej#de$ej#de%eej&dZ'e's e(deddddZ) e j*de)dZ+e+,ddd d!"Z-n0#e.$r(Z/e!0d#e/e1d$dZ/[/wwxYwd%Z2e e2gd&'Z3 ed(d)d*e'+Z4n0#e.$r(Z/e!0d,e/e1d-dZ/[/wwxYwed.d/Z5ej6e4e5e-d0e3i1Z7eZ8Gd2d3eZ9Gd4d5eZ:e8;d6d7ZdS)<N) PyPDFLoaderDirectoryLoader)HuggingFaceEmbeddings)SentenceTransformer)RecursiveCharacterTextSplitter)FAISS)PromptTemplate)Together)ConversationBufferMemory)ConversationalRetrievalChain)FastAPI HTTPException) BaseModel) load_dotenv)levelzStarting FastAPI app...ignorez4You are using `torch.load` with `weights_only=False`)messagez+Tried to instantiate class '__path__._path')category TOGETHER_AIzQEnvironment variable TOGETHER_AI_API is missing. Please set it in your .env file.znomic-ai/nomic-embed-text-v1T(289f532e14dbbbd5a04753fa58739e9ba766f3c7)trust_remote_coderevision) model_name model_kwargs ipc_vector_db)allow_dangerous_deserialization similarityi)k max_length) search_type search_kwargsz!Error loading FAISS vectorstore: zIFAISS vectorstore could not be loaded. Ensure the vector database exists.a[INST]As a legal chatbot specializing in the Indian Penal Code, provide a concise and accurate answer based on the given context. Avoid unnecessary details or unrelated content. Only respond if the answer can be derived from the provided context; otherwise, say "The information is not available in the provided context." CONTEXT: {context} CHAT HISTORY: {chat_history} QUESTION: {question} ANSWER: [INST] )contextquestion chat_history)templateinput_variablesz"mistralai/Mistral-7B-Instruct-v0.2g?i)model temperature max_tokenstogether_api_keyz!Error initializing Together API: zQTogether API could not be initialized. Check your API key and network connection.r%) memory_keyreturn_messagesprompt)llmmemory retrievercombine_docs_chain_kwargsceZdZUeed<dS) ChatRequestr$N__name__ __module__ __qualname__str__annotations__2C:\Users\Chaithanya\PycharmProjects\lawapi\main.pyr4r4TsMMMMMr<r4ceZdZUeed<dS) ChatResponseanswerNr5r;r<r=r?r?Ws KKKKKr<r?/cKddiS)Nrz Hello, World!r;r;r<r=rootrC[s  ''r<z/chat)response_modelrequestcK t|j}|dd}t |S#t $r3}t d|tddd}~wwxYw) N)inputr@z*The chatbot could not generate a response.)r@zError during chat invocation: izInternal server error) status_codedetail) qainvoker$getr? Exceptionloggererrorr)rEresultr@es r=chatrR`sM!122H&RSS6**** MMM 9a99:::4KLLLLMsAA B.BB)?logging$langchain_community.document_loadersrrlangchain_huggingfacersentence_transformersrlangchain.text_splitterr langchain_community.vectorstoresrlangchain.promptsr langchain_togetherr langchain.memoryr langchain.chainsr fastapir rpydanticrosdotenvrwarnings basicConfigDEBUG getLoggerr6rNdebugfilterwarnings FutureWarningDeprecationWarninggetenvTOGETHER_AI_API ValueError embeddings load_localdb as_retriever db_retrieverrMrQrO RuntimeErrorprompt_templater.r/r0from_llmrJappr4r?rLrCpostrRr;r<r=rvsHMMMMMMMM777777555555BBBBBB222222,,,,,,''''''555555999999******** '-((((  8 $ $ &'''*`aaaa*WXXXX=9999+=>>>> ")M**j *h i ii# "-'+9cdd d  /:W[ \ \ \B??|QRbeKfKf?ggLLddd LL8Q88999 ,b c ccd  BiBiBi j j j l (2(    CC lll LL8Q88999 ,j k kkl " !^T R R R*!* '0 gii)9(((',//M MMM0/MMMs0-EE/#E**E/FG#F<<G