From 931f34fccd10a09ddfbe3427adda4bedd4e3af04 Mon Sep 17 00:00:00 2001 From: Mark Backman Date: Sat, 5 Jul 2025 08:12:23 -0700 Subject: [PATCH] OLLamaLLMService: Pass kwargs --- CHANGELOG.md | 3 +++ src/pipecat/services/ollama/llm.py | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e0b75ad..bce396bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 the value to False requires a custom processor before the `TTSService` to aggregate LLM tokens. +- Added `kwargs` to the `OLLamaLLMService` to allow for configuration args to + be passed to Ollama. + - Added call hang-up error handling in `TwilioFrameSerializer`, which handles the case where the user has hung up before the `TwilioFrameSerializer` hangs up the call. diff --git a/src/pipecat/services/ollama/llm.py b/src/pipecat/services/ollama/llm.py index c84505704..de01dbc5b 100644 --- a/src/pipecat/services/ollama/llm.py +++ b/src/pipecat/services/ollama/llm.py @@ -6,6 +6,8 @@ """OLLama LLM service implementation for Pipecat AI framework.""" +from loguru import logger + from pipecat.services.openai.llm import OpenAILLMService @@ -16,12 +18,28 @@ class OLLamaLLMService(OpenAILLMService): providing a compatible interface for running large language models locally. """ - def __init__(self, *, model: str = "llama2", base_url: str = "http://localhost:11434/v1"): + def __init__( + self, *, model: str = "llama2", base_url: str = "http://localhost:11434/v1", **kwargs + ): """Initialize OLLama LLM service. Args: model: The OLLama model to use. Defaults to "llama2". base_url: The base URL for the OLLama API endpoint. Defaults to "http://localhost:11434/v1". + **kwargs: Additional keyword arguments passed to OpenAILLMService. """ - super().__init__(model=model, base_url=base_url, api_key="ollama") + super().__init__(model=model, base_url=base_url, api_key="ollama", **kwargs) + + def create_client(self, base_url=None, **kwargs): + """Create OpenAI-compatible client for Ollama. + + Args: + base_url: The base URL for the API. If None, uses instance base_url. + **kwargs: Additional keyword arguments passed to the parent create_client method. + + Returns: + An OpenAI-compatible client configured for Ollama. + """ + logger.debug(f"Creating Ollama client with api {base_url}") + return super().create_client(base_url, **kwargs)