You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import typer
from typing import Optional, List
from phi.model.groq import Groq
from phi.agent import Agent
from phi.storage.agent.postgres import PgAgentStorage
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector2
from phi.embedder.base import Embedder
from phi.embedder.google import GeminiEmbedder
from dotenv import load_dotenv
import os
Load environment variables from a .env file
load_dotenv()
Retrieve the database URL from environment variables
# Retrieve existing run IDs for the user if not starting a new session
if not new:
existing_run_ids: List[str] = storage.get_all_run_ids(user)
if existing_run_ids:
run_id = existing_run_ids[0]
# Initialize the agent with the specified model, knowledge base, and storage
assistant = Agent(
model=Groq(id="llama-3.3-70b-versatile", embedder=embedder),
run_id=run_id,
user_id=user,
knowledge_base=knowledge_base,
storage=storage,
show_tool_calls=True,
search_knowledge=True,
read_chat_history=True,
)
# Print the run ID status
if run_id is None:
run_id = assistant.run_id
print(f"Started Run: {run_id}\n")
else:
print(f"Continuing Run: {run_id}\n")
# Start the command-line interface for the assistant
assistant.cli_app(markdown=True)
if name == "main":
typer.run(pdf_assistant)
error is :
(C:\Users\ASUS\all python files\Financial AI analyst.conda) PS C:\Users\ASUS\all python files\Financial AI analyst> python pdf_assistant.py
Traceback (most recent call last):
File "C:\Users\ASUS\all python files\Financial AI analyst\pdf_assistant.py", line 9, in
from phi.embedder.google import GeminiEmbedder
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\site-packages\phi\embedder\google.py", line 14, in
class GeminiEmbedder(Embedder):
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_model_construction.py", line 226, in new
complete_model_class(
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_model_construction.py", line 658, in complete_model_class
schema = cls.get_pydantic_core_schema(cls, handler)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic\main.py", line 702, in get_pydantic_core_schema
return handler(source)
^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_schema_generation_shared.py", line 84, in call
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 610, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 879, in _generate_schema_inner
return self._model_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 691, in _model_schema
{k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1071, in _generate_md_field_schema
common_field = self._common_field_schema(name, field_info, decorators)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1263, in _common_field_schema
schema = self._apply_annotations(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 2056, in _apply_annotations
schema = get_inner_schema(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_schema_generation_shared.py", line 84, in call
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 2037, in inner_handler
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 884, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 986, in match_type
return self._match_generic_type(obj, origin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1014, in _match_generic_type
return self._union_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1325, in _union_schema
choices.append(self.generate_schema(arg))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 610, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 884, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 975, in match_type
return self._call_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1818, in _call_schema
type_hints = _typing_extra.get_function_type_hints(function, globalns=globalns, localns=localns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 730, in get_function_type_hints
type_hints[name] = eval_type_backport(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 609, in eval_type_backport
return _eval_type_backport(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 633, in _eval_type_backport
return _eval_type(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 667, in _eval_type
return typing._eval_type( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\typing.py", line 415, in _eval_type
return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\typing.py", line 947, in _evaluate
eval(self.forward_code, globalns, localns),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1, in
NameError: name 'model_types' is not defined
The text was updated successfully, but these errors were encountered:
import typer
from typing import Optional, List
from phi.model.groq import Groq
from phi.agent import Agent
from phi.storage.agent.postgres import PgAgentStorage
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector2
from phi.embedder.base import Embedder
from phi.embedder.google import GeminiEmbedder
from dotenv import load_dotenv
import os
Load environment variables from a .env file
load_dotenv()
Retrieve the database URL from environment variables
db_url = os.getenv("DATABASE_URL", "postgresql+psycopg://ai:ai@localhost:5532/ai")
Initialize the embedder
embedder = GeminiEmbedder(api_key=os.getenv("GEMINI_API_KEY"))
Initialize the vector database with the embedder
vector_db = PgVector2(collection="reci", db_url=db_url, embedder=embedder)
Initialize the knowledge base with the specified PDF URL and vector database
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=vector_db
)
Load the knowledge base
knowledge_base.load()
Initialize storage for the agent's state
storage = PgAgentStorage(table_name="pdf_assistant", db_url=db_url)
def pdf_assistant(new: bool = False, user: str = "user"):
run_id: Optional[str] = None
if name == "main":
typer.run(pdf_assistant)
error is :
(C:\Users\ASUS\all python files\Financial AI analyst.conda) PS C:\Users\ASUS\all python files\Financial AI analyst> python pdf_assistant.py
Traceback (most recent call last):
File "C:\Users\ASUS\all python files\Financial AI analyst\pdf_assistant.py", line 9, in
from phi.embedder.google import GeminiEmbedder
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\site-packages\phi\embedder\google.py", line 14, in
class GeminiEmbedder(Embedder):
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_model_construction.py", line 226, in new
complete_model_class(
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_model_construction.py", line 658, in complete_model_class
schema = cls.get_pydantic_core_schema(cls, handler)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic\main.py", line 702, in get_pydantic_core_schema
return handler(source)
^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_schema_generation_shared.py", line 84, in call
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 610, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 879, in _generate_schema_inner
return self._model_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 691, in _model_schema
{k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1071, in _generate_md_field_schema
common_field = self._common_field_schema(name, field_info, decorators)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1263, in _common_field_schema
schema = self._apply_annotations(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 2056, in _apply_annotations
schema = get_inner_schema(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_schema_generation_shared.py", line 84, in call
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 2037, in inner_handler
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 884, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 986, in match_type
return self._match_generic_type(obj, origin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1014, in _match_generic_type
return self._union_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1325, in _union_schema
choices.append(self.generate_schema(arg))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 610, in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 884, in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 975, in match_type
return self._call_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_generate_schema.py", line 1818, in _call_schema
type_hints = _typing_extra.get_function_type_hints(function, globalns=globalns, localns=localns)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 730, in get_function_type_hints
type_hints[name] = eval_type_backport(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 609, in eval_type_backport
return _eval_type_backport(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 633, in _eval_type_backport
return _eval_type(value, globalns, localns, type_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\AppData\Roaming\Python\Python312\site-packages\pydantic_internal_typing_extra.py", line 667, in _eval_type
return typing._eval_type( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\typing.py", line 415, in _eval_type
return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ASUS\all python files\Financial AI analyst.conda\Lib\typing.py", line 947, in _evaluate
eval(self.forward_code, globalns, localns),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1, in
NameError: name 'model_types' is not defined
The text was updated successfully, but these errors were encountered: