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

feat: Add support for perplexity sonar #1319

Merged
merged 7 commits into from
Mar 3, 2025
Merged

Conversation

charlieyou
Copy link
Contributor

@charlieyou charlieyou commented Jan 25, 2025

Perplexity released their Sonar API with structured outputs which is not compatible with any of the existing function calling methods currently implemented. Rest of the API is similar to OpenAI.

See references:

Implemented it with a new client, but don't have a strong opinion on keeping it vs only keeping the new mode.


Important

Add support for Perplexity Sonar API with new client and mode, including JSON handling and tests.

  • Behavior:
    • Add support for Perplexity Sonar API with new client from_perplexity in client_perplexity.py.
    • Introduce PERPLEXITY_JSON mode in mode.py for handling structured outputs.
    • Update process_response.py and reask.py to handle PERPLEXITY_JSON mode.
  • Functions:
    • Add handle_perplexity_json() in process_response.py for processing JSON responses.
    • Add reask_perplexity_json() in reask.py for reasking logic.
  • Tests:
    • Add test_perplexity directory with conftest.py and test_modes.py for testing Perplexity integration.
    • Define test models and modes in util.py.

This description was created by Ellipsis for 73a9061. It will automatically update as commits are pushed.

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 73a9061 in 51 seconds

More details
  • Looked at 415 lines of code in 14 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. instructor/__init__.py:102
  • Draft comment:
    Add a newline at the end of the file for consistency and to follow best practices.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The code in instructor/__init__.py is missing a newline at the end of the file. This is a minor issue but it's a good practice to have a newline at the end of files.
2. instructor/client_perplexity.py:63
  • Draft comment:
    Add a newline at the end of the file for consistency and to follow best practices.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The code in instructor/client_perplexity.py is missing a newline at the end of the file. This is a minor issue but it's a good practice to have a newline at the end of files.
3. instructor/reask.py:374
  • Draft comment:
    Add a newline at the end of the file for consistency and to follow best practices.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The code in instructor/reask.py is missing a newline at the end of the file. This is a minor issue but it's a good practice to have a newline at the end of files.
4. README.md:298
  • Draft comment:
    If a new md file is created for Perplexity Sonar Models, ensure it's added to mkdocs.yml for documentation purposes.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The new md file for Perplexity Sonar Models should be added to mkdocs.yml for documentation purposes.

Workflow ID: wflow_GOqpyzQWupTnARBD


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

@rooterkyberian
Copy link

this resolves #1005 , but the structured outputs problem has been also discussed here #909

Maybe it would be worth to make it more universal?

BTW, if you add "name" to the json_schema object, then the same mode would also work with nebius API (which also follows OpenAI API but I think for some reason requires "name") https://openai.com/index/introducing-structured-outputs-in-the-api/ .
AFAIK "name' field in "json_schema" should not break perplexity API response.

@jxnl jxnl merged commit 240e405 into instructor-ai:main Mar 3, 2025
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.

3 participants