Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
|
|
|
| 13 |
import streamlit as st
|
| 14 |
|
| 15 |
# Custom wrapper for Groq API
|
| 16 |
class GroqLLM(LLM):
|
| 17 |
-
|
| 18 |
-
|
| 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(
|
| 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 =
|
| 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 =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|