Skip to content

Commit

Permalink
updated branch to langchain latest
Browse files Browse the repository at this point in the history
  • Loading branch information
emarco177 committed Feb 9, 2024
1 parent 2c29b18 commit 41d2a9b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions backend/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from langchain_openai import ChatOpenAI, OpenAIEmbeddings

import os
from typing import Any
from langchain.chains import RetrievalQA
from typing import Any, Dict, List
from langchain.chains import ConversationalRetrievalChain
from langchain_community.vectorstores.pinecone import Pinecone as PineconeLangChain
from pinecone import Pinecone

Expand All @@ -16,20 +16,18 @@
INDEX_NAME = "langchain-doc-index"


def run_llm(query: str) -> Any:
embeddings = OpenAIEmbeddings()
def run_llm(query: str, chat_history: List[Dict[str, Any]] = []):
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
docsearch = PineconeLangChain.from_existing_index(
index_name=INDEX_NAME, embedding=embeddings
embedding=embeddings,
index_name=INDEX_NAME,
)
chat = ChatOpenAI(verbose=True, temperature=0)
qa = RetrievalQA.from_chain_type(
llm=chat,
chain_type="stuff",
retriever=docsearch.as_retriever(),
return_source_documents=True,
chat = ChatOpenAI(
verbose=True,
temperature=0,
)
return qa({"query": query})


if __name__ == "__main__":
print(run_llm(query="What is LangChain?"))
qa = ConversationalRetrievalChain.from_llm(
llm=chat, retriever=docsearch.as_retriever(), return_source_documents=True
)
return qa.invoke({"question": query, "chat_history": chat_history})

0 comments on commit 41d2a9b

Please sign in to comment.