From af2bda6ce7c2fb8d52119137c9ea2ace47f4abf1 Mon Sep 17 00:00:00 2001 From: sanosh Date: Mon, 25 Nov 2024 14:25:46 +0530 Subject: [PATCH 1/2] adding the yaml_file path in flo build --- flo_ai/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flo_ai/core.py b/flo_ai/core.py index a42ac248..79b8f9bb 100644 --- a/flo_ai/core.py +++ b/flo_ai/core.py @@ -54,6 +54,7 @@ def async_invoke(self, query, config=None) -> Iterator[Union[dict[str, Any], Any def build( session: FloSession, yaml: Optional[str] = None, + yaml_path: Optional[str] = None, routed_team: Optional[FloRouter] = None, log_level: Optional[str] = None, ): @@ -65,6 +66,19 @@ def build( stacklevel=2, ) Flo.set_log_level(log_level) + if yaml_path: + if yaml is not None: + raise FloException( + 'Cannot specify both `yaml` and `yaml_path`. Use only one.' + ) + try: + with open(yaml_path) as file: + yaml = file.read() + except FileNotFoundError: + raise FloException(f'YAML file at path {yaml_path} not found.') + except Exception: + raise FloException(f'Error reading YAML file at path {yaml_path}.') + if yaml is not None: get_logger().info('Building Flo instance from YAML ...', session) executable: ExecutableFlo = build_supervised_team( From f809867ef9601f8a2d4efe4c31b3267cf0ce8ada Mon Sep 17 00:00:00 2001 From: sanosh Date: Mon, 25 Nov 2024 15:03:15 +0530 Subject: [PATCH 2/2] adding unit testing for yaml path --- tests/test.yaml | 11 ++++++++ tests/test_yaml_file_path.py | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/test.yaml create mode 100644 tests/test_yaml_file_path.py diff --git a/tests/test.yaml b/tests/test.yaml new file mode 100644 index 00000000..c58e8c9f --- /dev/null +++ b/tests/test.yaml @@ -0,0 +1,11 @@ +apiVersion: flo/alpha-v1 +kind: FloAgent +name: weather-assistant +agent: + name: WeatherAssistant + kind: agentic + job: > + Given the city name, you are capable of answering the latest weather this time of the year + by searching the internet. + tools: + - name: adder diff --git a/tests/test_yaml_file_path.py b/tests/test_yaml_file_path.py new file mode 100644 index 00000000..637503ed --- /dev/null +++ b/tests/test_yaml_file_path.py @@ -0,0 +1,55 @@ +from flo_ai import Flo, FloSession +from langchain_openai import ChatOpenAI +from flo_ai.tools.flo_tool import flotool +from flo_ai.error.flo_exception import FloException +from typing import List +import asyncio +import pytest + + +@pytest.fixture +def initialize_session(): + llm = ChatOpenAI(temperature=0, model_name='gpt-4o-mini', api_key='TEST_KEY') + session = FloSession(llm) + session.register_tool('adder', addition_tool) + session.register_tool('muller', mul_tool) + return session + + +@flotool(name='AdditionTool', description='Tool to add numbers') +async def addition_tool(numbers: List[int]) -> str: + result = sum(numbers) + await asyncio.sleep(1) + return f'The sum is {result}' + + +@flotool( + name='MultiplicationTool', + description='Tool to multiply numbers to get product of numbers', +) +def mul_tool(numbers: List[int]) -> str: + result = sum(numbers) + return f'The product is {result}' + + +def test_valid_path(initialize_session): + Flo.build(initialize_session, yaml_path='tests/test.yaml') + + +def test_invalid_path(initialize_session): + try: + yaml_path = 'test/test.yaml' + Flo.build(initialize_session, yaml_path=yaml_path) + except FloException as e: + assert str(e) == f'[Error -1] YAML file at path {yaml_path} not found.' + + +def test_both_yaml(initialize_session): + try: + yaml_path = 'test/test.yaml' + Flo.build(initialize_session, yaml='', yaml_path=yaml_path) + except FloException as e: + assert ( + str(e) + == '[Error -1] Cannot specify both `yaml` and `yaml_path`. Use only one.' + )