Skip to content

Commit 076de5d

Browse files
author
Elijah Wilson
committed
getting started stuff
1 parent 8bc7634 commit 076de5d

File tree

7 files changed

+87
-14
lines changed

7 files changed

+87
-14
lines changed

.env.example

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
auth0_domain=https://chatgpt-plugin-demo.us.auth0.com
2+
jwks_url=https://chatgpt-plugin-demo.us.auth0.com/.well-known/jwks.json
3+
domain=https://ff72e324bef5.ngrok.app
4+
openai_verification_token=unset

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,39 @@ This is heavily inspired by [dangermode](https://github.com/rgbkrk/dangermode).
1111
It could have been a fork, but the code is small enough that I started from scratch.
1212

1313
![example](.github/assets/example.png)
14+
15+
## Get Started
16+
17+
### Pre-requisites
18+
19+
1. Auth0 Account Created
20+
2. Auth0 Application Created
21+
3. Auth0 API Created (use `https://example.com/jupychat` as the identifier and audience)
22+
4. Python 3.11+ installed
23+
5. [Poetry](https://python-poetry.org/) installed
24+
6. [Task](https://taskfile.dev/) installed
25+
26+
### Run the FastAPI server
27+
28+
1. Clone this repository
29+
2. `cp .env.example .env`
30+
3. Fill out your auth0 details in `.env`
31+
4. `task serve`
32+
33+
### Configure the plugin
34+
35+
1. To use OAuth, you can't use localhost for the plugin. I recommend using [ngrok](https://ngrok.com).
36+
2. `ngrok http 8000`
37+
3. Copy the ngrok URL and add it to your `.env` as `domain=...`
38+
4. Restart your FastAPI server
39+
5. Copy the ngrok URL and paste it into the ChatGPT plugin UI
40+
6. Copy and paste your Auth0 Application's Client ID and Client Secret into the ChatGPT plugin UI
41+
7. Copy the verification token from the ChatGPT plugin UI and paste it into your `.env` like `openai_verification_token=...`
42+
8. Restart your FastAPI server
43+
44+
### Notes / Caveats
45+
46+
1. Every time you change your `ai-plugin.json`, you need to recreate your plugin in ChatGPT
47+
1. This means you'll get a new verification token too. You'll need to update your `.env` and restart your FastAPI server
48+
2. All kernel state is lost when your FastAPI server restarts. This is sort of a bug, it could be fixed by connecting to any kernels already running in the connections directory.
49+
3. The code getting generated by ChatGPT is mostly lost. It's only saved in the ChatGPT UI. [Noteable's plugin](https://noteable.io/chatgpt-plugin-for-notebook/) writes changes back to your file and you can view it execute in real time.

jupychat/app_utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from jupychat.auth import jwks_client
1010
from jupychat.kernels import get_nb_gpt_kernel_client
1111
from jupychat.routes import api, auth, root
12-
from jupychat.settings import DOMAIN, get_settings
12+
from jupychat.settings import get_settings
1313

1414
static_directory = pathlib.Path(__file__).parent / "static"
1515

@@ -29,10 +29,12 @@ async def lifespan(app: FastAPI):
2929

3030

3131
def build_app():
32+
settings = get_settings()
33+
3234
app = FastAPI(
3335
lifespan=lifespan,
3436
openapi_url="/openapi.json",
35-
servers=[{"url": DOMAIN, "description": "Notebook GPT server"}],
37+
servers=[{"url": settings.domain, "description": "Notebook GPT server"}],
3638
)
3739

3840
app.add_middleware(

jupychat/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from jupyter_client.kernelspec import NATIVE_KERNEL_NAME
66
from pydantic import BaseModel, Field
77

8-
from jupychat.settings import DOMAIN
8+
from jupychat.settings import get_settings
99

1010

1111
class RunCellRequest(BaseModel):
@@ -49,7 +49,7 @@ def store_images(self, dd: DisplayData) -> DisplayData:
4949
image_data = base64.b64decode(dd.data["image/png"])
5050

5151
self.image_store[image_name] = ImageData(
52-
data=image_data, url=f"{DOMAIN}/images/{image_name}"
52+
data=image_data, url=f"{get_settings().domain}/images/{image_name}"
5353
)
5454
dd.data["image/png"] = self.image_store[image_name].url
5555

jupychat/settings.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
1-
import os
21
from functools import lru_cache
32

43
from pydantic import BaseSettings
54

6-
DOMAIN = os.environ.get("JUPYCHAT_DOMAIN", "http://localhost:8000")
7-
85

96
class Settings(BaseSettings):
10-
logo_url: str = f"{DOMAIN}/static/images/logo.png"
11-
openapi_url: str = f"{DOMAIN}/openapi.json"
12-
oauth_client_url: str = f"{DOMAIN}/oauth/authorize"
13-
oauth_authorization_url: str = f"{DOMAIN}/oauth/token"
7+
domain: str = "http://localhost:8000"
8+
9+
@property
10+
def logo_url(self):
11+
return f"{self.domain}/static/images/logo.png"
12+
13+
@property
14+
def openapi_url(self):
15+
return f"{self.domain}/openapi.json"
16+
17+
@property
18+
def oauth_client_url(self):
19+
return f"{self.domain}/oauth/authorize"
20+
21+
@property
22+
def oauth_authorization_url(self):
23+
return f"{self.domain}/oauth/token"
24+
1425
openai_verification_token: str = "unset"
1526

16-
auth0_domain: str = "https://chatgpt-plugin-demo.us.auth0.com"
17-
jwks_url: str = "https://chatgpt-plugin-demo.us.auth0.com/.well-known/jwks.json"
27+
auth0_domain: str
28+
jwks_url: str
1829
jwks_cache_time_sec: int = 300
1930

2031
oauth_audience: str = "https://example.com/jupychat"
2132

2233
jupyter_connection_dir: str = "/tmp/jupychat_connection_files"
2334

35+
class Config:
36+
env_file = ".env"
37+
2438

2539
@lru_cache()
2640
def get_settings():

poetry.lock

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ipython = "^8.13.2"
2121
kernel-sidecar = "^0.5.5"
2222
cryptography = "^40.0.2"
2323
ipykernel = "^6.23.1"
24+
pydantic = {extras = ["dotenv"], version = "^1.10.8"}
2425

2526

2627
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)