Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Feb 12, 2024
1 parent c316ce1 commit a67803b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 41 deletions.
41 changes: 10 additions & 31 deletions ai/knowledge_base.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,37 @@
from phi.embedder.openai import OpenAIEmbedder
from phi.knowledge.combined import CombinedKnowledgeBase
from phi.knowledge.pdf import PDFUrlKnowledgeBase, PDFKnowledgeBase
from phi.knowledge.website import WebsiteKnowledgeBase
from phi.vectordb.pgvector import PgVector2

from ai.settings import ai_settings
from db.session import db_url

url_pdf_knowledge_base = PDFUrlKnowledgeBase(
urls=["https://www.family-action.org.uk/content/uploads/2019/07/meals-more-recipes.pdf"],
# Store this knowledge base in ai.url_pdf_documents
vector_db=PgVector2(
schema="ai",
db_url=db_url,
collection="url_pdf_documents",
),
# 2 references are added to the prompt
num_documents=2,
)

local_pdf_knowledge_base = PDFKnowledgeBase(
path="data/pdfs",
# Store this knowledge base in ai.local_pdf_documents
vector_db=PgVector2(
schema="ai",
db_url=db_url,
collection="local_pdf_documents",
),
# 3 references are added to the prompt
num_documents=3,
)

pdf_knowledge_base = CombinedKnowledgeBase(
sources=[
url_pdf_knowledge_base,
local_pdf_knowledge_base,
PDFUrlKnowledgeBase(urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"]),
PDFKnowledgeBase(path="data/pdfs"),
],
# Store this knowledge base in ai.pdf_documents
vector_db=PgVector2(
schema="ai",
db_url=db_url,
# Store the embeddings in ai.pdf_documents
collection="pdf_documents",
embedder=OpenAIEmbedder(model=ai_settings.embedding_model),
),
# 2 references are added to the prompt
num_documents=2,
)

website_knowledge_base = WebsiteKnowledgeBase(
urls=["https://docs.phidata.com/introduction"],
# Add URLs to the knowledge base
# urls=["https://docs.phidata.com/introduction"],
# Number of links to follow from the seed URLs
max_links=15,
# Store this knowledge base in ai.website_documents
vector_db=PgVector2(
schema="ai",
db_url=db_url,
# Store the embeddings in ai.website_documents
collection="website_documents",
embedder=OpenAIEmbedder(model=ai_settings.embedding_model),
),
# 3 references are added to the prompt
num_documents=3,
Expand Down
2 changes: 1 addition & 1 deletion ai/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AISettings(BaseSettings):
gpt_3_5: str = "gpt-3.5-turbo-1106"
dall_e: str = "dall-e-3"
whisper: str = "whisper-1"
embedding_model: str = "text-embedding-ada-002"
embedding_model: str = "text-embedding-3-small"
default_max_tokens: int = 1024
default_temperature: float = 0

Expand Down
3 changes: 0 additions & 3 deletions ai/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
from db.session import db_url

pdf_assistant_storage = PgAssistantStorage(
schema="ai",
db_url=db_url,
table_name="pdf_assistant",
)

image_assistant_storage = PgAssistantStorage(
schema="ai",
db_url=db_url,
table_name="image_assistant",
)

website_assistant_storage = PgAssistantStorage(
schema="ai",
db_url=db_url,
table_name="website_assistant",
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
# Linting and Formatting
"ruff",
# phidata
"phidata==2.3.19",
"phidata==2.3.35",
]

[build-system]
Expand Down
2 changes: 1 addition & 1 deletion recipe/assistant_with_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from db.session import db_url

knowledge_base = PDFUrlKnowledgeBase(
urls=["https://www.family-action.org.uk/content/uploads/2019/07/meals-more-recipes.pdf"],
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector2(collection="recipes", db_url=db_url),
)

Expand Down
2 changes: 1 addition & 1 deletion recipe/auto_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from db.session import db_url

knowledge_base = PDFUrlKnowledgeBase(
urls=["https://www.family-action.org.uk/content/uploads/2019/07/meals-more-recipes.pdf"],
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector2(collection="recipes", db_url=db_url),
)
knowledge_base.load(recreate=False)
Expand Down
2 changes: 1 addition & 1 deletion recipe/rag_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from db.session import db_url

knowledge_base = PDFUrlKnowledgeBase(
urls=["https://www.family-action.org.uk/content/uploads/2019/07/meals-more-recipes.pdf"],
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector2(collection="recipes", db_url=db_url),
)
knowledge_base.load(recreate=False)
Expand Down
2 changes: 1 addition & 1 deletion recipe/recipe_assistant_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Load the recipe book from s3
recipe_book_s3 = UrlFile(
url="https://www.family-action.org.uk/content/uploads/2019/07/meals-more-recipes.pdf"
url="https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
).get_or_create()
# Load the recipe book locally
# recipe_book_local = LocalFile(path="data/pdfs/meals-more-recipes.pdf").get_or_create()
Expand Down
1 change: 0 additions & 1 deletion workspace/dev_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
pg_database="app",
# Connect to this db on port 5432
host_port=5432,
debug_mode=True,
)

# -*- Build container environment
Expand Down

0 comments on commit a67803b

Please sign in to comment.