Skip to content

Commit

Permalink
v2.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed May 9, 2024
1 parent 4242684 commit becb94f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
4 changes: 3 additions & 1 deletion cookbook/assistants/multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ def exponentiate(base: int, exponent: int) -> str:


assistant = Assistant(tools=[multiply, add, exponentiate])
assistant.print_response("Take 3 to the fifth power and multiply that by the sum of twelve and three, then square the whole result. Only show the result.")
assistant.print_response(
"Take 3 to the fifth power and multiply that by the sum of twelve and three, then square the whole result. Only show the result."
)
37 changes: 18 additions & 19 deletions cookbook/knowledge/llamaindex.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# Import necessary modules
# pip install llama-index-core llama-index-readers-file llama-index-embeddings-openai
"""
Import necessary modules
pip install llama-index-core llama-index-readers-file llama-index-embeddings-openai phidata
"""

from pathlib import Path
from shutil import rmtree

import httpx
from phi.assistant import Assistant
from phi.knowledge.llamaindex import LlamaIndexKnowledgeBase

from llama_index.core import (
SimpleDirectoryReader,
StorageContext,
VectorStoreIndex,
)

from llama_index.core.retrievers import VectorIndexRetriever

from llama_index.core.node_parser import SentenceSplitter

import os

import requests

os.makedirs("data\paul_graham", exist_ok=True)

data_dir = Path(__file__).parent.parent.parent.joinpath("wip", "data", "paul_graham")
if data_dir.is_dir():
rmtree(path=data_dir, ignore_errors=True)
data_dir.mkdir(parents=True, exist_ok=True)

url = "https://raw.githubusercontent.com/run-llama/llama_index/main/docs/docs/examples/data/paul_graham/paul_graham_essay.txt"

file_path = "cookbook\knowledge\data\paul_graham\paul_graham_essay.txt"

response = requests.get(url)

file_path = data_dir.joinpath("paul_graham_essay.txt")
response = httpx.get(url)
if response.status_code == 200:
with open(file_path, "wb") as file:
file.write(response.content)
Expand All @@ -35,7 +34,7 @@
print("Failed to download the file")


documents = SimpleDirectoryReader("cookbook\knowledge\data\paul_graham").load_data()
documents = SimpleDirectoryReader(str(data_dir)).load_data()

splitter = SentenceSplitter(chunk_size=1024)

Expand All @@ -47,11 +46,11 @@

retriever = VectorIndexRetriever(index)

# # Create a knowledge base from the vector store
# Create a knowledge base from the vector store
knowledge_base = LlamaIndexKnowledgeBase(retriever=retriever)

# # Create an assistant with the knowledge base
# Create an assistant with the knowledge base
assistant = Assistant(knowledge_base=knowledge_base, search_knowledge=True, debug_mode=True, show_tool_calls=True)

# # Use the assistant to ask a question and print a response.
# Use the assistant to ask a question and print a response.
assistant.print_response("Explain what this text means: low end eats the high end", markdown=True)
2 changes: 1 addition & 1 deletion cookbook/workflows/investment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


reports_dir = Path(__file__).parent.parent.parent.joinpath("wip", "reports")
if reports_dir.exists():
if reports_dir.is_dir():
rmtree(path=reports_dir, ignore_errors=True)
reports_dir.mkdir(parents=True, exist_ok=True)

Expand Down
6 changes: 1 addition & 5 deletions phi/knowledge/llamaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
from phi.utils.log import logger

try:
# I am aadding this to assert that the retreiver we receive is of the correct type.
from llama_index.core.retrievers import BaseRetriever

from llama_index.core.schema import NodeWithScore

from llama_index.core.retrievers import BaseRetriever
except ImportError:
raise ImportError("The `llama-index-core` package is not installed. Please install it via `pip install langchain`.")

Expand All @@ -30,7 +27,6 @@ def search(self, query: str, num_documents: Optional[int] = None) -> List[Docume
List[Document]: A list of relevant documents matching the query.
Raises:
ValueError: If the retriever is not of type BaseRetriever.
"""
if not isinstance(self.retriever, BaseRetriever):
raise ValueError(f"Retriever is not of type BaseRetriever: {self.retriever}")
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.4.2"
version = "2.4.3"
description = "Memory, knowledge and tools for LLMs."
requires-python = ">=3.7"
readme = "README.md"
Expand Down Expand Up @@ -94,8 +94,8 @@ module = [
"kubernetes.*",
"lancedb.*",
"langchain.*",
"langchain.*",
"langchain_core.*",
"llama_index.*",
"mistralai.*",
"newspaper.*",
"nest_asyncio.*",
Expand Down

0 comments on commit becb94f

Please sign in to comment.