Skip to content

Commit

Permalink
MODIFIED: changes in RAG_PDF_Groq route
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Mar 28, 2024
1 parent fcef0ad commit 6e8be6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Generative AI, powered by advanced machine learning models, enables the creation
- **Route:** `/text_summarizer_groq`
- **Description:** Dive into a realm of creativity with our text summarization endpoint, where the model mixtral-8x7b-32768 crafts concise summaries from your input text, delivering insights at the speed of thought.

### 12. RAG Using Groq

- **Route:** `/RAG_PDF_Groq`
- **Description:** This endpoint uses the pdf and give the answer based on the prompt provided using Groq,with a default model input of llama2-70b-4096, but offering alternatives like mixtral-8x7b-32768 and gemma-7b-it.

## Usage

Expand Down
8 changes: 5 additions & 3 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,12 @@ async def groq_text_summary(input_text: str = Form(...)):
except Exception as e:
return ResponseText(response=f"Error: {str(e)}")

@app.post("/RAG_PDF_Groq",description="The endpoint uses the pdf and give the answer based on the prompt provided using groq")
async def talk_pd_groq(pdf: UploadFile = File(...),prompt: str = Form(...)):
@app.post("/RAG_PDF_Groq",description="The endpoint uses the pdf and give the answer based on the prompt provided using groq\
In model input default is mixtral-8x7b-32768 but you can choose llama2-70b-4096 and gemma-7b-it.")
async def talk_pd_groq(pdf: UploadFile = File(...),prompt: str = Form(...),
model: Optional[str] = Form('llama2-70b-4096')):
try:
rag_chain = groq_pdf(pdf.file)
rag_chain = groq_pdf(pdf.file,model)
out = rag_chain.invoke(prompt)
db = MongoDB()
payload = {
Expand Down
4 changes: 2 additions & 2 deletions helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def questions_generator(doc):
ques = ques_gen_chain.run(document_ques_gen)
return ques

def groq_pdf(pdf):
def groq_pdf(pdf,model):
llm = ChatGroq(
api_key=os.environ['GROQ_API_KEY'],
model_name='mixtral-8x7b-32768'
model_name=model
)
text = "".join(page.extract_text() for page in PdfReader(pdf).pages)
text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=1000)
Expand Down

0 comments on commit 6e8be6a

Please sign in to comment.