From 1b8977d62151495f52d076c9aebc8af0a90ca345 Mon Sep 17 00:00:00 2001
From: Jan Frenzel <jan.frenzel@tu-dresden.de>
Date: Wed, 21 Aug 2024 18:04:39 +0200
Subject: [PATCH] Improve summarize example instructions in README.md

---
 summarize/README.md    |  2 +-
 summarize/summarize.py | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/summarize/README.md b/summarize/README.md
index c978a9a..527f160 100644
--- a/summarize/README.md
+++ b/summarize/README.md
@@ -18,7 +18,7 @@ pip install -r requirements.txt
 
 ## Usage
 
-1. Put your API key in the file `my_key`.
+1. Create a file `my_key` and put your API key in the file. For security reasons API Key is necessary. You have to obtain the API Key from the llm.scads.ai team. You can find instructions on https://llm.scads.ai/ .
 2. Then start the script `main.py` from your bash shell and provide a plain text file:
 
 ```bash
diff --git a/summarize/summarize.py b/summarize/summarize.py
index e049965..2050899 100755
--- a/summarize/summarize.py
+++ b/summarize/summarize.py
@@ -3,8 +3,13 @@
 import sys
 from openai import OpenAI
 my_api_key = ""
-with open("my_key") as keyfile:
-    my_api_key = keyfile.readline()[:-1]
+try:
+    with open("my_key") as keyfile:
+        my_api_key = keyfile.readline().strip()
+except FileNotFoundError:
+    print("Error: The file 'my_key' was not found. Please make sure the file exists and contains your API key.")
+    exit(1)
+
 
 client = OpenAI(base_url="https://llm.scads.ai/v1",api_key=my_api_key)
 
@@ -43,7 +48,7 @@ response = client.chat.completions.create(
     max_tokens = 2048 # longer answer
 )
 
-# Print the joke
+# Print the summary
 print("""
 Summary:
 """)
-- 
GitLab