-
Notifications
You must be signed in to change notification settings - Fork 1
Add Gemini integration with optional dependencies #57
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
59cdb86
Add Gemini integration with optional dependencies
AHGIJMKLKKZNPJKQR d087b13
Change exports
AHGIJMKLKKZNPJKQR 69ad351
Add tests
AHGIJMKLKKZNPJKQR df45a06
Update example
AHGIJMKLKKZNPJKQR 5f34c37
Formatting
AHGIJMKLKKZNPJKQR 00ba8a8
Install extras in tests
AHGIJMKLKKZNPJKQR a30b173
Add mime type
AHGIJMKLKKZNPJKQR a16ea88
Add output settings
AHGIJMKLKKZNPJKQR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| try: | ||
| from google import genai | ||
| from google.auth.credentials import Credentials | ||
| from google.genai import types | ||
| from google.genai.client import DebugConfig | ||
| except ImportError: | ||
| raise ImportError( | ||
| "To use the Fishjam Gemini integration, you need to import the `gemini` extra." | ||
| "Install it with `pip install 'fishjam-server-sdk[gemini]'`" | ||
| ) | ||
|
|
||
| from functools import singledispatch | ||
| from typing import Optional, Union | ||
|
|
||
| from fishjam import AgentOutputOptions | ||
| from fishjam.version import get_version | ||
|
|
||
|
|
||
| def _get_headers(): | ||
| return {"x-goog-api-client": f"fishjam-python-server-sdk/{get_version()}"} | ||
|
|
||
|
|
||
| @singledispatch | ||
| def _add_fishjam_header( | ||
| http_options: Optional[Union[types.HttpOptions, types.HttpOptionsDict]], | ||
| ) -> Union[types.HttpOptions, types.HttpOptionsDict]: ... | ||
|
|
||
|
|
||
AHGIJMKLKKZNPJKQR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @_add_fishjam_header.register | ||
| def _(http_options: types.HttpOptions) -> types.HttpOptions: | ||
| http_options.headers = (http_options.headers or {}) | _get_headers() | ||
| return http_options | ||
|
|
||
|
|
||
| @_add_fishjam_header.register | ||
| def _(http_options: types.HttpOptionsDict) -> types.HttpOptionsDict: | ||
| headers = (http_options.get("headers") or {}) | _get_headers() | ||
| return http_options | {"headers": headers} | ||
|
|
||
|
|
||
| @_add_fishjam_header.register | ||
| def _(_http_options: None) -> types.HttpOptionsDict: | ||
| return {"headers": _get_headers()} | ||
|
|
||
|
|
||
| class _GeminiIntegration: | ||
| def create_client( | ||
AHGIJMKLKKZNPJKQR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self, | ||
| vertexai: Optional[bool] = None, | ||
| api_key: Optional[str] = None, | ||
| credentials: Optional[Credentials] = None, | ||
| project: Optional[str] = None, | ||
| location: Optional[str] = None, | ||
| debug_config: Optional[DebugConfig] = None, | ||
| http_options: Optional[Union[types.HttpOptions, types.HttpOptionsDict]] = None, | ||
| ): | ||
| full_http_options = _add_fishjam_header(http_options) | ||
|
|
||
| return genai.Client( | ||
| vertexai=vertexai, | ||
| api_key=api_key, | ||
| credentials=credentials, | ||
| project=project, | ||
| location=location, | ||
| debug_config=debug_config, | ||
| http_options=full_http_options, | ||
| ) | ||
|
|
||
| @property | ||
| def GeminiInputAudioSettings(self) -> AgentOutputOptions: | ||
AHGIJMKLKKZNPJKQR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return AgentOutputOptions( | ||
| audio_format="pcm16", | ||
| audio_sample_rate=16_000, | ||
| ) | ||
|
|
||
|
|
||
| GeminiIntegration = _GeminiIntegration() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from importlib.metadata import version | ||
|
|
||
| __version__ = version("fishjam-server-sdk") | ||
|
|
||
|
|
||
| def get_version(): | ||
| return __version__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.