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

Feature/openai plugins anthropic #39

Merged
merged 7 commits into from
Jun 2, 2024

Conversation

dockhardman
Copy link
Owner

Anthropic API Client

  • Added a new AnthropicOpenAI client class that integrates with the Anthropic API to access Claude models
  • Implemented AnthropicChatCompletions class to support chat completions and streaming with Anthropic models
  • Added AnthropicChat and AnthropicModels classes to provide a consistent interface with the OpenAI API
  • Introduced AnthropicChatCompletionRequest type to convert OpenAI chat completion requests to the Anthropic format

Google GenAI and Perplexity API Clients

  • Updated the Google GenAI and Perplexity API clients to fall back to the OPENAI_API_KEY environment variable if their specific API key env vars are not set
  • Improved docstrings for the generator_generate_content_chunks method in the Google GenAI client

Tests

  • Added tests for the new AnthropicOpenAI client, covering model retrieval, listing, and chat completions (both regular and streaming)
  • Renamed test methods for the Perplexity API client to use the correct prefix (test_pplx_openai instead of test_google_openai)

- Add OPENAI_API_KEY as a fallback API key for GoogleOpenAI and PerplexityOpenAI clients
- This allows using the OPENAI_API_KEY env var if provider-specific env vars are not set
- Improves flexibility and ease of configuration for users of these OpenAI client classes
- Add `AnthropicChatCompletions` class to support chat completions using Anthropic API
  - Implement `create` and `_create_stream` methods (streaming not supported)
  - Validate `messages` parameter is non-empty
- Add `AnthropicChat` class extending `OpenAIResources.Chat`
  - Use `AnthropicChatCompletions` for chat completions
- Add `AnthropicModels` class extending `OpenAIResources.Models`
  - Support retrieving and listing a fixed set of Anthropic models
- Add top-level `AnthropicOpenAI` class
  - Initialize `AnthropicChat` and `AnthropicModels`
  - Require Anthropic API key
- Add tests for retrieving and listing Anthropic models
- Rename test_google_openai_chat_completions_create to test_pplx_openai_chat_completions_create
- Rename test_google_openai_chat_completions_create_stream to test_pplx_openai_chat_completions_create_stream
- Rename test_google_openai_models_retrieve to test_pplx_openai_models_retrieve
- Rename test_google_openai_models_list to test_pplx_openai_models_list
- Remove unused imports (uuid, google.generativeai, GoogleNotFound, generation_types, ContentDict)
- Add imports for Anthropic API (AnthropicMessageStream, AnthropicChatCompletionRequest)
- Update AnthropicChatCompletions to use Anthropic API for create and _create_stream methods
  - Convert OpenAI chat completion request to Anthropic request format
  - Send request using Anthropic client and process response
  - Stream response using generator_generate_content_chunks method
- Add anthropic_client attribute to AnthropicOpenAI class
- Update AnthropicChatCompletionRequest to convert from OpenAI to Anthropic format
  - Handle system, user, and assistant roles
  - Set default max_tokens, temperature, and stream values
- Import necessary types: Stream, ChatCompletion, ChatCompletionChunk
- Import ensure_chat_completion_message_params utility function
- Add test_claude_openai_chat_completions_create to test creating a chat completion
  - Use ensure_chat_completion_message_params to format messages
  - Specify test_chat_model_name and temperature
  - Assert the response contains choices with a message
- Add commented out test_claude_openai_chat_completions_create_stream (WIP) to test streaming chat completions
- Refactor `AnthropicChatCompletions.create` to extract the message stream from the context manager
- Add docstring for `generator_generate_content_chunks` method
- Enable and fix test for chat completion streaming
…nks method

The generate_chat_completion_response_chunks method in the GoogleChatCompletions class now has a detailed docstring explaining its parameters, return value, and functionality. This improves code readability and maintainability.
Copy link

codecov bot commented Jun 2, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 79.52%. Comparing base (497ebc8) to head (f1e108c).

Files Patch % Lines
languru/openai_plugins/clients/anthropic.py 88.67% 12 Missing ⚠️
languru/types/chat/anthropic.py 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
+ Coverage   79.33%   79.52%   +0.18%     
==========================================
  Files          70       71       +1     
  Lines        3112     3213     +101     
==========================================
+ Hits         2469     2555      +86     
- Misses        643      658      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dockhardman dockhardman merged commit 40e1403 into master Jun 2, 2024
3 checks 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.

None yet

1 participant