rajat5ranjan commited on
Commit
61a50a8
·
verified ·
1 Parent(s): 0159ca8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -18,23 +18,37 @@ GOOGLE_API_KEY=os.environ['GOOGLE_API_KEY']
18
  genai.configure(api_key=GOOGLE_API_KEY)
19
 
20
 
21
- loader = WebBaseLoader("https://blog.google/technology/ai/google-gemini-ai/")
22
  docs = loader.load()
23
- st.write(len(docs))
 
 
 
24
 
25
 
26
- model = genai.GenerativeModel('gemini-pro')
 
 
 
 
27
 
28
- prompt = st.text_input("Enter Prompt","What is the meaning of life?")
29
- response = model.generate_content(prompt)
30
 
31
- st.write(response.text)
32
- # If there is no environment variable set for the API key, you can pass the API
33
- # key to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:
34
- # `google_api_key="key"`.
35
- # llm = ChatGoogleGenerativeAI(model="gemini-pro",
36
- # temperature=0.7, top_p=0.85)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  # If there is no environment variable set for the API key, you can pass the API
40
  # key to the parameter `google_api_key` of the `GoogleGenerativeAIEmbeddings`
 
18
  genai.configure(api_key=GOOGLE_API_KEY)
19
 
20
 
21
+ loader = WebBaseLoader("https://www.google.com/finance/?hl=en")
22
  docs = loader.load()
23
+ # If there is no environment variable set for the API key, you can pass the API
24
+ # key to the parameter `google_api_key` of the `ChatGoogleGenerativeAI` function:
25
+ # `google_api_key="key"`.
26
+ llm = ChatGoogleGenerativeAI(model="gemini-pro",google_api_key = GOOGLE_API_KEY)
27
 
28
 
29
+ llm_prompt_template = """You are an assistant for question-answering tasks.
30
+ Use the following context to answer the question.
31
+ If you don't know the answer, just say that you don't know.
32
+ Use five sentences maximum and keep the answer concise.\n
33
+ Question: {question} \nContext: {context} \nAnswer:"""
34
 
35
+ llm_prompt = PromptTemplate.from_template(llm_prompt_template)
 
36
 
 
 
 
 
 
 
37
 
38
+ def format_docs(docs):
39
+ return "\n\n".join(doc.page_content for doc in docs)
40
+
41
+ rag_chain = (
42
+ {"context": retriever | format_docs, "question": RunnablePassthrough()}
43
+ | llm_prompt
44
+ | llm
45
+ | StrOutputParser()
46
+ )
47
+
48
+ prompt = st.text_input("Enter Prompt","What is the best stocks for the next few weeks")
49
+
50
+ res = rag_chain.invoke(prompt)
51
+ st.write(res)
52
 
53
  # If there is no environment variable set for the API key, you can pass the API
54
  # key to the parameter `google_api_key` of the `GoogleGenerativeAIEmbeddings`