Update backend/gemini/client.py
Browse files- backend/gemini/client.py +16 -6
backend/gemini/client.py
CHANGED
|
@@ -112,7 +112,7 @@ class GeminiConnection:
|
|
| 112 |
await self._receive_queue.put(None)
|
| 113 |
|
| 114 |
async def send_audio(self, data: str) -> None:
|
| 115 |
-
"""Send audio data to Gemini
|
| 116 |
if not self.session:
|
| 117 |
print(f"[DEBUG][{self.client_id}] ❌ Cannot send audio: no session")
|
| 118 |
return
|
|
@@ -120,8 +120,13 @@ class GeminiConnection:
|
|
| 120 |
# Decode base64 string to bytes
|
| 121 |
audio_bytes = base64.b64decode(data) if isinstance(data, str) else data
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
except Exception as e:
|
| 126 |
print(f"[DEBUG][{self.client_id}] Send audio error: {e}")
|
| 127 |
|
|
@@ -139,7 +144,7 @@ class GeminiConnection:
|
|
| 139 |
print(f"[DEBUG][{self.client_id}] Send text error: {e}")
|
| 140 |
|
| 141 |
async def send_image(self, data: str) -> None:
|
| 142 |
-
"""Send image data to Gemini
|
| 143 |
if not self.session:
|
| 144 |
print(f"[DEBUG][{self.client_id}] ❌ Cannot send image: no session")
|
| 145 |
return
|
|
@@ -147,8 +152,13 @@ class GeminiConnection:
|
|
| 147 |
# Decode base64 string to bytes
|
| 148 |
image_bytes = base64.b64decode(data) if isinstance(data, str) else data
|
| 149 |
|
| 150 |
-
#
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
except Exception as e:
|
| 153 |
print(f"[DEBUG][{self.client_id}] Send image error: {e}")
|
| 154 |
|
|
|
|
| 112 |
await self._receive_queue.put(None)
|
| 113 |
|
| 114 |
async def send_audio(self, data: str) -> None:
|
| 115 |
+
"""Send audio data to Gemini using Blob object"""
|
| 116 |
if not self.session:
|
| 117 |
print(f"[DEBUG][{self.client_id}] ❌ Cannot send audio: no session")
|
| 118 |
return
|
|
|
|
| 120 |
# Decode base64 string to bytes
|
| 121 |
audio_bytes = base64.b64decode(data) if isinstance(data, str) else data
|
| 122 |
|
| 123 |
+
# Create Blob with proper MIME type
|
| 124 |
+
audio_blob = types.Blob(
|
| 125 |
+
data=audio_bytes,
|
| 126 |
+
mime_type="audio/pcm"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
await self.session.send_realtime_input(audio=audio_blob)
|
| 130 |
except Exception as e:
|
| 131 |
print(f"[DEBUG][{self.client_id}] Send audio error: {e}")
|
| 132 |
|
|
|
|
| 144 |
print(f"[DEBUG][{self.client_id}] Send text error: {e}")
|
| 145 |
|
| 146 |
async def send_image(self, data: str) -> None:
|
| 147 |
+
"""Send image data to Gemini using Blob object"""
|
| 148 |
if not self.session:
|
| 149 |
print(f"[DEBUG][{self.client_id}] ❌ Cannot send image: no session")
|
| 150 |
return
|
|
|
|
| 152 |
# Decode base64 string to bytes
|
| 153 |
image_bytes = base64.b64decode(data) if isinstance(data, str) else data
|
| 154 |
|
| 155 |
+
# Create Blob with proper MIME type
|
| 156 |
+
image_blob = types.Blob(
|
| 157 |
+
data=image_bytes,
|
| 158 |
+
mime_type="image/jpeg"
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
await self.session.send_realtime_input(video=image_blob)
|
| 162 |
except Exception as e:
|
| 163 |
print(f"[DEBUG][{self.client_id}] Send image error: {e}")
|
| 164 |
|