Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - refactor BinaryParam SDK type #1082

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions agenta-cli/agenta/sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,12 @@ def __modify_schema__(cls, field_schema):
field_schema.update({"x-parameter": "text"})


class BoolMeta(type):
"""
This meta class handles the behavior of a boolean without
directly inheriting from it (avoiding the conflict
that comes from inheriting bool).
"""

def __new__(cls, name: str, bases: tuple, namespace: dict):
if "default" in namespace and namespace["default"] not in [0, 1]:
raise ValueError("Must provide either 0 or 1")
namespace["default"] = bool(namespace.get("default", 0))
instance = super().__new__(cls, name, bases, namespace)
instance.default = 0
class BinaryParam(int):
def __new__(cls, value: bool = False):
instance = super().__new__(cls, int(value))
instance.default = value
return instance


class BinaryParam(int, metaclass=BoolMeta):
@classmethod
def __modify_schema__(cls, field_schema):
field_schema.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const useStyles = createUseStyles({
interface ModelParametersProps {
optParams: Parameter[] | null
onChange: (param: Parameter, value: number | string) => void
handleParamChange: (name: string, value: number | string) => void
handleParamChange: (name: string, value: number | string | boolean) => void
}

export const ModelParameters: React.FC<ModelParametersProps> = ({
Expand All @@ -73,8 +73,7 @@ export const ModelParameters: React.FC<ModelParametersProps> = ({
}) => {
const classes = useStyles()
const handleCheckboxChange = (paramName: string, checked: boolean) => {
const value = checked ? 1 : 0
handleParamChange(paramName, value)
handleParamChange(paramName, checked)
}
return (
<>
Expand Down
3 changes: 1 addition & 2 deletions examples/chat_json_format/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import agenta as ag
from agenta.sdk.types import BinaryParam
from openai import OpenAI

client = OpenAI()
Expand All @@ -20,7 +19,7 @@
model=ag.MultipleChoiceParam("gpt-3.5-turbo", CHAT_LLM_GPT),
max_tokens=ag.IntParam(-1, -1, 4000),
prompt_system=ag.TextParam(SYSTEM_PROMPT),
force_json_response=BinaryParam(),
force_json_response=ag.BinaryParam(False),
)


Expand Down
Loading