From fa99b6c3404a03e1ba4fae13e1fca3d021483f2e Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 1 Apr 2023 18:37:55 -0700 Subject: [PATCH] Suppress some warnings --- llm/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llm/cli.py b/llm/cli.py index 223ac09..4bafe1b 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -5,6 +5,9 @@ import openai import os import sqlite_utils import sys +import warnings + +warnings.simplefilter("ignore", ResourceWarning) CODE_SYSTEM_PROMPT = """ You are a code generating tool. Return just the code, with no explanation @@ -90,7 +93,8 @@ def get_openai_api_key(): path = os.path.expanduser("~/.openai-api-key.txt") # If the file exists, read it if os.path.exists(path): - return open(path).read().strip() + with open(path) as fp: + return fp.read().strip() raise click.ClickException( "No OpenAI API key found. Set OPENAI_API_KEY environment variable or create ~/.openai-api-key.txt" )