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

Parse availability of dates #267

Merged
merged 9 commits into from
Dec 11, 2023
Merged

Parse availability of dates #267

merged 9 commits into from
Dec 11, 2023

Conversation

jxnl
Copy link
Owner

@jxnl jxnl commented Dec 10, 2023

Summary by CodeRabbit

  • New Features

    • Introduced a new date range selection tool for easier scheduling.
    • Enhanced availability responses to provide clearer information.
  • Improvements

    • Improved date preparation process for more accurate scheduling.
    • Upgraded availability parsing to utilize advanced AI technology for better accuracy.

Copy link
Contributor

coderabbitai bot commented Dec 10, 2023

Walkthrough

The update introduces two new classes, DateRange and AvailabilityResponse, to handle scheduling and availability data. It also adds a prepare_dates function for date generation and modifies the parse_availability function to interact with an external AI API, enhancing the system's ability to process and understand availability information.

Changes

File Change Summary
examples/avail/run.py Introduced DateRange and AvailabilityResponse classes; added prepare_dates function; modified parse_availability function to use AI API.

🐇✨
To code is to weave a brand new tale,
Classes and functions in harmony sail.
With AI's might, we parse the day,
In the burrow of bytes, we find our way. 🌟📅

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 ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 941f100 and 27e28f4.
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 parameter n=7. Ensure this is the intended behavior and that the function is flexible enough for different use cases.

Comment on lines 11 to 16
class DateRange(BaseModel):
explination: str = Field(
..., description="Explination of the date range in the context of the text"
)
start: datetime
end: datetime
Copy link
Contributor

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.

Suggested change
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

Comment on lines 69 to 119
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",
},
]
Copy link
Contributor

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.

Suggested change
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))

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 27e28f4 and 2f691d5.
Files selected for processing (1)
  • examples/avail/run.py (1 hunks)



class DateRange(BaseModel):
explain: str = Field(
Copy link

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?

Copy link
Owner Author

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 601d0b2 and b05ce18.
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.

Comment on lines +11 to +40
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."
)
Copy link
Contributor

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.

Suggested change
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."
)

Comment on lines +62 to +80
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],
)
Copy link
Contributor

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.

Suggested change
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))
Copy link
Contributor

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.

Suggested change
print(schedule.model_dump_json(indent=2))
print(schedule.json(indent=2))

@jxnl jxnl merged commit d3c1396 into main Dec 11, 2023
11 checks passed
@jxnl jxnl deleted the parse-avail branch December 11, 2023 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants