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

Functions with datetime arguments #53

Open
ashpreetbedi opened this issue Jan 24, 2024 Discussed in #50 · 1 comment · May be fixed by #249
Open

Functions with datetime arguments #53

ashpreetbedi opened this issue Jan 24, 2024 Discussed in #50 · 1 comment · May be fixed by #249
Assignees
Labels
enhancement New feature or request

Comments

@ashpreetbedi
Copy link
Contributor

Discussed in https://github.com/orgs/phidatahq/discussions/50

Originally posted by adieyal January 19, 2024
Thanks for an excellent library.

I was wondering what the best approach for defining tools whose functions have datetime arguments. From my reading of the code, it seems that you need to create a custom Function since get_json_schema doesn't handle dates. e.g.

class SalesFunction(Function):
    ...
    parameters: Dict[str, Any] = {
        "type": "object",
        "properties": {
            "start_date": {
                "type": "string",
                "format": "date-time",
                "description": ...
            },
            "end_date": {
                "type": "string",
                "format": "date-time",
                "description": ...
            }
        }
    }

    entrypoint: Callable[[str, str], str] = ...

perhaps an alternative would be to customise get_json_schema and then override from_callable to use the new function?

def from_callable(cls, c: Callable) -> "Function":
from inspect import getdoc
from phi.utils.json_schema import get_json_schema
parameters = {"type": "object", "properties": {}}
try:
type_hints = get_type_hints(c)
parameters = get_json_schema(type_hints)
# logger.debug(f"Type hints for {c.__name__}: {type_hints}")
except Exception as e:
logger.warning(f"Could not parse args for {c.__name__}: {e}")
return cls(
name=c.__name__,
description=getdoc(c),
parameters=parameters,
entrypoint=validate_call(c),
)

@ashpreetbedi ashpreetbedi added the enhancement New feature or request label Jan 24, 2024
@ashpreetbedi ashpreetbedi self-assigned this Jan 24, 2024
@ashpreetbedi
Copy link
Contributor Author

cc @adieyal

@nexxeln nexxeln linked a pull request May 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

1 participant