NHZ commited on
Commit
7f026ac
·
verified ·
1 Parent(s): 10f85c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -9,22 +9,20 @@ from langchain.embeddings import HuggingFaceEmbeddings
9
  from langchain.chains import RetrievalQA
10
  from langchain.prompts import PromptTemplate
11
  from langchain.llms.base import LLM
12
- from typing import Optional, List, Mapping, Any
 
13
  import streamlit as st
14
 
15
  # Custom wrapper for Groq API
16
  class GroqLLM(LLM):
17
- def __init__(self, api_key: str, model: str = "llama-3.3-70b-versatile"):
18
- self.api_key = api_key
19
- self.model = model
20
 
21
  @property
22
  def _llm_type(self) -> str:
23
  return "groq"
24
 
25
  def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
26
- import requests
27
-
28
  headers = {"Authorization": f"Bearer {self.api_key}"}
29
  json_data = {
30
  "model": self.model,
@@ -42,7 +40,7 @@ class GroqLLM(LLM):
42
  return data["choices"][0]["message"]["content"]
43
 
44
  # Initialize Groq API LLM
45
- llm = GroqLLM(api_key=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)
46
 
47
  # Function to extract content from a public Google Drive PDF link
48
  def extract_pdf_content(drive_url):
@@ -104,15 +102,4 @@ if text:
104
  )
105
 
106
  # Create a RetrievalQA chain
107
- qa_chain = RetrievalQA(
108
- retriever=retriever,
109
- llm=llm,
110
- prompt=prompt_template
111
- )
112
-
113
- # Run the query through the QA chain
114
- result = qa_chain.run(query)
115
- st.write("Answer:", result)
116
- else:
117
- st.error("Failed to extract content from the document.")
118
-
 
9
  from langchain.chains import RetrievalQA
10
  from langchain.prompts import PromptTemplate
11
  from langchain.llms.base import LLM
12
+ from pydantic import Field
13
+ from typing import Optional, List
14
  import streamlit as st
15
 
16
  # Custom wrapper for Groq API
17
  class GroqLLM(LLM):
18
+ api_key: str = Field(..., env="GROQ_API_KEY")
19
+ model: str = "llama-3.3-70b-versatile"
 
20
 
21
  @property
22
  def _llm_type(self) -> str:
23
  return "groq"
24
 
25
  def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
 
 
26
  headers = {"Authorization": f"Bearer {self.api_key}"}
27
  json_data = {
28
  "model": self.model,
 
40
  return data["choices"][0]["message"]["content"]
41
 
42
  # Initialize Groq API LLM
43
+ llm = GroqLLM()
44
 
45
  # Function to extract content from a public Google Drive PDF link
46
  def extract_pdf_content(drive_url):
 
102
  )
103
 
104
  # Create a RetrievalQA chain
105
+ qa_chain =