From 26f239616798ecc7e0c48ed3d27b649e267a231d Mon Sep 17 00:00:00 2001 From: Thomas Arnaud Date: Wed, 13 Nov 2024 10:12:55 +0100 Subject: [PATCH 1/2] add pop querier bash script and prefere usage of docker-compose than docker compose which isn-t available everywhere yet --- README.md | 10 +++++----- scripts/pop.sh | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100755 scripts/pop.sh diff --git a/README.md b/README.md index ff34c66..314a1b6 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ git clone https://github.com/centreonlabs/plugin-output-processing.git cd plugin-output-processing -docker compose --profile ollama up +docker-compose --profile ollama up ``` After the container is up, you can try the API at `http://localhost:8000/docs`. @@ -82,7 +82,7 @@ This method requires an [OpenAI API key](https://help.openai.com/en/articles/493 ```bash export OPENAI_API_KEY=... -docker compose up +docker-compose up ``` After the container is up, you can try the API the same way as the previous section. @@ -92,17 +92,17 @@ After the container is up, you can try the API the same way as the previous sect > If you want to use the OpenAI API, you must unset the `OLLAMA_HOST` if it exists and can reach an ollama instance. > [!CAUTHION] -> If you want to switch between providers (OpenAI to Ollama or vice versa), you must change the configuration file or removing it. +> If you want to switch between providers (OpenAI to Ollama or vice versa), you must change the configuration file or remove it. ```bash # Example to switch from OpenAI to Ollama -docker compose down +docker-compose down docker volume rm pop_pop # We need to recreate the network because ollama will start first. -docker compose --profile ollama up --force-recreate +docker-compose --profile ollama up --force-recreate ``` ### Running the API locally diff --git a/scripts/pop.sh b/scripts/pop.sh new file mode 100755 index 0000000..1409bf3 --- /dev/null +++ b/scripts/pop.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# This script prompts the user to input plugin output text, URL encodes the input, +# and sends it to a specified API endpoint for explanation. The response from the +# API is then formatted and displayed to the user. + +# Prompt the user to input text +read -p "Enter plugin output you want to be explained: " input_text + +echo +echo "----------" +echo + +# URL encode the input text +encoded_text=$(echo -n "$input_text" | jq -s -R -r @uri) + +# Define the API endpoint, replacing YOUR_API_ENDPOINT with the actual endpoint +api_endpoint="http://127.0.0.1:8000/explain" + +# Make the GET request +response=$(curl -s "${api_endpoint}?type=service&output=${encoded_text}") + +# replace return carriage and display the response +echo $response | sed 's/\\n/\n/g' From 3b0d99419125c589052257ffc1dbcad5c9382204 Mon Sep 17 00:00:00 2001 From: Thomas Arnaud <38663853+Nohzoh@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:08:29 +0100 Subject: [PATCH 2/2] remove useless comment --- scripts/pop.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/pop.sh b/scripts/pop.sh index 1409bf3..6914336 100755 --- a/scripts/pop.sh +++ b/scripts/pop.sh @@ -14,7 +14,6 @@ echo # URL encode the input text encoded_text=$(echo -n "$input_text" | jq -s -R -r @uri) -# Define the API endpoint, replacing YOUR_API_ENDPOINT with the actual endpoint api_endpoint="http://127.0.0.1:8000/explain" # Make the GET request