Skip to content

Commit f01dc47

Browse files
Rat0323Soulter
andauthored
fix(gemini-embedding): wrap batch embedding texts in Content to avoid collapse on gemini-embedding-2 (#8537)
* fix(provider): wrap batch embedding texts in Content to avoid collapse on gemini-embedding-2 * fix(gemini_embedding): format list comprehension for better readability --------- Co-authored-by: Rat0323 <Rat0323@users.noreply.github.com> Co-authored-by: Soulter <905617992@qq.com>
1 parent 0726918 commit f01dc47

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

astrbot/core/provider/sources/gemini_embedding_source.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import cast
21

32
from google import genai
43
from google.genai import types
@@ -61,9 +60,12 @@ async def get_embedding(self, text: str) -> list[float]:
6160
async def get_embeddings(self, text: list[str]) -> list[list[float]]:
6261
"""批量获取文本的嵌入"""
6362
try:
63+
contents = [
64+
types.Content(parts=[types.Part.from_text(text=s)]) for s in text
65+
]
6466
result = await self.client.models.embed_content(
6567
model=self.model,
66-
contents=cast(types.ContentListUnion, text),
68+
contents=contents,
6769
config=types.EmbedContentConfig(
6870
output_dimensionality=self.get_dim(),
6971
),

0 commit comments

Comments
 (0)