jeonghin commited on
Commit ·
c819284
1
Parent(s): 9f791c6
Added try catch for different api keys
Browse files- app_function.py +24 -8
app_function.py
CHANGED
|
@@ -39,9 +39,17 @@ def get_vectorstore(text_chunks):
|
|
| 39 |
Returns:
|
| 40 |
- FAISS: A FAISS vector store containing the embeddings of the text chunks.
|
| 41 |
"""
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
| 46 |
return vectorstore
|
| 47 |
|
|
@@ -57,10 +65,18 @@ def get_conversation_chain(vectorstore):
|
|
| 57 |
Returns:
|
| 58 |
- ConversationalRetrievalChain: An initialized conversational chain object.
|
| 59 |
"""
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 66 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
|
@@ -144,7 +160,7 @@ def chat_sidebar():
|
|
| 144 |
if not st.session_state["song_bool"]:
|
| 145 |
|
| 146 |
if st.sidebar.button("Submit"):
|
| 147 |
-
df = choice.process_data(
|
| 148 |
recommendations = choice.recommendation(
|
| 149 |
df,
|
| 150 |
dance_choice=user_danceability,
|
|
|
|
| 39 |
Returns:
|
| 40 |
- FAISS: A FAISS vector store containing the embeddings of the text chunks.
|
| 41 |
"""
|
| 42 |
+
try:
|
| 43 |
+
embeddings = OpenAIEmbeddings(
|
| 44 |
+
openai_api_base="https://openai.vocareum.com/v1",
|
| 45 |
+
openai_api_key=OPENAI_API_KEY,
|
| 46 |
+
)
|
| 47 |
+
except:
|
| 48 |
+
embeddings = OpenAIEmbeddings(
|
| 49 |
+
openai_api_base="https://openai.vocareum.com/v1",
|
| 50 |
+
openai_api_key=OPENAI_API_KEY2,
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
| 54 |
return vectorstore
|
| 55 |
|
|
|
|
| 65 |
Returns:
|
| 66 |
- ConversationalRetrievalChain: An initialized conversational chain object.
|
| 67 |
"""
|
| 68 |
+
try:
|
| 69 |
+
llm = ChatOpenAI(
|
| 70 |
+
model_name="gpt-4-1106-preview",
|
| 71 |
+
openai_api_base="https://openai.vocareum.com/v1",
|
| 72 |
+
openai_api_key=OPENAI_API_KEY,
|
| 73 |
+
)
|
| 74 |
+
except:
|
| 75 |
+
llm = ChatOpenAI(
|
| 76 |
+
model_name="gpt-4-1106-preview",
|
| 77 |
+
openai_api_base="https://openai.vocareum.com/v1",
|
| 78 |
+
openai_api_key=OPENAI_API_KEY2,
|
| 79 |
+
)
|
| 80 |
|
| 81 |
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 82 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
|
|
|
| 160 |
if not st.session_state["song_bool"]:
|
| 161 |
|
| 162 |
if st.sidebar.button("Submit"):
|
| 163 |
+
df = choice.process_data("data.json")
|
| 164 |
recommendations = choice.recommendation(
|
| 165 |
df,
|
| 166 |
dance_choice=user_danceability,
|