Skip to content

Commit

Permalink
v2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Jan 4, 2024
1 parent 0a2226e commit 5a80752
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 25 deletions.
1 change: 1 addition & 0 deletions phi/assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def update(self) -> "Assistant":
self.load_from_openai(self.openai_assistant)
logger.debug(f"Assistant updated: {self.id}")
return self
raise ValueError("Assistant not available")
except AssistantIdNotSet:
logger.warning("Assistant not available")
raise
Expand Down
1 change: 1 addition & 0 deletions phi/assistant/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def download(self, path: Optional[str] = None, suffix: Optional[str] = None) ->
temp_file.write(response.content)
temp_file_path = temp_file.name
return temp_file_path
raise ValueError("File not available")
except FileIdNotSet:
logger.warning("File not available")
raise
Expand Down
1 change: 1 addition & 0 deletions phi/assistant/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def update(self, thread_id: Optional[str] = None) -> "Message":
self.load_from_openai(self.openai_message)
logger.debug(f"Message updated: {self.id}")
return self
raise ValueError("Message not available")
except (ThreadIdNotSet, MessageIdNotSet):
logger.warning("Message not available")
raise
Expand Down
1 change: 1 addition & 0 deletions phi/assistant/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def update(self, thread_id: Optional[str] = None) -> "Run":
self.load_from_openai(self.openai_run)
logger.debug(f"Run updated: {self.id}")
return self
raise ValueError("Run not available")
except (ThreadIdNotSet, RunIdNotSet):
logger.warning("Message not available")
raise
Expand Down
1 change: 1 addition & 0 deletions phi/assistant/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def update(self) -> "Thread":
self.load_from_openai(self.openai_thread)
logger.debug(f"Thead updated: {self.id}")
return self
raise ValueError("Thread not available")
except ThreadIdNotSet:
logger.warning("Thread not available")
raise
Expand Down
1 change: 1 addition & 0 deletions phi/docker/app/whoami/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from phi.docker.app.whoami.whoami import Whoami
15 changes: 15 additions & 0 deletions phi/docker/app/whoami/whoami.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from phi.docker.app.base import DockerApp, ContainerContext # noqa: F401


class Whoami(DockerApp):
# -*- App Name
name: str = "whoami"

# -*- Image Configuration
image_name: str = "traefik/whoami"
image_tag: str = "v1.10"

# -*- App Ports
# Open a container port if open_port=True
open_port: bool = True
port_number: int = 80
147 changes: 125 additions & 22 deletions phi/workspace/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,135 @@
from phi.infra.resources import InfraResources
from phi.api.schemas.workspace import WorkspaceSchema
from phi.workspace.settings import WorkspaceSettings
from phi.utils.py_io import get_python_objects_from_module
from phi.utils.log import logger

# List of directories to ignore when loading the workspace
ignored_dirs = ["ignore", "test", "tests", "config"]


def get_workspace_objects_from_file(resource_file: Path) -> dict:
"""Returns workspace objects from the resource file"""
try:
python_objects = get_python_objects_from_module(resource_file)
# logger.debug(f"python_objects: {python_objects}")

workspace_objects = {}
docker_resources_available = False
create_default_docker_resources = False
k8s_resources_available = False
create_default_k8s_resources = False
aws_resources_available = False
create_default_aws_resources = False
for obj_name, obj in python_objects.items():
_type_name = obj.__class__.__name__
if _type_name in [
"WorkspaceSettings",
"DockerResources",
"K8sResources",
"AwsResources",
]:
workspace_objects[obj_name] = obj
if _type_name == "DockerResources":
docker_resources_available = True
elif _type_name == "K8sResources":
k8s_resources_available = True
elif _type_name == "AwsResources":
aws_resources_available = True

try:
if not docker_resources_available:
if obj.__class__.__module__.startswith("phi.docker"):
create_default_docker_resources = True
if not k8s_resources_available:
if obj.__class__.__module__.startswith("phi.k8s"):
create_default_k8s_resources = True
if not aws_resources_available:
if obj.__class__.__module__.startswith("phi.aws"):
create_default_aws_resources = True
except Exception:
pass

if not docker_resources_available and create_default_docker_resources:
from phi.docker.resources import DockerResources, DockerResource, DockerApp

logger.debug("Creating default docker resources")
default_docker_resources = DockerResources()
add_default_docker_resources = False
for obj_name, obj in python_objects.items():
_obj_class = obj.__class__
if issubclass(_obj_class, DockerResource):
if default_docker_resources.resources is None:
default_docker_resources.resources = []
default_docker_resources.resources.append(obj)
add_default_docker_resources = True
logger.debug(f"Added DockerResource: {obj_name}")
elif issubclass(_obj_class, DockerApp):
if default_docker_resources.apps is None:
default_docker_resources.apps = []
default_docker_resources.apps.append(obj)
add_default_docker_resources = True
logger.debug(f"Added DockerApp: {obj_name}")

if add_default_docker_resources:
workspace_objects["default_docker_resources"] = default_docker_resources

