Repository: hand-e-fr/OpenHosta (language: python)

Issue:
Prompts could be shorter and optimized.
Do a list of elements given to the LLM at the start
Faire référence à la fonction elle-même avec son nom dans le user prompt
ajouter des "```" pour les bloques techniques


Discussion / hints:

Fix patch:
diff --git a/CHAGELOG.md b/CHAGELOG.md
index 0079fbb..b2c87b8 100644
--- a/CHAGELOG.md
+++ b/CHAGELOG.md
@@ -28,7 +28,8 @@ All significant changes to this project will be documented in this file.
   - `set_prompt` in `PromptManager` enables to change automatically a prompt un "prompt.json"
 
 - **Optimization**
-  - `emulate` prompt changed: confidence level removed: (~20% speed gained)
+  - `emulate` prompt changed: confidence level removed: (~20% speed gained) (`emulate`: v1.1)
+  - All prompt enhanced: added code block, separator and reference to the name of the processed function (`emulate`: v1.2, `enhance` v1.2, `thought`: v1.1, `estimate`: v1.1)
 
 ## **v1.0** 29/08/2024:
 
diff --git a/src/OpenHosta/prompt.json b/src/OpenHosta/prompt.json
index aa9cee5..ec4ba33 100644
--- a/src/OpenHosta/prompt.json
+++ b/src/OpenHosta/prompt.json
@@ -2,27 +2,27 @@
     "prompts": [
         {
             "key": "estimate",
-            "text": "You're a prompt engineering engineer tasked with estimating the number of output tokens an AI would return when executing a given function.\nThe functions are written in Python, so function returns must use Python typing.\n\nEach time, I'll give you the following elements:\n- The definition of the function.\n- Its call with arguments.\n- The function's docstring.\n\nYou need to take all these elements into account when formulating your answer.\nTo estimate the output token, you need to use a tokenization algorithm: take the one in GPT-3.\n\nTo make your estimate, you need to go through this chain of thought:\n\n1. Understand the Function.\n\t- With the given definition, the function prototype and its docstring.\n2. Analyze the Function Call.\n\t- With the function name and arguments provided.\n3. Guess the expected result without calculating it.\n\t- You MUST NOT calculate the result of the function.\n\t- Simply make a prediction with all the elements you have at your disposal.\n\t- Pay attention to the type of output. If it's not specified in the function prototype, then guess it based on the description and type of the input arguments.\n4. Estimate the number of tokens.\n\t- Use the information you have available for this step.\n\t- If the estimate is complex or impossible, make a realistic prediction using the context elements.\n5. Formulate your answer\n\t- Synthesize your answer into a single number.\n\t- Follow the answer format I'll give you below\n\nYou should encode your response in valid JSON format, without comments, using the following format:\n{ “tokens”:...}\nYour answer in the “tokens” category must be a number only.\nNothing should appear other than this JSON structure.\n\nAny assumptions made should be reasonable based on the provided function description and should take into account the error handling of the function.\n\nI'll give you an example:\nFunction definition:\n```python\ndef reverse_string(a:str)->str:\n\t\"\"\"\n\tThis function reverse the string in parameter.\n\t\"\"\"\n\treturn emulate()\n```\n\nFunction call:\n```python\nreverse_string(\"Hello World!\")\n```\n\nExcpected output:\n```\n{\"tokens\": 13}\n```\n\nHere's all the function documentation for you to estimate:",
+            "text": "You're a prompt engineering engineer tasked with estimating the number of output tokens an AI would return when executing a given function.\nThe functions are written in Python, so function returns must use Python typing.\n\nEach time, I'll give you the following elements:\n- The definition of the function.\n- Its call with arguments.\n- The function's docstring.\n\nYou need to take all these elements into account when formulating your answer.\nTo estimate the output token, you need to use a tokenization algorithm: take the one in GPT-3.\n---\nTo make your estimate, you need to go through this chain of thought:\n\n1. Understand the Function.\n\t- With the given definition, the function prototype and its docstring.\n2. Analyze the Function Call.\n\t- With the function name and arguments provided.\n3. Guess the expected result without calculating it.\n\t- You MUST NOT calculate the result of the function.\n\t- Simply make a prediction with all the elements you have at your disposal.\n\t- Pay attention to the type of output. If it's not specified in the function prototype, then guess it based on the description and type of the input arguments.\n4. Estimate the number of tokens.\n\t- Use the information you have available for this step.\n\t- If the estimate is complex or impossible, make a realistic prediction using the context elements.\n5. Formulate your answer\n\t- Synthesize your answer into a single number.\n\t- Follow the answer format I'll give you below\n---\nYou should encode your response in valid JSON format, without comments, using the following format:\n{ \"tokens\":...}\nYour answer in the \"tokens\" category must be a number only.\nNothing should appear other than this JSON structure.\n\nAny assumptions made should be reasonable based on the provided function description and should take into account the error handling of the function.\n---\nI'll give you an example:\nFunction definition:\n```python\ndef reverse_string(a:str)->str:\n\t\"\"\"\n\tThis function reverse the string in parameter.\n\t\"\"\"\n\treturn emulate()\n```\n\nFunction call:\n```python\nreverse_string(\"Hello World!\")\n```\n\nExcpected output:\n```\n{\"tokens\": 13}\n```\n\nHere's all the function documentation for you to estimate:\n---\n",
             "category": "analytics",
-            "version": "v1.0"
+            "version": "v1.1"
         },
         {
             "key": "thought",
-            "text": "You will act as an emulator of impossible-to-code functions. I will provide you with the description of the function using Python's way of declaring functions, but I won't provide the function body as I don't know how to code it. It might even be impossible to code. Therefore, you should not try to write the body. Instead, directly imagine the function output.\n\nIn the conversation, I will directly write the function behavior as a sentence, and the argument passed to the function.\n\nYour objective is to find the Python data type to be returned by the function. Take into account the function's behavior, the wording and intent of the sentence, and the arguments given. You must give your answer without any comment and in the following JSON schema: \n{\"type\": \"\"}\nTo fill in the type key, you need to follow Python syntax, such as \"int\" or \"str\", depending on your answer. \n\n---\n\nHere are a few examples:\n\nFunction behavior: “Is a positive number”\nArgument: “2”\nExpected response: {“type”: “bool”}\n\nFunction behavior: “Multiply a number by 2”\nArgument: “10”\nExpected response: {“type”: “int”}\n\nFunction behavior: “Reverse a string”\nArgument: “Hello World!\nExpected response: {“type”: “str”}\n\nFunction behavior: “Sorts a list in ascending order” Argument: “Hello World!\nArgument: “(10, 5, 7, 12 ,3)”\nExpected response: {“type”: “list”}\n\n---\n",
+            "text": "You will act as an emulator of impossible-to-code functions. I will provide you with the description of the function using Python's way of declaring functions, but I won't provide the function body as I don't know how to code it. It might even be impossible to code. Therefore, you should not try to write the body. Instead, directly imagine the function output.\n\nIn the conversation, I will directly write the function behavior as a sentence, and the argument passed to the function.\n\nYour objective is to find the Python data type to be returned by the function. Take into account the function's behavior, the wording and intent of the sentence, and the arguments given. You must give your answer without any comment and in the following JSON schema:\n```\n{\"type\": \"\"}\n```\n\nTo fill in the type key, you need to follow Python syntax, such as \"int\" or \"str\", depending on your answer. \n\n---\n\nHere are a few examples:\n\nFunction behavior: \"Is a positive number\"\nArgument: 2\nExpected response: {\"type\": \"bool\"}\n\nFunction behavior: \"Multiply a number by 2\"\nArgument: 10\nExpected response: {\"type\": \"int\"}\n\nFunction behavior: \"Reverse a string\"\nArgument: \"Hello World!\"\nExpected response: {\"type\": \"str\"}\n\nFunction behavior: \"Sorts a list in ascending order\"\nArgument: (10, 5, 7, 12, 3)\nExpected response: {\"type\": \"list\"}\n\n---\n",
             "category": "executive",
-            "version": "1.0"
+            "version": "1.1"
         },
         {
             "key": "enhance",
-            "text": "I want you to become my Expert Prompt Creator for developer. Your goal is to help me craft the best possible prompt for my programming needs. The prompt you provide should be written from the perspective of me making the request to GPT-4o. Consider in your prompt creation that this prompt will be entered into an interface for GPT-4o. Apart from diagrams, you must write in text, without following any syntax. The process is as follows: You will generate the following sections:\n\n---\n\n -> enhanced:\n{provide the best possible prompt according to my request. The prompt is used to describe a function to be performed in Python as precisely as possible. You can add error handling, as the function needs it to work properly. But don't code the function in the prompt. The prompt should not tell to create the function, but describe how it works.}\n\n-> review:\n{provide a concise paragraph on how to improve the prompt. Be very critical in your response. This section is intended to force constructive criticism even when the prompt is acceptable. Any assumptions and or issues should be included. Don't forget that you speak to a developer}\n\n-> advanced:\n{rewrite the prompt with the suggested improvements you made in the critique category. The aim is to make a proposal, an example. Make logical assumptions to solve the problem based on the context and all the information you have. You have to respond to the problems you formulated in the previous category. But don't code the function in the prompt.}\n\n-> mermaid:\n{Make a mermaid diagram explaining the function described by the prompt. You need to break the reasoning into several steps for ease of understanding and clarity. You must make it logical and easy to look at. You have to write it in mermaid syntax. You must not use the markdown syntax}\n\n---\n\nYou must formulate your response without any comment and in this JSON schema:\n{\"enhanced\": \"\", \"review\": \"\", \"advanced\": \"\", \"mermaid\": \"\"}\n\n---\n",
+            "text": "I want you to become my Expert Prompt Creator for developer. Your goal is to help me craft the best possible prompt for my programming needs. The prompt you provide should be written from the perspective of me making the request to GPT-4o. Consider in your prompt creation that this prompt will be entered into an interface for GPT-4o. Apart from diagrams, you must write in text, without following any syntax. The process is as follows: You will generate the following sections:\n\n---\n\n -> enhanced:\n{provide the best possible prompt according to my request. The prompt is used to describe a function to be performed in Python as precisely as possible. You can add error handling, as the function needs it to work properly. But don't code the function in the prompt. The prompt should not tell to create the function, but describe how it works.}\n\n-> review:\n{provide a concise paragraph on how to improve the prompt. Be very critical in your response. This section is intended to force constructive criticism even when the prompt is acceptable. Any assumptions and or issues should be included. Don't forget that you speak to a developer}\n\n-> advanced:\n{rewrite the prompt with the suggested improvements you made in the critique category. The aim is to make a proposal, an example. Make logical assumptions to solve the problem based on the context and all the information you have. You have to respond to the problems you formulated in the previous category. But don't code the function in the prompt.}\n\n-> mermaid:\n{Make a mermaid diagram explaining the function described by the prompt. You need to break the reasoning into several steps for ease of understanding and clarity. You must make it logical and easy to look at. You have to write it in mermaid syntax. You must not use the markdown syntax}\n\n---\n\nYou must formulate your response without any comment and in this JSON schema:\n```\n{\"enhanced\": \"\", \"review\": \"\", \"advanced\": \"\", \"mermaid\": \"\"}\n```\n---\n",
             "category": "analytics",
-            "version": "v1.1"
+            "version": "v1.2"
         },
         {
             "key": "emulate",
-            "text": "You will act as an emulator of impossible-to-code functions. I will provide you with the description of the function using Python's way of declaring functions, but I won't provide the function body as I don't know how to code it. It might even be impossible to code. Therefore, you should not try to write the body. Instead, directly imagine the function output.\n\nIn the conversation, I will directly write the function call as if it was called in Python. You should directly answer with whatever you believe would be a good return for the function.\n\n\nIf the output is documented as a Python structure, you should translate it to JSON.\nYou should encode the return in valid JSON format, without comments, using the following format:\n{\"return\":\"...\"}\n\nThe output must be of the same type as that specified in the function call.\n\nAny assumptions made should be reasonable based on the provided function description and should take into account the error handling of the function.\n\nConsistency in the confidence levels is important to ensure accurate responses.\\nThis is the function documentation:\n\nExample function call:\n\ndef example_function(a: int, b: dict) -> int:\n\t\\\"\\\"\\\"\\\n\tThis is an example function.\n\tIt adds two numbers.\n\t\\\"\\\"\\\"\n\treturn emulate()\n\nExample imagined function output:\n\nresult = example_function(3, {\\\"value\\\": 7})\n\nExpected JSON output:\n{\"return\": 10}",
+            "text": "You will act as an emulator of impossible-to-code functions. I will provide you with the description of the function using Python's way of declaring functions, but I won't provide the function body as I don't know how to code it. It might even be impossible to code. Therefore, you should not try to write the body. Instead, directly imagine the function output.\n\nIn the conversation, I will directly write the function call as if it was called in Python. You should directly answer with whatever you believe would be a good return for the function.\n\nIf the output is documented as a Python structure, you should translate it to JSON.\nYou should encode the return in valid JSON format, without comments, using the following format:\n```\n{\"return\":\"...\"}\n```\nThe output must be of the same type as that specified in the function call.\n\nAny assumptions made should be reasonable based on the provided function description and should take into account the error handling of the function.\n\nConsistency in the confidence levels is important to ensure accurate responses.\nThis is the function documentation:\n---\nExample function definition:\n```python\ndef example_function(a: int, b: dict) -> int:\n\t\"\"\"\n\tThis is an example function.\n\tIt adds two numbers.\n\t\"\"\"\n\treturn emulate()\n```\n\nExample imagined function call:\n```python\nresult = example_function(3, {\\\"value\\\": 7})\n```\n\nExpected JSON output:\n{\"return\": 10}\n---\n",
             "category": "executive",
-            "version": "v1.1"
+            "version": "v1.2"
         }
     ]
 }
\ No newline at end of file


Test patch:
diff --git a/tests/functionnalTests/test_mandatory.py b/tests/functionnalTests/test_mandatory.py
index 5a58347..2e8e0d6 100644
--- a/tests/functionnalTests/test_mandatory.py
+++ b/tests/functionnalTests/test_mandatory.py
@@ -221,7 +221,7 @@ def test_BasicTyped(self, prompt, args, expected):
         ("Count the letter un a setence", "Hello World!", int),
         ("capitalize a setence", "hello world!", str),
         ("Give the number Pi to 3 decimal places", "", float),
-        ("Sort in ascending order", (2, 5, 1, 12, 6), list),
+        ("Sort in ascending order", [2, 5, 1, 12, 6], list),
         ("Is a positive number", 6, bool),
     ])
     def test_FeaturePredict(self, prompt, args, expected):