-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
Parse availability of dates #267
Conversation
WalkthroughThe update introduces two new classes, Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (1)
- examples/avail/run.py (1 hunks)
Additional comments: 1
examples/avail/run.py (1)
- 33-45: The
prepare_dates
function is hardcoded to loop for 7 days, which matches the default parametern=7
. Ensure this is the intended behavior and that the function is flexible enough for different use cases.
examples/avail/run.py
Outdated
class DateRange(BaseModel): | ||
explination: str = Field( | ||
..., description="Explination of the date range in the context of the text" | ||
) | ||
start: datetime | ||
end: datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the DateRange
class field name 'explination'; it should be 'explanation'.
11 class DateRange(BaseModel):
- 12 explination: str = Field(
+ 12 explanation: str = Field(
13 ..., description="Explanation of the date range in the context of the text"
14 )
15 start: datetime
16 end: datetime
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
class DateRange(BaseModel): | |
explination: str = Field( | |
..., description="Explination of the date range in the context of the text" | |
) | |
start: datetime | |
end: datetime | |
class DateRange(BaseModel): | |
explanation: str = Field( | |
..., description="Explanation of the date range in the context of the text" | |
) | |
start: datetime | |
end: datetime |
examples/avail/run.py
Outdated
if __name__ == "__main__": | ||
schedules = parse_availability(text) | ||
for schedule in schedules: | ||
print(schedule.model_dump_json(indent=2)) | ||
{ | ||
"availability": [ | ||
{ | ||
"explination": "General availability from December 8th to December 24th, 9am - 5pm Monday to Saturday", | ||
"start": "2023-12-11T09:00:00", | ||
"end": "2023-12-16T17:00:00", | ||
}, | ||
{ | ||
"explination": "General availability for the Sundays within the range of December 8th to December 24th, 10am - 5pm.", | ||
"start": "2023-12-10T10:00:00", | ||
"end": "2023-12-10T17:00:00", | ||
}, | ||
{ | ||
"explination": "Continuation of general availability from December 8th to December 24th, 9am - 5pm Monday to Saturday for the following week.", | ||
"start": "2023-12-18T09:00:00", | ||
"end": "2023-12-23T17:00:00", | ||
}, | ||
{ | ||
"explination": "Continuation of general availability for the last Sunday within the range of December 8th to December 24th, 10am - 5pm.", | ||
"start": "2023-12-17T10:00:00", | ||
"end": "2023-12-17T17:00:00", | ||
}, | ||
] | ||
} | ||
{ | ||
"availability": [ | ||
{ | ||
"explination": "Special availability for the Friday after Thanksgiving, assumed to be November 24th, 2023 based on the given next days.", | ||
"start": "2023-11-24T09:00:00", | ||
"end": "2023-11-24T17:00:00", | ||
}, | ||
{ | ||
"explination": "Saturdays availability from after Thanksgiving up to the foreseeable Saturdays, 9am till dusk (assumed to be 5pm based on the general availability previously mentioned).", | ||
"start": "2023-11-25T09:00:00", | ||
"end": "2023-11-25T17:00:00", | ||
}, | ||
{ | ||
"explination": "Sundays availability from after Thanksgiving up to the foreseeable Sundays, 9am till dusk (assumed to be 5pm).", | ||
"start": "2023-12-10T09:00:00", | ||
"end": "2023-12-10T17:00:00", | ||
}, | ||
{ | ||
"explination": "Continuation of Saturdays availability, 9am till dusk.", | ||
"start": "2023-12-16T09:00:00", | ||
"end": "2023-12-16T17:00:00", | ||
}, | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON-like structure in the if __name__ == "__main__":
block is not valid Python code and should be removed or corrected to be a valid Python code example.
69 if __name__ == "__main__":
70 schedules = parse_availability(text)
71 for schedule in schedules:
72 print(schedule.model_dump_json(indent=2))
- 73 {
- 74 "availability": [
- 75 {
- 76 "explination": "General availability from December 8th to December 24th, 9am - 5pm Monday to Saturday",
- 77 "start": "2023-12-11T09:00:00",
- 78 "end": "2023-12-16T17:00:00",
- 79 },
- 80 {
- 81 "explination": "General availability for the Sundays within the range of December 8th to December 24th, 10am - 5pm.",
- 82 "start": "2023-12-10T10:00:00",
- 83 "end": "2023-12-10T17:00:00",
- 84 },
- 85 {
- 86 "explination": "Continuation of general availability from December 8th to December 24th, 9am - 5pm Monday to Saturday for the following week.",
- 87 "start": "2023-12-18T09:00:00",
- 88 "end": "2023-12-23T17:00:00",
- 89 },
- 90 {
- 91 "explination": "Continuation of general availability for the last Sunday within the range of December 8th to December 24th, 10am - 5pm.",
- 92 "start": "2023-12-17T10:00:00",
- 93 "end": "2023-12-17T17:00:00",
- 94 },
- 95 ]
- 96 }
- 97 {
- 98 "availability": [
- 99 {
- 100 "explination": "Special availability for the Friday after Thanksgiving, assumed to be November 24th, 2023 based on the given next days.",
- 101 "start": "2023-11-24T09:00:00",
- 102 "end": "2023-11-24T17:00:00",
- 103 },
- 104 {
- 105 "explination": "Saturdays availability from after Thanksgiving up to the foreseeable Saturdays, 9am till dusk (assumed to be 5pm based on the general availability previously mentioned).",
- 106 "start": "2023-11-25T09:00:00",
- 107 "end": "2023-11-25T17:00:00",
- 108 },
- 109 {
- 110 "explination": "Sundays availability from after Thanksgiving up to the foreseeable Sundays, 9am till dusk (assumed to be 5pm).",
- 111 "start": "2023-12-10T09:00:00",
- 112 "end": "2023-12-10T17:00:00",
- 113 },
- 114 {
- 115 "explination": "Continuation of Saturdays availability, 9am till dusk.",
- 116 "start": "2023-12-16T09:00:00",
- 117 "end": "2023-12-16T17:00:00",
- 118 },
- 119 ]
- 120 }
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
if __name__ == "__main__": | |
schedules = parse_availability(text) | |
for schedule in schedules: | |
print(schedule.model_dump_json(indent=2)) | |
{ | |
"availability": [ | |
{ | |
"explination": "General availability from December 8th to December 24th, 9am - 5pm Monday to Saturday", | |
"start": "2023-12-11T09:00:00", | |
"end": "2023-12-16T17:00:00", | |
}, | |
{ | |
"explination": "General availability for the Sundays within the range of December 8th to December 24th, 10am - 5pm.", | |
"start": "2023-12-10T10:00:00", | |
"end": "2023-12-10T17:00:00", | |
}, | |
{ | |
"explination": "Continuation of general availability from December 8th to December 24th, 9am - 5pm Monday to Saturday for the following week.", | |
"start": "2023-12-18T09:00:00", | |
"end": "2023-12-23T17:00:00", | |
}, | |
{ | |
"explination": "Continuation of general availability for the last Sunday within the range of December 8th to December 24th, 10am - 5pm.", | |
"start": "2023-12-17T10:00:00", | |
"end": "2023-12-17T17:00:00", | |
}, | |
] | |
} | |
{ | |
"availability": [ | |
{ | |
"explination": "Special availability for the Friday after Thanksgiving, assumed to be November 24th, 2023 based on the given next days.", | |
"start": "2023-11-24T09:00:00", | |
"end": "2023-11-24T17:00:00", | |
}, | |
{ | |
"explination": "Saturdays availability from after Thanksgiving up to the foreseeable Saturdays, 9am till dusk (assumed to be 5pm based on the general availability previously mentioned).", | |
"start": "2023-11-25T09:00:00", | |
"end": "2023-11-25T17:00:00", | |
}, | |
{ | |
"explination": "Sundays availability from after Thanksgiving up to the foreseeable Sundays, 9am till dusk (assumed to be 5pm).", | |
"start": "2023-12-10T09:00:00", | |
"end": "2023-12-10T17:00:00", | |
}, | |
{ | |
"explination": "Continuation of Saturdays availability, 9am till dusk.", | |
"start": "2023-12-16T09:00:00", | |
"end": "2023-12-16T17:00:00", | |
}, | |
] | |
if __name__ == "__main__": | |
schedules = parse_availability(text) | |
for schedule in schedules: | |
print(schedule.model_dump_json(indent=2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
class DateRange(BaseModel): | ||
explain: str = Field( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the DateRange model also contain timezones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd say, that a requirement a developer could make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (1)
- examples/avail/run.py (1 hunks)
Additional comments: 2
examples/avail/run.py (2)
43-44: The
AvailabilityResponse
class is well-defined for encapsulating availability data.47-59: The
prepare_dates
function correctly generates a string representation of the next 7 days.
class DateRange(BaseModel): | ||
explain: str = Field( | ||
..., | ||
description="Explain the date range in the context of the text before generating the date range and the repeat pattern.", | ||
) | ||
repeats: Literal["daily", "weekly", "monthly", None] = Field( | ||
default=None, | ||
description="If the date range repeats, and how often, this way we can generalize the date range to the future., if its special, then we can assume it is a one time event.", | ||
) | ||
days_of_week: List[ | ||
Literal[ | ||
"monday", | ||
"tuesday", | ||
"wednesday", | ||
"thursday", | ||
"friday", | ||
"saturday", | ||
"sunday", | ||
None, | ||
] | ||
] = Field( | ||
..., | ||
description="If the date range repeats, which days of the week does it repeat on.", | ||
) | ||
time_start: datetime = Field( | ||
description="The start of the first time range in the day." | ||
) | ||
time_end: datetime = Field( | ||
description="The end of the first time range in the day." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a timezone field to the DateRange
class to handle different time zones, as previously discussed in the comments.
class DateRange(BaseModel):
# ... existing fields ...
+ timezone: str = Field(
+ default="UTC",
+ description="Timezone for the start and end times of the date range."
+ )
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
class DateRange(BaseModel): | |
explain: str = Field( | |
..., | |
description="Explain the date range in the context of the text before generating the date range and the repeat pattern.", | |
) | |
repeats: Literal["daily", "weekly", "monthly", None] = Field( | |
default=None, | |
description="If the date range repeats, and how often, this way we can generalize the date range to the future., if its special, then we can assume it is a one time event.", | |
) | |
days_of_week: List[ | |
Literal[ | |
"monday", | |
"tuesday", | |
"wednesday", | |
"thursday", | |
"friday", | |
"saturday", | |
"sunday", | |
None, | |
] | |
] = Field( | |
..., | |
description="If the date range repeats, which days of the week does it repeat on.", | |
) | |
time_start: datetime = Field( | |
description="The start of the first time range in the day." | |
) | |
time_end: datetime = Field( | |
description="The end of the first time range in the day." | |
) | |
class DateRange(BaseModel): | |
explain: str = Field( | |
..., | |
description="Explain the date range in the context of the text before generating the date range and the repeat pattern.", | |
) | |
repeats: Literal["daily", "weekly", "monthly", None] = Field( | |
default=None, | |
description="If the date range repeats, and how often, this way we can generalize the date range to the future., if its special, then we can assume it is a one time event.", | |
) | |
days_of_week: List[ | |
Literal[ | |
"monday", | |
"tuesday", | |
"wednesday", | |
"thursday", | |
"friday", | |
"saturday", | |
"sunday", | |
None, | |
] | |
] = Field( | |
..., | |
description="If the date range repeats, which days of the week does it repeat on.", | |
) | |
time_start: datetime = Field( | |
description="The start of the first time range in the day." | |
) | |
time_end: datetime = Field( | |
description="The end of the first time range in the day." | |
) | |
timezone: str = Field( | |
default="UTC", | |
description="Timezone for the start and end times of the date range." | |
) |
def parse_availability(text: str) -> Iterable[AvailabilityResponse]: | ||
return client.chat.completions.create( | ||
model="gpt-4-1106-preview", | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content": "You are a state of the art date range parse designed to correctly extract availabilities.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": text, | ||
}, | ||
{ | ||
"role": "user", | ||
"content": f"To help you understand the dates, here are the next 7 days: {prepare_dates()}", | ||
}, | ||
], | ||
response_model=Iterable[AvailabilityResponse], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response_model
parameter in the parse_availability
function call is still present and should be removed or corrected to match the API's expected parameters.
def parse_availability(text: str) -> Iterable[AvailabilityResponse]:
return client.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
# ... existing message content ...
],
- response_model=Iterable[AvailabilityResponse],
)
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def parse_availability(text: str) -> Iterable[AvailabilityResponse]: | |
return client.chat.completions.create( | |
model="gpt-4-1106-preview", | |
messages=[ | |
{ | |
"role": "system", | |
"content": "You are a state of the art date range parse designed to correctly extract availabilities.", | |
}, | |
{ | |
"role": "user", | |
"content": text, | |
}, | |
{ | |
"role": "user", | |
"content": f"To help you understand the dates, here are the next 7 days: {prepare_dates()}", | |
}, | |
], | |
response_model=Iterable[AvailabilityResponse], | |
) | |
def parse_availability(text: str) -> Iterable[AvailabilityResponse]: | |
return client.chat.completions.create( | |
model="gpt-4-1106-preview", | |
messages=[ | |
{ | |
"role": "system", | |
"content": "You are a state of the art date range parse designed to correctly extract availabilities.", | |
}, | |
{ | |
"role": "user", | |
"content": text, | |
}, | |
{ | |
"role": "user", | |
"content": f"To help you understand the dates, here are the next 7 days: {prepare_dates()}", | |
}, | |
], | |
) |
The parse_availability
function should include logic to process the API response and convert it into AvailabilityResponse
objects, as the direct API call return value likely does not match the expected return type.
""" | ||
schedules = parse_availability(text) | ||
for schedule in schedules: | ||
print(schedule.model_dump_json(indent=2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the non-existent model_dump_json
method with the correct json()
method to serialize Pydantic models.
for schedule in schedules:
- print(schedule.model_dump_json(indent=2))
+ print(schedule.json(indent=2))
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
print(schedule.model_dump_json(indent=2)) | |
print(schedule.json(indent=2)) |
Summary by CodeRabbit
New Features
Improvements