feat: add basic ui

This commit is contained in:
Yidadaa
2023-03-10 01:01:40 +08:00
parent 0decdb3e43
commit d49b2aa2c3
26 changed files with 4500 additions and 463 deletions

1
app/api/chat/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
config.ts

35
app/api/chat/route.ts Normal file
View File

@@ -0,0 +1,35 @@
import { OpenAIApi, Configuration } from "openai";
import { apiKey } from "./config";
// set up openai api client
const config = new Configuration({
apiKey,
});
const openai = new OpenAIApi(config);
export async function GET(req: Request) {
try {
const completion = await openai.createChatCompletion(
{
messages: [
{
role: "user",
content: "hello",
},
],
model: "gpt-3.5-turbo",
},
{
proxy: {
protocol: "socks",
host: "127.0.0.1",
port: 7890,
},
}
);
return new Response(JSON.stringify(completion.data));
} catch (e) {
return new Response(JSON.stringify(e));
}
}

7
app/api/chat/typing.ts Normal file
View File

@@ -0,0 +1,7 @@
import type {
CreateChatCompletionRequest,
CreateChatCompletionResponse,
} from "openai";
export type ChatRequest = CreateChatCompletionRequest;
export type ChatReponse = CreateChatCompletionResponse;