Skip to content

fix gemini live update chatcontext #2057

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jayeshp19
Copy link
Contributor

No description provided.

Copy link
Contributor

⚠️ Changeset Required

We detected changes in the following package(s) but no changeset file was found. Please add one for proper versioning:

  • livekit-agents
  • livekit-plugins-google
  • livekit-plugins-openai
  • livekit-plugins-speechify

👉 Create a changeset file by clicking here.

@@ -418,6 +434,15 @@ async def _main_task(self):
async with self._session_lock:
self._session = session

# for reconnect, send the updated chat context
if self._chat_ctx:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're reconnecting while calling update_chat_ctx we need to send updated context.
this will resend chat context once for normal cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any synchronization if we're calling update_chat_ctx & the reconnection is happening? How do we know it'll not race and send two times?

Comment on lines -158 to -170
if not gcp_project or not gcp_location:
raise ValueError(
"Project and location are required for VertexAI either via project and location or GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables" # noqa: E501
)
gemini_api_key = None # VertexAI does not require an API key

if not (gcp_project and gcp_location):
raise ValueError("Project and location required for VertexAI")
gemini_api_key = None
else:
if not gemini_api_key:
raise ValueError("API key required for Google API")
gcp_project = None
gcp_location = None
if not gemini_api_key:
raise ValueError(
"API key is required for Google API either via api_key or GOOGLE_API_KEY environment variable" # noqa: E501
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the messages where better before?

diff = llm.utils.compute_chat_ctx_diff(self._chat_ctx, chat_ctx)
if diff.to_remove:
self._chat_ctx = chat_ctx
self.reset_gemini_session()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to reconnect, but ideally, we use aiohttp with a connection pool

@@ -602,10 +625,14 @@ def _handle_go_away(self, go_away: LiveServerGoAway):
)

def commit_audio(self) -> None:
raise NotImplementedError("commit_audio_buffer is not supported yet")
raise NotImplementedError("commit_audio is not supported yet")

def clear_audio(self) -> None:
raise NotImplementedError("clear_audio is not supported yet")

def server_vad_enabled(self) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was there before, but I believe this fnc is unused

@@ -258,6 +255,11 @@ async def _close_gemini_session(self) -> None:
finally:
self._session = None

def reset_gemini_session(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it private

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.

2 participants