Skip to content

feat: implement DeepsetClient for API communication#11

Closed
mathislucka wants to merge 61 commits into
mainfrom
fix-issue-10
Closed

feat: implement DeepsetClient for API communication#11
mathislucka wants to merge 61 commits into
mainfrom
fix-issue-10

Conversation

@mathislucka
Copy link
Copy Markdown
Contributor

Overview

This PR implements a DeepsetClient class to handle all API communication with the deepset Cloud API. The client provides a more structured, testable, and maintainable approach to API interactions.

Changes

  1. Created a new DeepsetClient class with the following features:

    • Async implementation with context manager support (async with DeepsetClient() as client)
    • Dependency injection for testing via the HttpClient protocol
    • Consistent error handling and response processing
    • Methods that map to API endpoints used in the application
  2. Updated main.py to use the new client:

    • Added helper function to run async code in sync context (async_to_sync decorator)
    • Migrated all API request functions to use the new client
    • Updated tool functions to be async and use the client
  3. Added tests:

    • Unit tests for the DeepsetClient class
    • Updated existing tests to work with the async client
  4. Updated dependencies:

    • Added httpx for modern async HTTP requests
    • Added typing-extensions for Python 3.11 compatibility with Self

Implementation Details

  • The DeepsetClient implements the AsyncContextManager protocol to properly handle client resources
  • A thin HTTP client abstraction enables dependency injection for testing
  • All original functionality is preserved with improved testability
  • Error handling is consistent across all endpoints

Testing Considerations

  • Unit tests verify the client can be used with environment variables or explicit parameters
  • Tests check error handling for missing credentials
  • Mocks verify that requests are made with correct endpoints and parameters

Next Steps

Future PRs could enhance this implementation by:

  1. Adding specific models for API responses
  2. Creating resource-specific classes like PipelineResource
  3. Introducing proper API exception hierarchy
  4. Adding more comprehensive error handling and retries

Closes #10

mathislucka added 30 commits May 6, 2025 15:52
mathislucka added 28 commits May 6, 2025 15:58
@mathislucka mathislucka deleted the fix-issue-10 branch May 12, 2025 10:09
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.

Introduce DeepsetAPIClient

1 participant