Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
the-praxs committed Jan 18, 2025
1 parent 392677a commit 38e2621
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions agentops/llms/providers/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from agentops.log_config import logger
from agentops.singleton import singleton


@singleton
class GeminiProvider(BaseProvider):
original_generate_content = None
Expand All @@ -27,9 +28,7 @@ def __init__(self, client=None):
super().__init__(client)
self._provider_name = "Gemini"

def handle_response(
self, response, kwargs, init_timestamp, session: Optional[Session] = None
) -> dict:
def handle_response(self, response, kwargs, init_timestamp, session: Optional[Session] = None) -> dict:
"""Handle responses from Gemini API for both sync and streaming modes.
Args:
Expand All @@ -45,7 +44,7 @@ def handle_response(
llm_event = LLMEvent(init_timestamp=init_timestamp, params=kwargs)
if session is not None:
llm_event.session_id = session.session_id

accumulated_content = ""

def handle_stream_chunk(chunk):
Expand Down Expand Up @@ -82,10 +81,12 @@ def handle_stream_chunk(chunk):

# For streaming responses
if kwargs.get("stream", False):

def generator():
for chunk in response:
handle_stream_chunk(chunk)
yield chunk

return generator()

# For synchronous responses
Expand Down Expand Up @@ -190,4 +191,4 @@ def undo_override(self):

if self.original_generate_content_async is not None:
genai.GenerativeModel.generate_content_async = self.original_generate_content_async
self.original_generate_content_async = None
self.original_generate_content_async = None

0 comments on commit 38e2621

Please sign in to comment.