if not k8s_resources_available and create_default_k8s_resources:
from phi.k8s.resources import K8sResources, K8sResource, K8sApp, CreateK8sResource

logger.debug("Creating default k8s resources")
default_k8s_resources = K8sResources()
add_default_k8s_resources = False
for obj_name, obj in python_objects.items():
_obj_class = obj.__class__
# logger.debug(f"Checking {_obj_class}: {obj_name}")
if issubclass(_obj_class, K8sResource) or issubclass(_obj_class, CreateK8sResource):
if default_k8s_resources.resources is None:
default_k8s_resources.resources = []
default_k8s_resources.resources.append(obj)
add_default_k8s_resources = True
logger.debug(f"Added K8sResource: {obj_name}")
elif issubclass(_obj_class, K8sApp):
if default_k8s_resources.apps is None:
default_k8s_resources.apps = []
default_k8s_resources.apps.append(obj)
add_default_k8s_resources = True
logger.debug(f"Added K8sApp: {obj_name}")

if add_default_k8s_resources:
workspace_objects["default_k8s_resources"] = default_k8s_resources

if not aws_resources_available and create_default_aws_resources:
from phi.aws.resources import AwsResources, AwsResource, AwsApp

logger.debug("Creating default aws resources")
default_aws_resources = AwsResources()
add_default_aws_resources = False
for obj_name, obj in python_objects.items():
_obj_class = obj.__class__
# logger.debug(f"Checking {_obj_class}: {obj_name}")
if issubclass(_obj_class, AwsResource):
if default_aws_resources.resources is None:
default_aws_resources.resources = []
default_aws_resources.resources.append(obj)
add_default_aws_resources = True
logger.debug(f"Added AwsResource: {obj_name}")
elif issubclass(_obj_class, AwsApp):
if default_aws_resources.apps is None:
default_aws_resources.apps = []
default_aws_resources.apps.append(obj)
add_default_aws_resources = True
logger.debug(f"Added AwsApp: {obj_name}")

if add_default_aws_resources:
workspace_objects["default_aws_resources"] = default_aws_resources

return workspace_objects
except Exception:
logger.error(f"Error reading: {resource_file}")
raise


class WorkspaceConfig(BaseModel):
"""The WorkspaceConfig stores data for a phidata workspace."""

Expand Down Expand Up @@ -91,9 +214,6 @@ def workspace_settings(self) -> Optional[WorkspaceSettings]:
return None

logger.debug(f"Loading workspace_settings from {ws_settings_file}")

from phi.utils.py_io import get_python_objects_from_module

try:
python_objects = get_python_objects_from_module(ws_settings_file)
for obj_name, obj in python_objects.items():
Expand Down Expand Up @@ -164,7 +284,6 @@ def get_resources(

from sys import path as sys_path
from phi.utils.load_env import load_env
from phi.utils.py_io import get_python_objects_from_module

# Objects to read from the files in the workspace_dir_path
docker_resource_groups: Optional[List[Any]] = None
Expand Down Expand Up @@ -311,7 +430,6 @@ def get_resources_from_file(

from sys import path as sys_path
from phi.utils.load_env import load_env
from phi.utils.py_io import get_python_objects_from_module

# Objects to read from the file
docker_resource_groups: Optional[List[Any]] = None
Expand All @@ -331,24 +449,9 @@ def get_resources_from_file(
logger.debug(f"Adding {resource_file_parent_dir} to path")
sys_path.insert(0, str(resource_file_parent_dir))

# Create a dict of objects in the workspace directory
workspace_objects = {}
logger.debug(f"**--> Loading resources from {resource_file}")
try:
python_objects = get_python_objects_from_module(resource_file)
# logger.debug(f"python_objects: {python_objects}")
for obj_name, obj in python_objects.items():
_type_name = obj.__class__.__name__
if _type_name in [
"WorkspaceSettings",
"DockerResources",
"K8sResources",
"AwsResources",
]:
workspace_objects[obj_name] = obj
except Exception:
logger.warning(f"Error in {resource_file}")
raise
# Create a dict of objects from the file
workspace_objects = get_workspace_objects_from_file(resource_file)

# logger.debug(f"workspace_objects: {workspace_objects}")
for obj_name, obj in workspace_objects.items():
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "phidata"
version = "2.1.3"
version = "2.1.4"
description = "AI Toolkit for Engineers"
requires-python = ">=3.7"
readme = "README.md"
Expand Down Expand Up @@ -80,15 +80,18 @@ module = [
"docker.*",
"duckdb.*",
"kubernetes.*",
"langchain.*",
"langchain_core.*",
"openai.*",
"pandas.*",
"pgvector.*",
"psycopg.*",
"pypdf.*",
"pandas.*",
"qdrant_client.*",
"setuptools.*",
"sqlalchemy.*",
"streamlit.*",
"textract.*",
"wikipedia.*",
"qdrant_client.*",
]
ignore_missing_imports = true

0 comments on commit 5a80752

Please sign in to comment.