Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
feat(ollama): update the ollama embedding API (#874)
qbc5f62604c8c56
diff --git a/pyproject.toml b/pyproject.tomlindex abfe2c924..24635a5ce 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -42,7 +42,7 @@ dependencies = [[project.optional-dependencies]full = [# Model- "ollama",+ "ollama>=0.5.4","google-genai","Pillow","transformers",diff --git a/src/agentscope/embedding/_ollama_embedding.py b/src/agentscope/embedding/_ollama_embedding.pyindex f5445072b..fc3a94892 100644--- a/src/agentscope/embedding/_ollama_embedding.py+++ b/src/agentscope/embedding/_ollama_embedding.py@@ -1,6 +1,5 @@# -*- coding: utf-8 -*-"""The ollama text embedding model class."""-import asynciofrom datetime import datetimefrom typing import List, Any@@ -68,6 +67,13 @@ class OllamaTextEmbedding(EmbeddingModelBase):"Input text must be a list of strings or TextBlock dicts.",)+ kwargs = {+ "input": gather_text,+ "model": self.model_name,+ "dimensions": self.dimensions,+ **kwargs,+ }+if self.embedding_cache:cached_embeddings = await self.embedding_cache.retrieve(identifier=kwargs,@@ -83,22 +89,17 @@ class OllamaTextEmbedding(EmbeddingModelBase):)start_time = datetime.now()- response = await asyncio.gather(- *[- self.client.embeddings(self.model_name, _, **kwargs)- for _ in gather_text- ],- )+ response = await self.client.embed(**kwargs)time = (datetime.now() - start_time).total_seconds()if self.embedding_cache:await self.embedding_cache.store(identifier=kwargs,- embeddings=[_.embedding for _ in response],+ embeddings=response.embeddings,)return EmbeddingResponse(- embeddings=[_.embedding for _ in response],+ embeddings=response.embeddings,usage=EmbeddingUsage(time=time,),