forked from phidatahq/phidata
-
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
20715f3
commit c595e8a
Showing
6 changed files
with
58 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ venv* | |
phienv* | ||
aienv* | ||
|
||
# ignore scratch dir | ||
# ignore tmp dirs | ||
scratch | ||
junk | ||
tmp | ||
|
||
.ipynb_checkpoints |
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,36 @@ | ||
import json | ||
from typing import List, Optional | ||
|
||
from phi.assistant import Assistant | ||
from phi.document import Document | ||
from phi.knowledge.pdf import PDFUrlKnowledgeBase | ||
from phi.vectordb.pgvector import PgVector2 | ||
|
||
from resources import vector_db # type: ignore | ||
|
||
knowledge_base = PDFUrlKnowledgeBase( | ||
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], | ||
vector_db=PgVector2(collection="recipes", db_url=vector_db.get_db_connection_local()), | ||
) | ||
# Comment out after first run | ||
# knowledge_base.load(recreate=False) | ||
|
||
|
||
def custom_references_function(query: str, **kwargs) -> Optional[str]: | ||
"""Return a list of references from the knowledge base""" | ||
print(f"-*- Searching for references for query: {query}") | ||
relevant_docs: List[Document] = knowledge_base.search(query=query, num_documents=5) | ||
if len(relevant_docs) == 0: | ||
return None | ||
|
||
return json.dumps([doc.to_dict() for doc in relevant_docs], indent=2) | ||
|
||
|
||
assistant = Assistant( | ||
knowledge_base=knowledge_base, | ||
# Generate references using a custom function. | ||
references_function=custom_references_function, | ||
# Adds references to the prompt. | ||
add_references_to_prompt=True, | ||
) | ||
assistant.print_response("How to make Thai curry?", markdown=True) |
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 |
---|---|---|
@@ -1 +1,12 @@ | ||
from phi.assistant.assistant import Assistant, AssistantRun, AssistantMemory, AssistantStorage, AssistantKnowledge | ||
from phi.assistant.assistant import ( | ||
Assistant, | ||
AssistantRun, | ||
AssistantMemory, | ||
AssistantStorage, | ||
AssistantKnowledge, | ||
LLMTask, | ||
Task, | ||
Function, | ||
Tool, | ||
Toolkit, | ||
) |
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