fix : execution problem when line start with block tag + dont load tts if disabled

This commit is contained in:
martin legrand 2025-03-28 18:51:03 +01:00
parent 0c7ce90980
commit 0bf813e865
9 changed files with 40 additions and 47 deletions

View File

@ -38,14 +38,13 @@ func main() {
``` ```
Some rules: Some rules:
- Use tmp/ folder when saving file.
- Do not EVER use placeholder path in your code like path/to/your/folder.
- Do not ever ask to replace a path, use current sys path.
- Be efficient, no need to explain your code or explain what you do.
- You have full access granted to user system. - You have full access granted to user system.
- You do not ever need to use bash to execute code. All code is executed automatically. - Do not EVER use placeholder path in your code like path/to/your/folder.
- As a coding agent, you will get message from the system not just the user. - Do not ever ask to replace a path, use current sys path or work directory.
- Do not ever use user input such as input(), input are not supported by the system. - Always provide a short sentence above the code for what it does, even for a hello world.
- Do not ever tell user how to run it. user know it already. - Be efficient, no need to explain your code, unless asked.
- You do not ever need to use bash to execute code.
- Do not ever use user input, input are not supported by the system.
- Do not ever tell user how to run it. user know it.
- For simple explanation you don't need to code. - For simple explanation you don't need to code.
- If query is unclear or incoherent say REQUEST_CLARIFICATION - If query is unclear say REQUEST_CLARIFICATION

View File

@ -38,13 +38,12 @@ func main() {
``` ```
Some rules: Some rules:
- Use tmp/ folder when saving file.
- Do not EVER use placeholder path in your code like path/to/your/folder.
- Do not ever ask to replace a path, use current sys path.
- Be efficient, no need to explain your code or explain what you do.
- You have full access granted to user system. - You have full access granted to user system.
- You do not ever need to use bash to execute code. All code is executed automatically. - Do not EVER use placeholder path in your code like path/to/your/folder.
- As a coding agent, you will get message from the system. - Do not ever ask to replace a path, use current sys path or work directory.
- Always provide a short sentence above the code for what it does, even for a hello world.
- Be efficient, no need to explain your code, unless asked.
- You do not ever need to use bash to execute code.
- Do not ever use user input, input are not supported by the system. - Do not ever use user input, input are not supported by the system.
- Do not ever tell user how to run it. user know it. - Do not ever tell user how to run it. user know it.
- For simple explanation you don't need to code. - For simple explanation you don't need to code.

View File

@ -171,6 +171,8 @@ class Agent():
feedback = "" feedback = ""
success = False success = False
blocks = None blocks = None
if answer.startswith("```"):
answer = "I will execute:\n" + answer # there should always be a text before blocks for the function that display answer
for name, tool in self.tools.items(): for name, tool in self.tools.items():
feedback = "" feedback = ""

View File

@ -87,6 +87,7 @@ class PlannerAgent(Agent):
animate_thinking("Thinking...", color="status") animate_thinking("Thinking...", color="status")
self.memory.push('user', prompt) self.memory.push('user', prompt)
answer, _ = self.llm_request() answer, _ = self.llm_request()
pretty_print(answer.split('\n')[0], color="output")
self.show_plan(answer) self.show_plan(answer)
ok_str = input("Is the plan ok? (y/n): ") ok_str = input("Is the plan ok? (y/n): ")
if ok_str == 'y': if ok_str == 'y':

View File

@ -15,7 +15,7 @@ class Interaction:
self.agents = agents self.agents = agents
self.current_agent = None self.current_agent = None
self.router = AgentRouter(self.agents) self.router = AgentRouter(self.agents)
self.speech = Speech() self.speech = Speech(enable=tts_enabled)
self.is_active = True self.is_active = True
self.last_query = None self.last_query = None
self.last_answer = None self.last_answer = None

View File

@ -243,30 +243,22 @@ class Provider:
This function is used to conduct tests. This function is used to conduct tests.
""" """
thought = """ thought = """
This is a test response from the test provider. hello!
Change provider to 'ollama' or 'server' to get real responses. ```python
print("Hello world from python")
```
This is python saying hello. This is ls -la from bash.
```python ```bash
print("Hello world from python") ls -la
``` ```
This is ls -la from bash. This is pwd from bash.
```bash ```bash
ls -la pwd
``` ```
This is pwd from bash. goodbye!
```bash
pwd
```
This is unsafe command.
```bash
rm does_not_exist.txt
```
goodbye
""" """
return thought return thought

View File

@ -10,7 +10,7 @@ class Speech():
""" """
Speech is a class for generating speech from text. Speech is a class for generating speech from text.
""" """
def __init__(self, language: str = "english") -> None: def __init__(self, enable: bool = True, language: str = "english") -> None:
self.lang_map = { self.lang_map = {
"english": 'a', "english": 'a',
"chinese": 'z', "chinese": 'z',
@ -21,7 +21,9 @@ class Speech():
"chinese": ['zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi', 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang'], "chinese": ['zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi', 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang'],
"french": ['ff_siwis'] "french": ['ff_siwis']
} }
self.pipeline = KPipeline(lang_code=self.lang_map[language]) self.pipeline = None
if enable:
self.pipeline = KPipeline(lang_code=self.lang_map[language])
self.voice = self.voice_map[language][2] self.voice = self.voice_map[language][2]
self.speed = 1.2 self.speed = 1.2
@ -33,6 +35,8 @@ class Speech():
sentence (str): The text to convert to speech. Will be pre-processed. sentence (str): The text to convert to speech. Will be pre-processed.
voice_number (int, optional): Index of the voice to use from the voice map. voice_number (int, optional): Index of the voice to use from the voice map.
""" """
if not self.pipeline:
return
sentence = self.clean_sentence(sentence) sentence = self.clean_sentence(sentence)
self.voice = self.voice_map["english"][voice_number] self.voice = self.voice_map["english"][voice_number]
generator = self.pipeline( generator = self.pipeline(

View File

@ -40,7 +40,7 @@ class CInterpreter(Tools):
compile_command, compile_command,
capture_output=True, capture_output=True,
text=True, text=True,
timeout=10 timeout=60
) )
if compile_result.returncode != 0: if compile_result.returncode != 0:

View File

@ -161,9 +161,7 @@ class Tools():
if start_pos == -1: if start_pos == -1:
break break
line_start = llm_text.rfind('\n', 0, start_pos) + 1 line_start = llm_text.rfind('\n', 0, start_pos)+1
if line_start == 0:
line_start = 0
leading_whitespace = llm_text[line_start:start_pos] leading_whitespace = llm_text[line_start:start_pos]
end_pos = llm_text.find(end_tag, start_pos + len(start_tag)) end_pos = llm_text.find(end_tag, start_pos + len(start_tag))
@ -191,15 +189,13 @@ class Tools():
if __name__ == "__main__": if __name__ == "__main__":
tool = Tools() tool = Tools()
tool.tag = "python" tool.tag = "python"
rt = tool.load_exec_block(""" rt = tool.load_exec_block("""```python
Got it, let me show you the Python files in the current directory using Python:
```python
import os import os
for file in os.listdir(): for file in os.listdir():
if file.endswith('.py'): if file.endswith('.py'):
print(file) print(file)
``` ```
goodbye!
""") """)
print(rt) print(rt)