Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(ollama): create embedding client per call to avoid event loop binding issues (#1836)
DavdGao0f4961ad78e4
diff --git a/src/agentscope/embedding/_ollama_embedding.py b/src/agentscope/embedding/_ollama_embedding.pyindex fc3a94892..fbc080185 100644--- a/src/agentscope/embedding/_ollama_embedding.py+++ b/src/agentscope/embedding/_ollama_embedding.py@@ -38,11 +38,10 @@ class OllamaTextEmbedding(EmbeddingModelBase):The embedding cache class instance, used to cache theembedding results to avoid repeated API calls."""- import ollama-super().__init__(model_name, dimensions)- self.client = ollama.AsyncClient(host=host, **kwargs)+ self.host = host+ self.client_kwargs = kwargsself.embedding_cache = embedding_cacheasync def __call__(@@ -88,8 +87,15 @@ class OllamaTextEmbedding(EmbeddingModelBase):source="cache",)+ import ollama++ client = ollama.AsyncClient(+ host=self.host,+ **self.client_kwargs,+ )+start_time = datetime.now()- response = await self.client.embed(**kwargs)+ response = await client.embed(**kwargs)time = (datetime.now() - start_time).total_seconds()if self.embedding_cache: