Spaces:
Runtime error
Runtime error
adding Pinecone code
Browse files
app.py
CHANGED
|
@@ -2,15 +2,31 @@
|
|
| 2 |
import streamlit as st
|
| 3 |
from streamlit_chat import message
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from langchain.chains import ConversationChain
|
| 6 |
from langchain.llms import OpenAI
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def load_chain():
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
chain = load_chain()
|
| 16 |
|
|
@@ -33,7 +49,8 @@ def get_text():
|
|
| 33 |
user_input = get_text()
|
| 34 |
|
| 35 |
if user_input:
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
st.session_state.past.append(user_input)
|
| 39 |
st.session_state.generated.append(output)
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from streamlit_chat import message
|
| 4 |
|
| 5 |
+
import pinecone
|
| 6 |
+
import os
|
| 7 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 8 |
+
from langchain.vectorstores import Pinecone
|
| 9 |
+
|
| 10 |
from langchain.chains import ConversationChain
|
| 11 |
from langchain.llms import OpenAI
|
| 12 |
|
| 13 |
+
embeddings = OpenAIEmbeddings()
|
| 14 |
+
|
| 15 |
+
pinecone.init(
|
| 16 |
+
api_key=str(os.environ['PINECONE_API_KEY']),
|
| 17 |
+
environment=str(os.environ['PINECONE_ENV']))
|
| 18 |
+
|
| 19 |
+
index_name = str(os.environ['PINECONE_INDEX_NAME'])
|
| 20 |
|
| 21 |
def load_chain():
|
| 22 |
+
docsearch = Pinecone.from_existing_index(index_name, embeddings)
|
| 23 |
+
return docsearch
|
| 24 |
+
|
| 25 |
+
# def load_chain():
|
| 26 |
+
# """Logic for loading the chain you want to use should go here."""
|
| 27 |
+
# llm = OpenAI(temperature=0)
|
| 28 |
+
# chain = ConversationChain(llm=llm)
|
| 29 |
+
# return chain
|
| 30 |
|
| 31 |
chain = load_chain()
|
| 32 |
|
|
|
|
| 49 |
user_input = get_text()
|
| 50 |
|
| 51 |
if user_input:
|
| 52 |
+
docs = chain.similarity_search(user_input)
|
| 53 |
+
output = docs[0].page_content
|
| 54 |
|
| 55 |
st.session_state.past.append(user_input)
|
| 56 |
st.session_state.generated.append(output)
|