diff --git a/agenta-cli/agenta/__init__.py b/agenta-cli/agenta/__init__.py index 8ab228be22..b73eb24d60 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..b10b8c1e17 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 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" 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