diff --git a/README.md b/README.md index 0c916c7..ab728e3 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,9 @@ This Artificially Assisted User Interface Testing framework is a pioneering tool # Installation ``` # Add your Chat-GPT API Keys to the project: -add your API Key in /core/core_api.py -> line 3: client = OpenAI(api_key='insert_your_api_key_here') -add your API Key in /core/core_imaging.py -> line 12: api_key = 'insert_your_api_key_here' +Create a .env file with your API Key in the project folder +and add your key like this: OPENAI_API_KEY=sk-pr.... + # Install requirements: cd pywinassistant diff --git a/core/core_api.py b/core/core_api.py index cb3cf5d..2a79647 100644 --- a/core/core_api.py +++ b/core/core_api.py @@ -1,10 +1,15 @@ +import os +from dotenv import load_dotenv from openai import OpenAI -client = OpenAI(api_key='insert_your_api_key_here') +load_dotenv() + +openai_api_key = os.getenv('OPENAI_API_KEY') + +client = OpenAI(api_key=openai_api_key) # Available models: "gpt-4-1106-preview", "gpt-3.5-turbo-1106", or "davinci-codex" MODEL_NAME = "gpt-3.5-turbo-1106" - def api_call(messages, model_name=MODEL_NAME, temperature=0.5, max_tokens=150): # if model_name == "gpt-4-1106-preview": # model_name = "gpt-3.5-turbo-1106" diff --git a/core/core_imaging.py b/core/core_imaging.py index b94e20d..c4c67a8 100644 --- a/core/core_imaging.py +++ b/core/core_imaging.py @@ -2,14 +2,16 @@ import pygetwindow as gw import base64 import requests +import os import io from PIL import Image +from dotenv import load_dotenv # Assuming that the `activate_window_title` function is defined in another module correctly from window_focus import activate_windowt_title # OpenAI API Key -api_key = 'insert_your_api_key_here' +openai_api_key = os.getenv('OPENAI_API_KEY') # Function to focus a window given its title @@ -47,7 +49,7 @@ def analyze_image(base64_image, window_title, additional_context='What’s in th # Your logic to call the OpenAI API headers = { "Content-Type": "application/json", - "Authorization": f"Bearer {api_key}" + "Authorization": f"Bearer {openai_api_key}" } payload = { diff --git a/requirements.txt b/requirements.txt index 3bde5f1..51375b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ uiautomation gtts pygame pyAudio +python-dotenv \ No newline at end of file