From b77ce4e8464df5c91589e5da6e6958c2a6731271 Mon Sep 17 00:00:00 2001 From: Kevin Hu Date: Mon, 24 Mar 2025 14:53:17 +0800 Subject: [PATCH] Feat: support api-key for Ollama. (#6448) ### What problem does this PR solve? #6189 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/llm/embedding_model.py | 3 ++- rag/llm/tts_model.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.py index dba11b7db..c42e9b0f5 100644 --- a/rag/llm/embedding_model.py +++ b/rag/llm/embedding_model.py @@ -252,7 +252,8 @@ class ZhipuEmbed(Base): class OllamaEmbed(Base): def __init__(self, key, model_name, **kwargs): - self.client = Client(host=kwargs["base_url"]) + self.client = Client(host=kwargs["base_url"]) if not key or key == "x" else \ + Client(host=kwargs["base_url"], headers={"Authorization": f"Bear {key}"}) self.model_name = model_name def encode(self, texts: list): diff --git a/rag/llm/tts_model.py b/rag/llm/tts_model.py index ebcdca5e4..e07ba695a 100644 --- a/rag/llm/tts_model.py +++ b/rag/llm/tts_model.py @@ -339,6 +339,8 @@ class OllamaTTS(Base): self.headers = { "Content-Type": "application/json" } + if key and key != "x": + self.headers["Authorization"] = f"Bear {key}" def tts(self, text, voice="standard-voice"): payload = {