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

Adding support for O1 #991

Merged
merged 2 commits into from
Sep 13, 2024
Merged

Adding support for O1 #991

merged 2 commits into from
Sep 13, 2024

Conversation

ivanleomk
Copy link
Collaborator

@ivanleomk ivanleomk commented Sep 13, 2024

This adds a new mode which should support the o1 model family using the openai client sdk. We'll need to upgrade the supported version to support the new max_completion_tokens parameter though. This allows us to do something like what we see below.

from instructor import from_openai, Mode
from openai import OpenAI
from pydantic import BaseModel

client = from_openai(OpenAI(), mode=Mode.JSON_O1)


class UserDetails(BaseModel):
    name: str
    age: int


resp = client.chat.completions.create(
    model="o1-mini",
    messages=[{"role": "user", "content": "Jason is 10"}],
    response_model=UserDetails,
    max_completion_tokens=300, # This has to have a minimum of 200+ because of reasoning tokens
)

print(resp)

🚀 This description was created by Ellipsis for commit f35b04c

feat: add support for JSON_O1 mode with OpenAI SDK

Summary:

Adds support for JSON_O1 mode using the OpenAI client SDK, requiring an updated openai dependency.

Key points:

  • Behavior:
    • Adds support for JSON_O1 mode in from_openai() in client.py.
    • Updates handle_response_model() in process_response.py to handle JSON_O1 mode, ensuring no system messages are included.
    • Updates from_response() in function_calls.py to parse JSON_O1 mode using parse_json().
  • Dependencies:
    • Updates openai dependency to ^1.45.0 in pyproject.toml to support max_completion_tokens.
  • Enums:
    • Adds JSON_O1 to Mode enum in mode.py.

Generated with ❤️ by ellipsis.dev

@ivanleomk ivanleomk requested a review from jxnl September 13, 2024 04:57
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to f35b04c in 25 seconds

More details
  • Looked at 89 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. instructor/client.py:426
  • Draft comment:
    Consider adding specific handling for Mode.JSON_O1 in the from_openai function if it requires special processing, similar to other modes like MD_JSON or TOOLS_STRICT.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a new mode JSON_O1 but does not update the from_openai function to handle this mode specifically. This could lead to unexpected behavior if the mode requires special handling.
2. instructor/process_response.py:263
  • Draft comment:
    Ensure that Mode.JSON_O1 is handled correctly in handle_response_model. The current implementation seems to append a message to new_kwargs["messages"], but verify if additional handling is needed.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new mode JSON_O1 but does not update the handle_response_model function to handle this mode specifically. This could lead to unexpected behavior if the mode requires special handling.

Workflow ID: wflow_YHsDjroDOx3yW1gZ


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

cloudflare-workers-and-pages bot commented Sep 13, 2024

Deploying instructor with  Cloudflare Pages  Cloudflare Pages

Latest commit: ee1c5af
Status: ✅  Deploy successful!
Preview URL: https://e0dd1e53.instructor.pages.dev
Branch Preview URL: https://support-o1.instructor.pages.dev

View logs

Copy link
Contributor

ellipsis-dev bot commented Sep 13, 2024

Skipped PR review on ee1c5af because no changed files had a supported extension. If you think this was in error, please contact us and we'll fix it right away.


Generated with ❤️ by ellipsis.dev

@ivanleomk
Copy link
Collaborator Author

Important here to note that the current o1-preview doesn't support things like tool-calling, streaming and so this is really just supporting a simple json mode support

@ivanleomk ivanleomk merged commit 8362181 into main Sep 13, 2024
14 of 15 checks passed
@ivanleomk ivanleomk deleted the support-o1 branch September 13, 2024 15:38
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