Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,9 @@ from pymongo import MongoClient
|
|
| 6 |
from langchain_community.vectorstores import MongoDBAtlasVectorSearch
|
| 7 |
from langchain_openai import OpenAIEmbeddings
|
| 8 |
from langchain_community.llms import OpenAI
|
|
|
|
|
|
|
|
|
|
| 9 |
# from langchain_community.prompts import PromptTemplate
|
| 10 |
# from langchain.chains import LLMChain
|
| 11 |
import json
|
|
@@ -20,6 +23,13 @@ collection = client[db_name][collection_name]
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
vector_store = MongoDBAtlasVectorSearch(embedding=OpenAIEmbeddings(), collection=collection, index_name='vector_index', text_key='plot', embedding_key='plot_embedding')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
except:
|
| 25 |
# If open ai key is wrong
|
|
@@ -34,6 +44,7 @@ def get_movies(message, history):
|
|
| 34 |
for movie in movies:
|
| 35 |
retrun_text = retrun_text + 'Title : ' + movie.metadata['title'] + '\n------------\n' + 'Plot: ' + movie.page_content + '\n\n'
|
| 36 |
|
|
|
|
| 37 |
for i in range(len(retrun_text)):
|
| 38 |
time.sleep(0.05)
|
| 39 |
yield "Found: " + "\n\n" + retrun_text[: i+1]
|
|
|
|
| 6 |
from langchain_community.vectorstores import MongoDBAtlasVectorSearch
|
| 7 |
from langchain_openai import OpenAIEmbeddings
|
| 8 |
from langchain_community.llms import OpenAI
|
| 9 |
+
from langchain_openai import ChatOpenAI
|
| 10 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 11 |
+
|
| 12 |
# from langchain_community.prompts import PromptTemplate
|
| 13 |
# from langchain.chains import LLMChain
|
| 14 |
import json
|
|
|
|
| 23 |
|
| 24 |
try:
|
| 25 |
vector_store = MongoDBAtlasVectorSearch(embedding=OpenAIEmbeddings(), collection=collection, index_name='vector_index', text_key='plot', embedding_key='plot_embedding')
|
| 26 |
+
llm = ChatOpenAI()
|
| 27 |
+
prompt = ChatPromptTemplate.from_messages([
|
| 28 |
+
("system", "You are a movie recommendation engine please elaborate on movies."),
|
| 29 |
+
("user", "List of movies: {input}")
|
| 30 |
+
])
|
| 31 |
+
chain = prompt | llm
|
| 32 |
+
|
| 33 |
|
| 34 |
except:
|
| 35 |
# If open ai key is wrong
|
|
|
|
| 44 |
for movie in movies:
|
| 45 |
retrun_text = retrun_text + 'Title : ' + movie.metadata['title'] + '\n------------\n' + 'Plot: ' + movie.page_content + '\n\n'
|
| 46 |
|
| 47 |
+
print_llm_text = chain.invoke({"input": retrun_text})
|
| 48 |
for i in range(len(retrun_text)):
|
| 49 |
time.sleep(0.05)
|
| 50 |
yield "Found: " + "\n\n" + retrun_text[: i+1]
|