Skip to content

Commit

Permalink
Merge pull request #1082 from Agenta-AI/gh/feat-sdk-binaryparam
Browse files Browse the repository at this point in the history
Enhancement - refactor BinaryParam SDK type
  • Loading branch information
mmabrouk authored Dec 20, 2023
2 parents 82bda30 + 79e8de8 commit 296dd10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
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

0 comments on commit 296dd10

Please sign in to comment.