Skip to content

Commit

Permalink
[Controller] Move _process_output to SQL Client (#35)
Browse files Browse the repository at this point in the history
* move function to child because uses unmandatory method

* format
  • Loading branch information
yonishelach authored Nov 4, 2024
1 parent 60c7a30 commit 526ea90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
24 changes: 0 additions & 24 deletions controller/src/controller/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,27 +706,3 @@ def list_sessions(
:return: The list of chat sessions.
"""
pass

def _process_output(
self,
items,
obj_class,
mode: api_models.OutputMode = api_models.OutputMode.DETAILS,
) -> Union[list, dict]:
"""
Process the output of a query. Use this method to convert the output to the desired format.
For example when listing.
:param items: The items to process.
:param obj_class: The class of the items.
:param mode: The output mode.
:return: The processed items.
"""
if mode == api_models.OutputMode.NAMES:
return [item.name for item in items]
items = [self._from_db_object(item, obj_class) for item in items]
if mode == api_models.OutputMode.DETAILS:
return items
short = mode == api_models.OutputMode.SHORT
return [item.to_dict(short=short) for item in items]
24 changes: 24 additions & 0 deletions controller/src/controller/db/sql/sqlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,3 +1360,27 @@ def list_sessions(
if last > 0:
query = query.limit(last)
return self._process_output(query.all(), api_models.ChatSession, output_mode)

def _process_output(
self,
items,
obj_class,
mode: api_models.OutputMode = api_models.OutputMode.DETAILS,
) -> Union[list, dict]:
"""
Process the output of a query. Use this method to convert the output to the desired format.
For example when listing.
:param items: The items to process.
:param obj_class: The class of the items.
:param mode: The output mode.
:return: The processed items.
"""
if mode == api_models.OutputMode.NAMES:
return [item.name for item in items]
items = [self._to_schema_object(item, obj_class) for item in items]
if mode == api_models.OutputMode.DETAILS:
return items
short = mode == api_models.OutputMode.SHORT
return [item.to_dict(short=short) for item in items]
2 changes: 1 addition & 1 deletion genai_factory/src/genai_factory/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import click
import dotenv
from genai_factory.api import router

from genai_factory import WorkflowServerConfig
from genai_factory.api import router

# Load the environment variables:
dotenv.load_dotenv(os.environ.get("GENAI_FACTORY_ENV_PATH", "./.env"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from urllib.parse import urlparse

import uvicorn

from genai_factory.config import WorkflowServerConfig
from genai_factory.controller_client import ControllerClient
from genai_factory.schemas import WorkflowType
Expand Down

0 comments on commit 526ea90

Please sign in to comment.