Skip to content

Commit ec7d098

Browse files
authored
Merge pull request #64 from dasmy/dev/models_selection
Dev/models selection
2 parents 980b4b9 + e4ace46 commit ec7d098

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

.env.azure-example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ OPENAI_API_TYPE=azure
33
OPENAI_BASE_URL=https://your-resource-name.openai.azure.com
44
OPENAI_API_VERSION=2023-03-15-preview
55
# OPENAI_EXTRA_HEADERS={"key": "value"}
6-
AZURE_OPENAI_DEPLOYMENT=your-model-deployment-name
6+
AZURE_OPENAI_DEPLOYMENTS=[{"displayName": "GPT-3.5", "name": "your-gpt-3.5-deployment"}, {"displayName": "GPT-4", "name": "your-gpt-4-deployment"}]
7+
# OPENAI_API_LOGLEVEL=debug
78
API_PORT=5010
89
WEB_PORT=8080
910
SNAKEMQ_PORT=8765

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ OPENAI_API_TYPE=openai
33
OPENAI_BASE_URL=https://api.openai.com
44
OPENAI_API_VERSION=2023-03-15-preview
55
# OPENAI_EXTRA_HEADERS={"key": "value"}
6+
OPENAI_MODELS=[{"displayName": "GPT-3.5", "name": "gpt-3.5-turbo"}, {"displayName": "GPT-4", "name": "gpt-4"}]
7+
# OPENAI_API_LOGLEVEL=debug
68
API_PORT=5010
79
WEB_PORT=8080
810
SNAKEMQ_PORT=8765

frontend/src/App.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import "./App.css";
22
import Input from "./components/Input";
33
import Sidebar from "./components/Sidebar";
44
import Chat, { WaitingStates } from "./components/Chat";
5-
import React, { useState } from "react";
5+
import React, { useState, useEffect } from "react";
66
import Config from "./config";
77
import { useLocalStorage } from "usehooks-ts";
88

@@ -14,16 +14,22 @@ export type MessageDict = {
1414

1515
function App() {
1616
const COMMANDS = ["reset"];
17-
const MODELS = [
18-
{
19-
displayName: "GPT-3.5",
20-
name: "gpt-3.5-turbo",
21-
},
22-
{
23-
displayName: "GPT-4",
24-
name: "gpt-4",
25-
},
26-
];
17+
18+
let [MODELS, setModels] = useState([{displayName: "GPT-3.5", name: "gpt-3.5-turbo"}]);
19+
20+
useEffect(() => {
21+
const getModels = async () => {
22+
try {
23+
const response = await fetch(`${Config.WEB_ADDRESS}/models`);
24+
const json = await response.json();
25+
setModels(json);
26+
} catch (e) {
27+
console.error(e);
28+
};
29+
};
30+
31+
getModels();
32+
}, []);
2733

2834
let [selectedModel, setSelectedModel] = useLocalStorage<string>(
2935
"model",

gpt_code_ui/webapp/main.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# The GPT web UI as a template based Flask app
22
import os
33
import requests
4-
import json
54
import asyncio
5+
import json
66
import re
77
import logging
88
import sys
@@ -24,9 +24,18 @@
2424
openai.api_version = os.environ.get("OPENAI_API_VERSION", "2023-03-15-preview")
2525
openai.api_key = os.environ.get("OPENAI_API_KEY", "")
2626
openai.log = os.getenv("OPENAI_API_LOGLEVEL", "")
27-
AZURE_OPENAI_DEPLOYMENT = os.environ.get("AZURE_OPENAI_DEPLOYMENT", "")
2827
OPENAI_EXTRA_HEADERS = json.loads(os.environ.get("OPENAI_EXTRA_HEADERS", "{}"))
2928

29+
if openai.api_type == "openai":
30+
AVAILABLE_MODELS = json.loads(os.environ.get("OPENAI_MODELS", '''[{"displayName": "GPT-3.5", "name": "gpt-3.5-turbo"}, {"displayName": "GPT-4", "name": "gpt-4"}]'''))
31+
elif openai.api_type == "azure":
32+
try:
33+
AVAILABLE_MODELS = json.loads(os.environ["AZURE_OPENAI_DEPLOYMENTS"])
34+
except KeyError as e:
35+
raise RuntimeError('AZURE_OPENAI_DEPLOYMENTS environment variable not set') from e
36+
else:
37+
raise ValueError(f'Invalid OPENAI_API_TYPE: {openai.api_type}')
38+
3039
UPLOAD_FOLDER = 'workspace/'
3140
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
3241

@@ -132,7 +141,7 @@ async def get_code(user_prompt, user_openai_key=None, model="gpt-3.5-turbo"):
132141
if openai.api_type == 'openai':
133142
arguments["model"] = model
134143
elif openai.api_type == 'azure':
135-
arguments["deployment_id"] = AZURE_OPENAI_DEPLOYMENT
144+
arguments["deployment_id"] = model
136145
else:
137146
return None, f"Error: Invalid OPENAI_PROVIDER: {openai.api_type}", 500
138147

@@ -197,6 +206,11 @@ def index():
197206
return send_from_directory('static', 'index.html')
198207

199208

209+
@app.route("/models")
210+
def models():
211+
return jsonify(AVAILABLE_MODELS)
212+
213+
200214
@app.route('/api/<path:path>', methods=["GET", "POST"])
201215
def proxy_kernel_manager(path):
202216
if request.method == "POST":

0 commit comments

Comments
 (0)