Commit 269d7628 authored by Jiabo Li's avatar Jiabo Li
Browse files

Put API key file in the fixed .PyMOL folder in the home directory to avoid...

Put API key file in the fixed .PyMOL folder in the home directory to avoid permission issues. Also fixed a bug for conversation history. Use gloable flag in start_chatgpt_cmd
parent aa3aa701
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ The PyMOL ChatGPT Plugin seamlessly integrates OpenAI's GPT-3.5-turbo model into
1. Download the plugin script `chatmol.py` and save it to a convenient location on your computer.
2. Open PyMOL.
3. In the PyMOL command line, enter `run /path/to/chatmol.py` (replace `/path/to` with the actual path to the script).
4. The plugin is now installed and ready to use.
4. Create a .PyMOL folder in your home director for saving PyMOL related files, like ChatGPT API keys, PyMOL license file etc.
5. The plugin is now installed and ready to use.

Alternatively, you can use the following command to load the plugin directly:

+6 −2
Original line number Diff line number Diff line
@@ -6,13 +6,14 @@ import os
conversation_history = " "    
stashed_commands = []

PLUGIN_DIR = os.path.dirname(os.path.abspath(__file__))
API_KEY_FILE = os.path.join(PLUGIN_DIR, "apikey.txt")
# Save API Key in ~/.PyMOL/apikey.txt
API_KEY_FILE = os.path.expanduser('~')+"/.PyMOL/apikey.txt"
OPENAI_KEY_ENV = "OPENAI_API_KEY"

def set_api_key(api_key):
    api_key = api_key.strip()
    openai.api_key = api_key
    print("APIKEYFILE = ",API_KEY_FILE)
    try:
        with open(API_KEY_FILE, "w") as api_key_file:
            api_key_file.write(api_key)
@@ -22,6 +23,7 @@ def set_api_key(api_key):

def load_api_key():
    api_key = os.getenv(OPENAI_KEY_ENV)
    print("APIKEYFILE = ",API_KEY_FILE)
    if not api_key:
        try:
            with open(API_KEY_FILE, "r") as api_key_file:
@@ -66,6 +68,8 @@ def chat_with_gpt(message):

def start_chatgpt_cmd(message, execute:bool=True):
    global stashed_commands
    global conversation_history

    message = message.strip()
    execution = True
    if (message[-1] == '?'):