first rev
This commit is contained in:
commit
bd58078014
8 changed files with 278 additions and 0 deletions
63
ai_output_parser
Executable file
63
ai_output_parser
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python
|
||||
import re
|
||||
import argparse
|
||||
|
||||
def extract_content(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
|
||||
# Utiliser une expression régulière pour trouver le contenu entre les balises <think> et </think>
|
||||
#think_pattern = r'<think>(.*?)</think>'
|
||||
think_pattern = r'Thinking\.\.\.(.*?)\.\.\.done thinking\.'
|
||||
think_matches = re.findall(think_pattern, content, re.DOTALL)
|
||||
|
||||
# Nettoyer les résultats pour enlever les espaces superflus
|
||||
extracted_think = [match.strip() for match in think_matches]
|
||||
|
||||
# Utiliser une expression régulière pour trouver le contenu YAML entre les balises ```yaml et ```
|
||||
yaml_pattern = r'```yaml(.*?)```'
|
||||
yaml_matches = re.findall(yaml_pattern, content, re.DOTALL)
|
||||
|
||||
# Nettoyer les résultats pour enlever les espaces superflus
|
||||
extracted_yaml = [match.strip() for match in yaml_matches]
|
||||
|
||||
# Supprimer le contenu YAML et <think> du texte complet
|
||||
markdown_content = re.sub(yaml_pattern, '', content, flags=re.DOTALL)
|
||||
markdown_content = re.sub(think_pattern, '', markdown_content, flags=re.DOTALL)
|
||||
|
||||
return extracted_think, extracted_yaml, markdown_content.strip()
|
||||
|
||||
def main():
|
||||
# Configuration de l'analyseur d'arguments
|
||||
parser = argparse.ArgumentParser(description='Extraire le contenu d\'un fichier texte.')
|
||||
parser.add_argument('file_path', type=str, help='Chemin vers le fichier texte à analyser.')
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('--think', action='store_true', help='Afficher le contenu de la balise <think>.')
|
||||
group.add_argument('--explanation', action='store_true', help='Afficher le reste du Markdown sans le code YAML et <think>.')
|
||||
group.add_argument('--yaml', action='store_true', help='Afficher le contenu YAML.')
|
||||
|
||||
# Analyse des arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
# Extraction du contenu
|
||||
extracted_think, extracted_yaml, markdown_content = extract_content(args.file_path)
|
||||
|
||||
if args.think:
|
||||
# Affichage du contenu de la balise <think>
|
||||
if extracted_think:
|
||||
print(extracted_think[0])
|
||||
else:
|
||||
print("Aucun contenu trouvé entre les balises <think> et </think>.")
|
||||
elif args.yaml:
|
||||
# Affichage du contenu YAML
|
||||
if extracted_yaml:
|
||||
print(extracted_yaml[0])
|
||||
else:
|
||||
print("Aucun contenu YAML trouvé.")
|
||||
elif args.explanation:
|
||||
# Affichage du reste du Markdown sans le code YAML et <think>
|
||||
print(markdown_content)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
25
readme.rst
Normal file
25
readme.rst
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
AI output parser
|
||||
================
|
||||
|
||||
Description
|
||||
---------------
|
||||
|
||||
A Python script that parses the markdown output of a reasonning LLM output,
|
||||
it processes the output, it:
|
||||
|
||||
- extracts the `think` inner monolog
|
||||
<!-- - extracts a Rougail YAML output -->
|
||||
<!-- extracting the Rougail documentation description -->
|
||||
- erases the inner monologs
|
||||
- ...
|
||||
|
||||
Usage
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
./bin/ai_output_parser
|
||||
usage: ai_output_parser [-h] (--think | --explanation | --yaml) file_path
|
||||
|
||||
The `file_path` argument is required and
|
||||
one of the arguments --think --explanation --yaml is required.
|
||||
68
tests/ai_output.md
Normal file
68
tests/ai_output.md
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
ollama run rougail_ai
|
||||
>>> I would like informations about the HTTPS proxy. What is the name of the variable ?
|
||||
Thinking...
|
||||
|
||||
Alright, the user is asking about the HTTPS proxy variables. They want to know the variable names related to HTTPS proxy setup.
|
||||
|
||||
Looking at the markdown, I need to find the section under the "proxy_mode" variable that's specifically for HTTPS.
|
||||
|
||||
I see a section labeled "HTTPS Proxy" which is under the "manual" path. This section contains the details about the variables used for HTTPS proxy configuration.
|
||||
|
||||
Now, I should list each variable and its description. The variables mentioned are:
|
||||
|
||||
1. manual.https_proxy.address: This is the HTTPS proxy address. It's mandatory and can be an IP address or a domain name.
|
||||
|
||||
2. manual.https_proxy.port: This sets the HTTPS proxy port. It's mandatory and can be any well-known, registered, or private port. The default is 8080, but it's set to the same as the
|
||||
HTTP proxy port if not specified.
|
||||
|
||||
3. manual.use_for_https: This is a boolean variable that determines if the proxy should be used for HTTPS traffic. It's mandatory and defaults to true.
|
||||
|
||||
I should present these variables clearly, explaining each one's purpose and default values. This way, the user can understand how to configure their HTTPS proxy settings based on the
|
||||
documentation.
|
||||
...done thinking.
|
||||
|
||||
|
||||
|
||||
To provide information about the HTTPS proxy variables, here's what you need to know:
|
||||
|
||||
### Variable Names for HTTPS Proxy Configuration:
|
||||
1. **`manual.https_proxy.address`**
|
||||
- **Description**: Specifies the address of the HTTPS proxy.
|
||||
- **Type**: `domainname` or IP address (mandatory).
|
||||
- **Default**: Uses the value of `[HTTP proxy address](#manual.http_proxy.address)`.
|
||||
|
||||
2. **`manual.https_proxy.port`**
|
||||
- **Description**: Specifies the port number for the HTTPS proxy.
|
||||
- **Type**: Integer (1 to 65535, inclusive).
|
||||
- **Default**: The value of `[HTTP proxy port](#manual.http_proxy.port)`.
|
||||
- **Enabled**: Only when `[manual.use_for_https](#manual.use_for_https)` is set to `true`.
|
||||
|
||||
3. **`manual.use_for_https`**
|
||||
- **Description**: Determines if the proxy is used for HTTPS traffic.
|
||||
- **Type**: Boolean (mandatory).
|
||||
- **Default**: `true`.
|
||||
|
||||
These variables allow you to configure a dedicated HTTPS proxy setup.
|
||||
|
||||
>>> OK yes, what is the HTTPS Proxy variables' group name ?
|
||||
Thinking...
|
||||
|
||||
Alright, so the user asked about the HTTPS Proxy variables' group name. From the previous conversation, I explained that there are specific variables under the manual section for HTTPS
|
||||
proxy, including manual.https_proxy.address, manual.https_proxy.port, and manual.use_for_https.
|
||||
|
||||
Now, the user is specifically asking about the group name of these variables. I need to recall the structure from the markdown provided. Looking back, under the "Manual proxy
|
||||
configuration" path, there's a sub-note saying the path is manual, and then under that, there's the "hidden" option. That probably indicates that HTTPS proxy variables are under the
|
||||
manual.https_proxy group.
|
||||
|
||||
I should confirm this by rechecking the markdown. Yes, under the path manual, there's a note about the "disabled" option which points to the "manual.https_proxy" path. So, the HTTPS
|
||||
proxy variables are indeed under the manual.https_proxy group.
|
||||
|
||||
I should explain this clearly, ensuring the user understands where these variables fall within the overall structure. Also, I'll offer further assistance in case they need more details
|
||||
about any of the variables.
|
||||
...done thinking.
|
||||
|
||||
|
||||
|
||||
The HTTPS Proxy variables are organized under the **`manual.https_proxy`** group. This group contains the variables and their configurations for setting up an HTTPS proxy.
|
||||
|
||||
>>> Send a message (/? for help)
|
||||
54
tests/ai_output.md.old
Normal file
54
tests/ai_output.md.old
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<think>
|
||||
Okay, let's see what this user is asking for. They want me to create a YAML schema based on their input about setting a proxy in Mozilla Firefox. First, they mention they're trying to configure a proxy and have different options like no proxy, auto-detect, system settings, etc., with default being 'No proxy'.
|
||||
|
||||
In the second example provided by another user, it's similar but focuses more on the variable choices in setting up proxies. The output schema includes variables with descriptions, types, choices, and defaults.
|
||||
|
||||
Now, looking at the current interaction: The user is trying to set a proxy in Firefox. They've chosen the manual mode. The address specified isn't clear initially; it says '192.168.230.4 not' which seems like an error or unclear syntax. The port they're setting is 8080.
|
||||
|
||||
So, I need to create a YAML schema based on this scenario. Since the user is choosing between different proxy configurations and has specific settings for address and port, but there's some confusion with the address part, perhaps that needs clarification. However, the main choices are already outlined in the first example.
|
||||
|
||||
I'll structure the schema similarly: include variables like proxy_mode, proxy_address, proxy_port, etc., each with appropriate descriptions and types. The default choice is 'No proxy', as per the user's example.
|
||||
|
||||
But wait, there's confusion about the proxy_address being '192.168.230.4 not'. Maybe it should be '192.168.230.4' without the 'not'. Also, perhaps the address is optional or needs more details, but for simplicity, I'll proceed with what's given.
|
||||
|
||||
I need to make sure each choice has a description and that default values are included as specified in the schema example. So, variables like proxy_address, proxy_port, etc., will be defined with their respective descriptions, types (like string), choices, and defaults.
|
||||
|
||||
Finally, ensure the YAML is properly formatted and enclosed within triple backticks for code-like structure.
|
||||
</think>
|
||||
|
||||
```yaml
|
||||
---
|
||||
proxy_mode:
|
||||
description: Configure Proxy Access to the Internet
|
||||
type: choice
|
||||
default: No proxy
|
||||
|
||||
proxy_address:
|
||||
description: IP address where proxy will be configured
|
||||
type: string
|
||||
required: true
|
||||
choices:
|
||||
- 192.168.230.4
|
||||
- 10.100.200.50
|
||||
|
||||
proxy_port:
|
||||
description: Port number for proxy configuration
|
||||
type: integer
|
||||
default: 8080
|
||||
|
||||
default:
|
||||
description: Default value for all variables
|
||||
type: choice
|
||||
choices:
|
||||
- No proxy
|
||||
```
|
||||
|
||||
### Explanation:
|
||||
|
||||
- **proxy_mode**: This variable defines the primary configuration mode, such as 'No proxy', 'Auto-detect...', or other options. The default is set to 'No proxy'.
|
||||
|
||||
- **proxy_address**: This field specifies the IP address where the proxy will be configured. It has a required type and optional choices.
|
||||
|
||||
- **proxy_port**: Specifies the port number for proxy configuration. A default value of 8080 is provided, though it can be adjusted based on user needs.
|
||||
|
||||
This schema provides a structured way to handle proxy configurations, allowing users to choose from predefined options with specific settings.
|
||||
9
tests/explanation.txt
Normal file
9
tests/explanation.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
### Explanation:
|
||||
|
||||
- **proxy_mode**: This variable defines the primary configuration mode, such as 'No proxy', 'Auto-detect...', or other options. The default is set to 'No proxy'.
|
||||
|
||||
- **proxy_address**: This field specifies the IP address where the proxy will be configured. It has a required type and optional choices.
|
||||
|
||||
- **proxy_port**: Specifies the port number for proxy configuration. A default value of 8080 is provided, though it can be adjusted based on user needs.
|
||||
|
||||
This schema provides a structured way to handle proxy configurations, allowing users to choose from predefined options with specific settings.
|
||||
24
tests/rougail.yaml
Normal file
24
tests/rougail.yaml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
proxy_mode:
|
||||
description: Configure Proxy Access to the Internet
|
||||
type: choice
|
||||
default: No proxy
|
||||
|
||||
proxy_address:
|
||||
description: IP address where proxy will be configured
|
||||
type: string
|
||||
required: true
|
||||
choices:
|
||||
- 192.168.230.4
|
||||
- 10.100.200.50
|
||||
|
||||
proxy_port:
|
||||
description: Port number for proxy configuration
|
||||
type: integer
|
||||
default: 8080
|
||||
|
||||
default:
|
||||
description: Default value for all variables
|
||||
type: choice
|
||||
choices:
|
||||
- No proxy
|
||||
18
tests/taskfile.yml
Normal file
18
tests/taskfile.yml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
version: '3'
|
||||
tasks:
|
||||
default:
|
||||
desc: test
|
||||
cmds:
|
||||
- ../ai_output_parser --think ai_output.md > think.txt
|
||||
# - ../ai_output_parser --yaml ai_output.md > rougail.yaml
|
||||
# - ../ai_output_parser --explanation ai_output.md > explanation.txt
|
||||
generates:
|
||||
- think.txt
|
||||
# - rougail.yaml
|
||||
# - explanation.txt
|
||||
|
||||
clean:
|
||||
desc: Suppress generated files
|
||||
cmds:
|
||||
- rm -f {{.GENERATES}}
|
||||
|
||||
17
tests/think.txt
Normal file
17
tests/think.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Alright, the user is asking about the HTTPS proxy variables. They want to know the variable names related to HTTPS proxy setup.
|
||||
|
||||
Looking at the markdown, I need to find the section under the "proxy_mode" variable that's specifically for HTTPS.
|
||||
|
||||
I see a section labeled "HTTPS Proxy" which is under the "manual" path. This section contains the details about the variables used for HTTPS proxy configuration.
|
||||
|
||||
Now, I should list each variable and its description. The variables mentioned are:
|
||||
|
||||
1. manual.https_proxy.address: This is the HTTPS proxy address. It's mandatory and can be an IP address or a domain name.
|
||||
|
||||
2. manual.https_proxy.port: This sets the HTTPS proxy port. It's mandatory and can be any well-known, registered, or private port. The default is 8080, but it's set to the same as the
|
||||
HTTP proxy port if not specified.
|
||||
|
||||
3. manual.use_for_https: This is a boolean variable that determines if the proxy should be used for HTTPS traffic. It's mandatory and defaults to true.
|
||||
|
||||
I should present these variables clearly, explaining each one's purpose and default values. This way, the user can understand how to configure their HTTPS proxy settings based on the
|
||||
documentation.
|
||||
Loading…
Reference in a new issue