mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
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>
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from typing import cast
|
||||
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
@@ -61,9 +60,12 @@ class GeminiEmbeddingProvider(EmbeddingProvider):
|
||||
async def get_embeddings(self, text: list[str]) -> list[list[float]]:
|
||||
"""批量获取文本的嵌入"""
|
||||
try:
|
||||
contents = [
|
||||
types.Content(parts=[types.Part.from_text(text=s)]) for s in text
|
||||
]
|
||||
result = await self.client.models.embed_content(
|
||||
model=self.model,
|
||||
contents=cast(types.ContentListUnion, text),
|
||||
contents=contents,
|
||||
config=types.EmbedContentConfig(
|
||||
output_dimensionality=self.get_dim(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user