Skip to content

Add dev container to open in GitHub Codespace #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .devcontainer/addcodespacename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, we can update the file to have $host placeholder and then replace with host header. For codespaces, the original host is in x-forwarded-host.

  "api": {
    "type": "openapi",
    "is_user_authenticated": "false",
    "url": "$host/.well-known/openapi.yaml"
  },
  "logo_url": "$host/.well-known/logo.png",
  
@app.get("/.well-known/ai-plugin.json")
async def plugin_manifest(request: Request):
    """
    Returns the ai-plugin.json from .well-known location
    """

    host_header = request.headers.get("X-Forwarded-Host") or request.headers.get("Host")

    with open(".well-known/ai-plugin.json") as f:
        return Response(
            content=Template(f.read()).substitute(host=f"https://{host_header}"),
            media_type="application/json",
        )


# Determine the value of SITE_HOST based on whether the project is opened in a Codespace
if [ -z ${CODESPACE_NAME+x} ]; then
SITE_HOST="http://localhost:5003"
else
SITE_HOST="https://${CODESPACE_NAME}-5003.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"
fi

# Replace "localhost:5003" with the value of SITE_HOST in the ai-plugin.json file
sed -i "s#http://localhost:5003#${SITE_HOST}#g" .well-known/ai-plugin.json

# Replace "localhost:5003" with the value of SITE_HOST in the openapi.yaml file
sed -i "s#http://localhost:5003#${SITE_HOST}#g" openapi.yaml
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/universal:2",
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
5003
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install -r requirements.txt",
"postAttachCommand": ".devcontainer/addcodespacename.sh && python main.py",
"customizations": {
"codespaces": {
"openFiles": [
".well-known/ai-plugin.json",
"openapi.yaml"
]
}
}
}
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Get a Todo list ChatGPT plugin up and running in under 5 minutes using Python. If you do not already have plugin developer access, please [join the waitlist](https://openai.com/waitlist/plugins).

## Setup
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/openai/plugins-quickstart?devcontainer_path=/.devcontainer/basics/devcontainer.json)

## Local Setup

To install the required packages for this plugin, run the following command:

Expand All @@ -24,6 +26,34 @@ Once the local server is running:
4. Select "Develop your own plugin"
5. Enter in `localhost:5003` since this is the URL the server is running on locally, then select "Find manifest file".

The plugin should now be installed and enabled! You can start with a question like "What is on my todo list" and then try adding something to it as well!

## GitHub CodeSpaces Setup
_A codespace is a development environment that's hosted in the cloud. You can build and run this plugin via a GitHub Codespace by following the directions below:_

1. Open this environment in a GitHub Codespace by choosing "Use this template" > "Open in Codespace" as pictured below.
<img width="191" alt="Green button titled use this template with dropdown options of create new repository and open in codespace" src="https://user-images.githubusercontent.com/22990146/235506864-7be45716-4b61-4986-97b1-e69e3f3a4df4.png">

2. Allow the Codespace a few minutes to finish installing all necessary dependencies. It may take awhile, but keep in mind that GitHub Codespaces is running all the install commands, so you don't have to.

3. Once everything is installed, you should see that a forwarded port is now running the plugin. **Set the port visibility to public.**
<img width="1412" alt="Choosing public port visibility for forwarded port" src="https://user-images.githubusercontent.com/22990146/235510002-1a9ef89b-e12c-4145-8119-45daed452028.png">

4. Copy the forwarded port's local address. It should follow this naming convention

`https://<GITHUB_USER_HANDLE>-<RANDOMLY_GENERATED_PHRASE>-<RANDOMLY_GENERATED_ALPHANUMERIC_STRING>-5003.preview.app.github.dev`

5. Navigate to https://chat.openai.com.

6. In the Model drop down, select "Plugins" (note, if you don't see it there, you don't have access yet).

7. Select "Plugin store"

8. Select "Develop your own plugin"

9. Enter in the local address to your forwarded port (the one you copied in Step 3), then select "Find manifest file".


The plugin should now be installed and enabled! You can start with a question like "What is on my todo list" and then try adding something to it as well!

## Getting help
Expand Down