-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8f0393
commit 584ed58
Showing
4 changed files
with
75 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
from llama_chat import get_llama_embeddings, get_llama_answers | ||
from typing import List | ||
from openai_chat import get_openai_answers, get_openai_embeddings | ||
|
||
app = FastAPI() | ||
|
||
class QA(BaseModel): | ||
chunks : List | ||
store_name : str | ||
query : str | ||
k: int | ||
|
||
@app.post('/qa/openai') | ||
def openai_response(input: QA): | ||
vectorstore = get_openai_embeddings(input.chunks, input.store_name) | ||
if input.query: | ||
response = get_openai_answers(vectorstore, input.query, input.k) | ||
return response | ||
|
||
@app.post('/qa/llama') | ||
def llama_response(input: QA): | ||
vectorstore = get_llama_embeddings(input.chunks, input.store_name) | ||
if input.query: | ||
response = get_llama_answers(vectorstore, input.query, input.k) | ||
return response | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Filename: utils.py | ||
Description: Implements functions and methods needed for reading text from files | ||
and splitting into chunks, etc | ||
""" | ||
from PyPDF2 import PdfReader | ||
from langchain.text_splitter import RecursiveCharacterTextSplitter | ||
|
||
def read_pdf(pdf): | ||
""" | ||
Parameters: | ||
- pdf: path to the PDF file | ||
Return: Returns the contents of the PDF file | ||
""" | ||
pdf_reader = PdfReader(pdf) | ||
|
||
content = "" | ||
for page in pdf_reader.pages: | ||
content += page.extract_text() | ||
return content | ||
|
||
def split_into_chunks(content): | ||
""" | ||
Parameters: | ||
- content: the content read from the PDf file | ||
Return: Returns the contents split into chunks | ||
""" | ||
text_splitter = RecursiveCharacterTextSplitter( | ||
chunk_size = 1000, | ||
chunk_overlap = 200, | ||
length_function = len | ||
) | ||
chunks = text_splitter.split_text(text = content) | ||
return chunks |