Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fishjam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# pylint: disable=locally-disabled, no-name-in-module, import-error

# Exceptions and Server Messages
from fishjam import agent, errors, events, peer, room
from fishjam import agent, errors, events, peer, room, version
from fishjam._openapi_client.models import PeerMetadata

# API
Expand All @@ -24,6 +24,8 @@
RoomOptions,
)

__version__ = version.__version__

__all__ = [
"FishjamClient",
"FishjamNotifier",
Expand Down
Empty file.
77 changes: 77 additions & 0 deletions fishjam/integrations/gemini.py
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]: ...


@_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(
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:
return AgentOutputOptions(
audio_format="pcm16",
audio_sample_rate=16_000,
)


GeminiIntegration = _GeminiIntegration()
7 changes: 7 additions & 0 deletions fishjam/version.py
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__
12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ generate_docusaurus = "scripts:generate_docusaurus"
update_client = "scripts:update_client"
room_manager = "scripts:start_room_manager"

[project.optional-dependencies]
gemini = ["google-genai>=1.43.0"]

[dependency-groups]
dev = [
"betterproto[compiler]== 2.0.0b6",
Expand All @@ -55,7 +58,12 @@ test = [
default-groups = ["dev", "test"]

[tool.uv.workspace]
members = ["examples/transcription", ".", "examples/poet_chat", "examples/selective_subscription"]
members = [
"examples/transcription",
".",
"examples/poet_chat",
"examples/selective_subscription",
]

[tool.hatch.build.targets.sdist]
include = ["fishjam"]
Expand Down Expand Up @@ -86,8 +94,6 @@ convention = "google"
"scripts.py" = ["D"]




[tool.pytest.ini_options]
markers = [
"file_component_sources: Tests requiring files uploaded for File Component",
Expand Down
7 changes: 7 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.