Skip to content

Instantly share code, notes, and snippets.

@collabnix
Created March 19, 2023 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save collabnix/4d960207ca04f6daf63a810f249e7a59 to your computer and use it in GitHub Desktop.
Save collabnix/4d960207ca04f6daf63a810f249e7a59 to your computer and use it in GitHub Desktop.
Docker Diagnostic Tool Integrated with ChatGPT
import subprocess
import re
import openai
openai.api_key = "sk-peVXXXXXXXg8PPY0QuCYKPT"
def run_diagnose_tool():
# Run the Docker Desktop self-diagnose tool and capture the output
tool_location = "/Applications/Docker.app/Contents/MacOS/com.docker.diagnose"
result = subprocess.run([tool_location, "check"], stdout=subprocess.PIPE)
output = result.stdout.decode()
# Extract the results from the output
pattern = r"\[\s*(\w+)\s*\]\s*(\w+)"
matches = re.findall(pattern, output)
# Convert the results to a dictionary
results = {}
for match in matches:
status = match[0]
check_name = match[1]
if status == "PASS":
results[check_name] = True
else:
results[check_name] = False
return results
def analyze_results(results):
# Use ChatGPT to analyze the results and provide recommendations
for check_name, status in results.items():
if not status:
prompt = f"I see that {check_name} has failed. What should the user do?"
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=50,
n=1,
stop=None,
temperature=0.5
)
recommendation = response.choices[0].text.strip()
print(f"{check_name} has failed. Recommendation: {recommendation}")
if __name__ == "__main__":
results = run_diagnose_tool()
analyze_results(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment