You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It can be useful for the AI to know today's date, especially to prepare the parameters for other Function Callings. For example when asking "what are the trending news of yesterday". Beside, it is fast to implement and works all the time.
Note that I left a free parameter for the AI strftime_format, as the seconds since the Unix Epoch format is best suited for compatibility and equations.
Code
frominstructorimportOpenAISchemafrompydanticimportFieldfromdatetimeimportdatetime# Get current timeclassFunction(OpenAISchema):
""" Return local system time of the day. Calling in Python print(datetime.datetime.now()) and potentially format it with strftime(strftime_format) """strftime_format: str=Field(
None,
example="%Y-%m-%d %H:%M:%S",
description="Optional strftime format to format the datetime. To get the number of seconds since the Epoch, call with strftime_format=%s"
)
classConfig:
title="print_local_time"@classmethoddefexecute(cls, strftime_format: str=None) ->str:
current_time=datetime.now()
ifstrftime_format:
returncurrent_time.strftime(strftime_format)
else:
returnstr(current_time)
Example
sgpt "What time is it"
@FunctionCall print_local_time()
2024-07-21 20:46:55.904390
The current local time is 20:46:55 on July 21, 2024.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
It can be useful for the AI to know today's date, especially to prepare the parameters for other Function Callings. For example when asking "what are the trending news of yesterday". Beside, it is fast to implement and works all the time.
Note that I left a free parameter for the AI strftime_format, as the seconds since the Unix Epoch format is best suited for compatibility and equations.
Code
Example
Beta Was this translation helpful? Give feedback.
All reactions