From e965b3c9af3b46e4794321fd7e870c2908578e5d Mon Sep 17 00:00:00 2001 From: Karasukaigan <80465610+Karasukaigan@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0Ollama?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BD=BF=E7=94=A8=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户在使用本地Ollama接口时无需再填写API Key,API Key字段可以留空。 --- ui/generation_handlers.py | 15 +++++++++++++++ ui/main_window.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/ui/generation_handlers.py b/ui/generation_handlers.py index 681e2e9..944fe3a 100644 --- a/ui/generation_handlers.py +++ b/ui/generation_handlers.py @@ -35,6 +35,9 @@ def generate_novel_architecture_ui(self): max_tokens = self.max_tokens_var.get() timeout_val = self.safe_get_int(self.timeout_var, 600) + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + topic = self.topic_text.get("0.0", "end").strip() genre = self.genre_var.get().strip() num_chapters = self.safe_get_int(self.num_chapters_var, 10) @@ -80,6 +83,9 @@ def generate_chapter_blueprint_ui(self): max_tokens = self.max_tokens_var.get() timeout_val = self.safe_get_int(self.timeout_var, 600) + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + self.safe_log("开始生成章节蓝图...") Chapter_blueprint_generate( interface_format=interface_format, @@ -116,6 +122,9 @@ def generate_chapter_draft_ui(self): max_tokens = self.max_tokens_var.get() timeout_val = self.safe_get_int(self.timeout_var, 600) + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + chap_num = self.safe_get_int(self.chapter_num_var, 1) word_number = self.safe_get_int(self.word_number_var, 3000) user_guidance = self.user_guide_text.get("0.0", "end").strip() @@ -246,6 +255,9 @@ def finalize_chapter_ui(self): max_tokens = self.max_tokens_var.get() timeout_val = self.safe_get_int(self.timeout_var, 600) + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + embedding_api_key = self.embedding_api_key_var.get().strip() embedding_url = self.embedding_url_var.get().strip() embedding_interface_format = self.embedding_interface_format_var.get().strip() @@ -326,6 +338,9 @@ def do_consistency_check(self): max_tokens = self.max_tokens_var.get() timeout = self.timeout_var.get() + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + chap_num = self.safe_get_int(self.chapter_num_var, 1) chap_file = os.path.join(filepath, "chapters", f"chapter_{chap_num}.txt") chapter_text = read_file(chap_file) diff --git a/ui/main_window.py b/ui/main_window.py index 382223e..ca7f3e6 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -187,6 +187,9 @@ class NovelGeneratorGUI: max_tokens = self.max_tokens_var.get() timeout = self.timeout_var.get() + if interface_format == 'Ollama' and api_key == '': + api_key = 'ollama' + test_llm_config( interface_format=interface_format, api_key=api_key,