Pash1986 commited on
Commit
6128278
·
verified ·
1 Parent(s): 98a71ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -8,6 +8,9 @@ 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
@@ -28,8 +31,7 @@ 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
@@ -40,15 +42,15 @@ def get_movies(message, history):
40
 
41
  # try:
42
  movies = vector_store.similarity_search(message, 3)
43
- retrun_text = ''
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
 
49
- for i in range(len(print_llm_text['content'])):
50
  time.sleep(0.05)
51
- yield "Found: " + "\n\n" + print_llm_text['content'][: i+1]
52
  # except:
53
  # yield "Please clone the repo and add your open ai key as well as your MongoDB Atlas UR in the Secret Section of you Space\n OPENAI_API_KEY (your Open AI key) and MONGODB_ATLAS_CLUSTER_URI (0.0.0.0/0 whitelisted instance with Vector index created) \n\n For more information : https://mongodb.com/products/platform/atlas-vector-search"
54
 
 
8
  from langchain_community.llms import OpenAI
9
  from langchain_openai import ChatOpenAI
10
  from langchain_core.prompts import ChatPromptTemplate
11
+ from langchain_core.output_parsers import StrOutputParser
12
+
13
+ output_parser = StrOutputParser()
14
 
15
  # from langchain_community.prompts import PromptTemplate
16
  # from langchain.chains import LLMChain
 
31
  ("system", "You are a movie recommendation engine please elaborate on movies."),
32
  ("user", "List of movies: {input}")
33
  ])
34
+ chain = prompt | llm | output_parser
 
35
 
36
  #except:
37
  # If open ai key is wrong
 
42
 
43
  # try:
44
  movies = vector_store.similarity_search(message, 3)
45
+ return_text = ''
46
  for movie in movies:
47
+ return_text = return_text + 'Title : ' + movie.metadata['title'] + '\n------------\n' + 'Plot: ' + movie.page_content + '\n\n'
48
 
49
+ print_llm_text = chain.invoke({"input": return_text})
50
 
51
+ for i in range(len(print_llm_text)):
52
  time.sleep(0.05)
53
+ yield "Found: " + "\n\n" + print_llm_text[: i+1]
54
  # except:
55
  # yield "Please clone the repo and add your open ai key as well as your MongoDB Atlas UR in the Secret Section of you Space\n OPENAI_API_KEY (your Open AI key) and MONGODB_ATLAS_CLUSTER_URI (0.0.0.0/0 whitelisted instance with Vector index created) \n\n For more information : https://mongodb.com/products/platform/atlas-vector-search"
56