This repository provides a setup guide for creating OctoAgent, a ChatGPT assistant that responds in simple, clear language. OctoAgent uses OpenAI’s latest models (gpt-4
or gpt-3.5-turbo
) to answer questions interactively in the terminal. Follow these instructions to fork the repository, set up your OpenAI API key using GitHub Codespaces secrets, and run OctoAgent.
- Fork the Repository:
- Click the Fork button at the top-right of this page. This will create a copy of the repository under your GitHub account, allowing you to make changes without affecting the original.
To keep your OpenAI API key secure, we’ll store it as a secret in GitHub. This way, it won’t appear in any code files, and only you will have access to it in your Codespace.
-
Get Your OpenAI API Key:
- Open a new browser tab and go to OpenAI’s API key page.
- Sign in to your OpenAI account or create one if you haven’t already.
- Once signed in, locate the API keys section and click Create new secret key.
- Copy this key (it’s a long string of letters and numbers).
-
Add the API Key as a Codespace Secret:
- Go to your forked repository on GitHub.
- Click on Settings at the top.
- Scroll down to Secrets and variables and select Codespaces secrets.
- Click New repository secret.
- Name the secret
OPENAI_API_KEY
. - Paste your OpenAI API key into the value field.
- Click Add secret to save it.
Now, your API key is securely stored and will automatically be available to your Codespaces session.
-
Open Codespaces:
- Go to your forked repository on GitHub.
- Click the green Code button.
- Select the Codespaces tab.
- Click Create Codespace on main.
This will set up a Codespace, which may take a few moments. Once it’s ready, you’ll see a new page with a code editor and terminal where you can write and run OctoAgent.
In this step, you’ll create the octoagent.py
file, which contains the code for OctoAgent to connect to ChatGPT.
-
Create a New File:
- In your Codespace, look at the File Explorer on the left.
- Right-click and select New File.
- Name the file
octoagent.py
.
-
Add the Code to
octoagent.py
:-
Click on
octoagent.py
to open it. -
Copy and paste the following code into the file:
import os import openai # Load the API key from an environment variable openai.api_key = os.getenv('OPENAI_API_KEY') # Function to ask questions in simple, visual language def ask_chatgpt(query): """ Sends a query to ChatGPT and returns a response in simple, clear language. Parameters: query (str): The question or prompt to send to ChatGPT. Returns: str: The response from ChatGPT in simple, clear language. """ # Style prompt for clarity and simplicity default_style = "Use simple, visual words and clear, straightforward language that paints a picture." styled_query = f"{query}\n\n{default_style}" # Make API call to OpenAI with the latest model (gpt-4 or gpt-3.5-turbo) response = openai.ChatCompletion.create( model="gpt-4", # Use "gpt-3.5-turbo" for a more cost-effective option messages=[ {"role": "user", "content": styled_query} ], max_tokens=500 ) return response.choices[0].message['content'].strip() # Main interactive loop if __name__ == "__main__": while True: query = input("Ask OctoAgent a question (or type 'exit' to quit): ") if query.lower() == "exit": break print(ask_chatgpt(query))
This code:
- Loads your OpenAI API key from the secret environment variable.
- Defines a function,
ask_chatgpt
, that sends a question to ChatGPT, asking it to respond in simple, clear language. - Uses a loop to let you ask multiple questions interactively in the terminal.
-
Now, install the OpenAI library so that OctoAgent can connect to ChatGPT.
-
Install the Library:
- In the Terminal at the bottom of the Codespaces page, click to activate it (you should see a blinking cursor).
- Type the following command to install the OpenAI library:
pip install openai==0.28
- Press Enter to run the command.
This command installs the necessary tools to connect OctoAgent to OpenAI.
-
Run the Code:
- In the Terminal, ensure you’re in the correct folder by typing:
cd octoagent
- Run the code by typing:
python octoagent.py
- Press Enter.
- In the Terminal, ensure you’re in the correct folder by typing:
-
Ask OctoAgent Questions:
- After you start the script, you’ll be prompted with:
Ask OctoAgent a question (or type 'exit' to quit):
. - Type your question and press Enter to receive a response from ChatGPT.
- To exit the loop and stop the program, type
exit
and press Enter.
- After you start the script, you’ll be prompted with:
- OctoAgent connects to OpenAI using your API key (stored securely in Codespaces secrets).
- It sends questions in a style that requests simple, easy-to-understand answers.
- You can modify the question in the
ask_chatgpt()
function inoctoagent.py
to explore different prompts and responses.
- Forked the repository and securely added the OpenAI API key using Codespaces secrets.
- Opened the repository in GitHub Codespaces and installed the OpenAI library.
- Wrote and ran OctoAgent to receive responses in simple language.
Now, every time you run octoagent.py
, it will securely access your API key from Codespaces secrets and connect to ChatGPT for clear and understandable responses.