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 google #37

Merged
merged 7 commits into from
May 31, 2024
Merged

Conversation

dockhardman
Copy link
Owner

OpenAI Plugin Clients

  • Added a new GoogleOpenAI client that wraps the Google GenAI API to provide an interface similar to the OpenAI API
    • Implemented GoogleChatCompletions for creating chat completions and streaming chat completion chunks
    • Implemented GoogleModels for retrieving and listing available models
    • Implemented GoogleEmbeddings for creating embeddings
  • Added utility functions in languru/openai_plugins/clients/utils.py for OpenAI client initialization parameters

Utilities

  • Added languru/utils/openai_utils.py with a helper function rand_chat_completion_id() to generate random chat completion IDs
  • Added languru/utils/prompt.py with a helper function ensure_chat_completion_message_params() to validate chat completion message parameters
  • Added languru/utils/sse.py with a helper function simple_encode_sse() for simple Server-Sent Events (SSE) encoding

Tests

  • Added tests for the new GoogleOpenAI client in tests/openai_plugins/test_google_openai.py
    • Test cases for creating chat completions, streaming chat completions, retrieving models, listing models, and creating embeddings
  • Added a test for the simple_encode_sse() utility function in tests/utils/test_sse.py

**google.py**

*   Added `generation_config` parameter when calling `chat_session.send_message()` to allow setting the temperature.

**test_google_openai.py**

*   Included a test case for Google Chat Completions that sets the temperature.
…ts encoding

The simple_encode_sse function supports encoding bytes, text, Pydantic models,
dictionaries, and lists into the SSE format. It handles unknown data types
gracefully by encoding them as strings with a warning log.

Add tests/utils/test_sse.py with test cases for simple_encode_sse

The test cases cover encoding bytes, text, dictionaries, lists, and Pydantic
models, ensuring the correctness of the simple_encode_sse function.
- Add `stream` method to `GoogleChatCompletions` class
  - Validate `messages` input
  - Convert messages to Google PaLM API format
  - Start chat session and send latest message
  - Return a streaming response of `ChatCompletionChunk`s
- Add `generator_generate_content_chunks` method to generate chat completion chunks
  - Yield chunks for each generated content part
  - Yield final chunk with `finish_reason`
  - End the stream
- Add `rand_chat_completion_id` utility function to generate random chat completion IDs
- Add new test `test_google_openai_chat_completion_create_stream` to verify streaming functionality
- Import `Stream` and `ChatCompletionChunk` types for type hinting and casting
- Iterate over the stream, checking for `finish_reason` and `delta.content` in the response
- Add GoogleModels class to support retrieving and listing Google models
- Implement GoogleModels.retrieve() to get a specific model by name
- Implement GoogleModels.list() to list all available Google models
- Add GoogleModels to the GoogleOpenAI class
- Add tests for GoogleModels.retrieve() and GoogleModels.list()
- Handle GoogleNotFound exception in GoogleModels.retrieve()
- Rename test methods for consistency
- Add GoogleEmbeddings class to handle embeddings API requests
- Implement create() method in GoogleEmbeddings to call genai.embed_content()
- Add embeddings attribute to GoogleOpenAI class
- Add test case for GoogleOpenAI embeddings create API
Copy link

codecov bot commented May 31, 2024

Codecov Report

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

Project coverage is 79.20%. Comparing base (a8d9cd9) to head (9b0c2c5).
Report is 1 commits behind head on master.

Files Patch % Lines
languru/openai_plugins/clients/google.py 91.80% 5 Missing ⚠️
languru/utils/sse.py 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
+ Coverage   78.81%   79.20%   +0.38%     
==========================================
  Files          67       69       +2     
  Lines        2998     3078      +80     
==========================================
+ Hits         2363     2438      +75     
- Misses        635      640       +5     

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

@dockhardman dockhardman merged commit c6c6040 into master May 31, 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