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

Customizable Timeout for API Requests #11

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Customizable Timeout for API Requests #11

merged 2 commits into from
Dec 4, 2024

Conversation

kladaFOX
Copy link
Contributor

@kladaFOX kladaFOX commented Dec 4, 2024

New Features:

  • Customizable Timeout for API Requests
  • Introduced DEFAULT_TIMEOUT constant (set to 60 seconds) for managing request timeouts across the Completions and Embeddings classes.
  • Added optional arguments (args) to create methods, allowing users to override read_timeout and open_timeout dynamically.
  • This change ensures greater flexibility when dealing with varying network conditions or API response times.

Example Usage:

Spectre::Openai::Completions.create(
  messages: messages,
  read_timeout: 30,
  open_timeout: 20
)

Key Changes:

  • Updated Completions class:
    • http.read_timeout = args.fetch(:read_timeout, DEFAULT_TIMEOUT)
    • http.open_timeout = args.fetch(:open_timeout, DEFAULT_TIMEOUT)
    • Updated Embeddings class with the same timeout handling logic.

Fixes:

  • Simplified Exception Handling for Timeouts
  • Removed explicit handling of Net::OpenTimeout and Net::ReadTimeout exceptions in both Completions and Embeddings classes.
  • Letting these exceptions propagate ensures clearer and more consistent error messages for timeout issues.

@kladaFOX kladaFOX self-assigned this Dec 4, 2024
Copy link
Member

@matthewblack matthewblack left a comment

Choose a reason for hiding this comment

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

Awesome. 🤙

@kladaFOX kladaFOX merged commit bed072e into main Dec 4, 2024
1 check passed
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