diff --git a/main.py b/main.py index 1c967a6..ec2561b 100755 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ def handleInterrupt(signum, frame): def main(): signal.signal(signal.SIGINT, handler=handleInterrupt) - #local_provider = Provider("ollama", "deepseek-r1:14b", None) + #local_provider = Provider("ollama", "deepseek-r1:14b", "127.0.0.1:5000") server_provider = Provider(provider_name="server", model="deepseek-r1:14b", server_address="192.168.1.100:5000") diff --git a/requirements.txt b/requirements.txt index b08395f..2a94a0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ openai==1.61.1 colorama==0.4.6 python-dotenv==1.0.0 playsound==1.3.0 +soundfile==0.13.1 transformers==4.48.3 torch==2.5.1 ollama==0.4.7 diff --git a/sources/agent.py b/sources/agent.py index 397e4a1..5f998e9 100644 --- a/sources/agent.py +++ b/sources/agent.py @@ -101,7 +101,6 @@ class Agent(): feedback = "" blocks = None - print("Loading tools: ", self._tools.items()) for name, tool in self._tools.items(): feedback = "" blocks = tool.load_exec_block(answer) diff --git a/sources/llm_provider.py b/sources/llm_provider.py index d9321bd..a1bb575 100644 --- a/sources/llm_provider.py +++ b/sources/llm_provider.py @@ -15,8 +15,7 @@ class Provider: self.available_providers = { "ollama": self.ollama_fn, "server": self.server_fn, - "test": self.test_fn - + "test": self.test_fn, } if self.server != "": print("Provider initialized at ", self.server) @@ -99,7 +98,7 @@ class Provider: thought += chunk['message']['content'] except ollama.ResponseError as e: if e.status_code == 404: - ollama.pull(self._model) + ollama.pull(self.model) if "refused" in str(e): raise Exception("Ollama connection failed. is the server running ?") raise e diff --git a/sources/text_to_speech.py b/sources/text_to_speech.py index dfb52fe..ece674f 100644 --- a/sources/text_to_speech.py +++ b/sources/text_to_speech.py @@ -7,16 +7,22 @@ import re class Speech(): def __init__(self, language = "english") -> None: self.lang_map = { - "english": 'a', # πŸ‡ΊπŸ‡Έ 'a' => American English - "chinese": 'z', # πŸ‡―πŸ‡΅ 'j' => Japanese: pip install misaki[ja] - "japanese": 'j' # # πŸ‡¨πŸ‡³ 'z' => Mandarin Chinese: pip install misaki[zh] + "english": 'a', + "chinese": 'z', + "french": 'f' + } + self.voice_map = { + "english": ['af_alloy', 'af_aoede', 'af_bella', 'af_heart', 'af_jessica', 'af_kore', 'af_nicole', 'af_nova', 'af_river', 'af_sarah', 'af_sky', 'am_adam', 'am_echo', 'am_eric', 'am_fenrir', 'am_liam', 'am_michael', 'am_onyx', 'am_puck'], + "chinese": ['zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi', 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang'], + "french": ['ff_siwis'] } self.pipeline = KPipeline(lang_code=self.lang_map[language]) + self.voice = self.voice_map[language][0] def speak(self, sentence): sentence = self.clean_sentence(sentence) generator = self.pipeline( - sentence, voice='af_heart', # <= change voice here + sentence, voice=self.voice, speed=1, split_pattern=r'\n+' ) for i, (gs, ps, audio) in enumerate(generator): diff --git a/sources/tools/tools.py b/sources/tools/tools.py index 8dbe42a..aff62c8 100644 --- a/sources/tools/tools.py +++ b/sources/tools/tools.py @@ -70,25 +70,44 @@ class Tools(): return text return text[:start_idx] + text[end_idx:] - def load_exec_block(self, generation:str) -> str: + def load_exec_block(self, generation: str) -> str: """ - Extract the code/query blocks from the answer text. + Extract the code/query blocks from the answer text, removing consistent leading whitespace. """ assert self.tag != "undefined", "Tag not defined" start_tag = f'```{self.tag}' - end_tag = '```' + end_tag = '```' code_blocks = [] start_index = 0 - + if start_tag not in generation: return None + while True: start_pos = generation.find(start_tag, start_index) if start_pos == -1: break + + line_start = generation.rfind('\n', 0, start_pos) + 1 + if line_start == 0: + line_start = 0 + leading_whitespace = generation[line_start:start_pos] + end_pos = generation.find(end_tag, start_pos + len(start_tag)) if end_pos == -1: break - code_blocks.append(generation[start_pos + len(start_tag):end_pos]) + content = generation[start_pos + len(start_tag):end_pos] + lines = content.split('\n') + if leading_whitespace: + processed_lines = [] + for line in lines: + if line.startswith(leading_whitespace): + processed_lines.append(line[len(leading_whitespace):]) + else: + processed_lines.append(line) + content = '\n'.join(processed_lines) + + code_blocks.append(content) start_index = end_pos + len(end_tag) + return code_blocks \ No newline at end of file