From d05ca694e5be68183006d176f7e3cc8d917d19af Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 28 Nov 2023 14:26:22 +0100 Subject: [PATCH 1/4] Feat - created file input url sdk type --- agenta-cli/agenta/sdk/types.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/sdk/types.py b/agenta-cli/agenta/sdk/types.py index 5342f3c3ee..d97c617aea 100644 --- a/agenta-cli/agenta/sdk/types.py +++ b/agenta-cli/agenta/sdk/types.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List -from pydantic import BaseModel, Extra +from pydantic import BaseModel, Extra, HttpUrl class InFile: @@ -106,7 +106,7 @@ class Message(BaseModel): class MessagesInput(list): """Messages Input for Chat-completion. - Parameters: + Args: messages (List[Dict[str, str]]): The list of messages inputs. Required. Each message should be a dictionary with "role" and "content" keys. @@ -128,6 +128,12 @@ def __modify_schema__(cls, field_schema: dict[str, Any]): field_schema.update({"x-parameter": "messages", "type": "array"}) +class FileInputURL(HttpUrl): + @classmethod + def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: + field_schema.update({"x-parameter": "file_url", "type": "string"}) + + class Context(BaseModel): class Config: extra = Extra.allow From 06aef48c0030f6f0852caaabbe623d1a37e0d45e Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 28 Nov 2023 14:26:53 +0100 Subject: [PATCH 2/4] Update - import FileInputURL to sdk __init__ modules --- agenta-cli/agenta/__init__.py | 1 + agenta-cli/agenta/sdk/__init__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/agenta-cli/agenta/__init__.py b/agenta-cli/agenta/__init__.py index 8ab228be22..189f28ecdb 100644 --- a/agenta-cli/agenta/__init__.py +++ b/agenta-cli/agenta/__init__.py @@ -9,6 +9,7 @@ MultipleChoiceParam, MessagesInput, TextParam, + FileInputURL ) from .sdk.utils.preinit import PreInitObject from .sdk.agenta_init import Config, init diff --git a/agenta-cli/agenta/sdk/__init__.py b/agenta-cli/agenta/sdk/__init__.py index 4b4cdc6fe9..dda21429d2 100644 --- a/agenta-cli/agenta/sdk/__init__.py +++ b/agenta-cli/agenta/sdk/__init__.py @@ -11,6 +11,7 @@ MultipleChoiceParam, TextParam, MessagesInput, + FileInputURL ) from .agenta_init import Config, init From 9628573fcf7cca254a3d93d42d6bc21d535d0e37 Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 28 Nov 2023 14:31:11 +0100 Subject: [PATCH 3/4] Update - added annotation and default value to FileInputURL schema --- agenta-cli/agenta/sdk/agenta_decorator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/agenta-cli/agenta/sdk/agenta_decorator.py b/agenta-cli/agenta/sdk/agenta_decorator.py index d12b754182..878d0f5ceb 100644 --- a/agenta-cli/agenta/sdk/agenta_decorator.py +++ b/agenta-cli/agenta/sdk/agenta_decorator.py @@ -26,6 +26,7 @@ MultipleChoiceParam, TextParam, MessagesInput, + FileInputURL, ) app = FastAPI() @@ -315,6 +316,7 @@ def override_schema(openapi_schema: dict, func_name: str, endpoint: str, params: - The min and max values for each IntParam instance - The default value for DictInput instance - The default value for MessagesParam instance + - The default value for FileInputURL instance - ... [PLEASE ADD AT EACH CHANGE] Args: @@ -345,7 +347,6 @@ def find_in_schema(schema: dict, param_name: str, xparam: str): f"Body_{func_name}_{endpoint}_post" ]["properties"] for param_name, param_val in params.items(): - # print(param_name, param_val) if isinstance(param_val, MultipleChoiceParam): subschema = find_in_schema(schema_to_override, param_name, "choice") default = str(param_val) @@ -382,3 +383,9 @@ def find_in_schema(schema: dict, param_name: str, xparam: str): ): subschema = find_in_schema(schema_to_override, param_name, "messages") subschema["default"] = param_val.default + if ( + isinstance(param_val, inspect.Parameter) + and param_val.annotation is FileInputURL + ): + subschema = find_in_schema(schema_to_override, param_name, "file_url") + subschema["default"] = "https://example.com" From cc8894f10dd11b3f54601c93368b86445fb622be Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 28 Nov 2023 14:31:36 +0100 Subject: [PATCH 4/4] :art: Format - ran black --- agenta-cli/agenta/__init__.py | 2 +- agenta-cli/agenta/sdk/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/__init__.py b/agenta-cli/agenta/__init__.py index 189f28ecdb..b73eb24d60 100644 --- a/agenta-cli/agenta/__init__.py +++ b/agenta-cli/agenta/__init__.py @@ -9,7 +9,7 @@ MultipleChoiceParam, MessagesInput, TextParam, - FileInputURL + FileInputURL, ) from .sdk.utils.preinit import PreInitObject from .sdk.agenta_init import Config, init diff --git a/agenta-cli/agenta/sdk/__init__.py b/agenta-cli/agenta/sdk/__init__.py index dda21429d2..b10b8c1e17 100644 --- a/agenta-cli/agenta/sdk/__init__.py +++ b/agenta-cli/agenta/sdk/__init__.py @@ -11,7 +11,7 @@ MultipleChoiceParam, TextParam, MessagesInput, - FileInputURL + FileInputURL, ) from .agenta_init import Config, init