Skip to content

Commit

Permalink
change env
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdev committed Mar 3, 2023
1 parent 6a0c9b1 commit 0c9c70d
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
OPENAI_API_KEY=
OPENAI_API_KEY=

# 如官方地址服务访问可配置反向代理
OPENAI_API_URL=https://api.openai.com
34 changes: 16 additions & 18 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { defineConfig } from 'astro/config'
import vercel from '@astrojs/vercel/edge'
import unocss from 'unocss/astro'
import { presetUno } from 'unocss'
import presetAttributify from '@unocss/preset-attributify'
import presetTypography from '@unocss/preset-typography'
import solidJs from '@astrojs/solid-js'
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/edge';
import unocss from 'unocss/astro';
import { presetUno } from 'unocss';
import presetAttributify from '@unocss/preset-attributify';
import presetTypography from '@unocss/preset-typography';
import solidJs from '@astrojs/solid-js';

// https://astro.build/config
import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
integrations: [
unocss({
presets: [
presetAttributify(),
presetUno(),
presetTypography(),
]
}),
solidJs()
],
integrations: [unocss({
presets: [presetAttributify(), presetUno(), presetTypography()]
}), solidJs()],
output: 'server',
adapter: vercel()
adapter: node({
mode: "standalone"
})
});
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
app:
image: node:18
restart: always
ports:
- "9002:3000"
volumes:
- .:/app
entrypoint: bash -c "cd /app && HOST=0.0.0.0 PORT=3000 node ./dist/server/entry.mjs"
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"dev": "astro dev --host=0.0.0.0",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "^5.0.4",
"@astrojs/solid-js": "^2.0.2",
"@astrojs/vercel": "^3.1.3",
"@unocss/reset": "^0.50.1",
Expand All @@ -29,4 +30,4 @@
"punycode": "^2.3.0",
"unocss": "^0.50.1"
}
}
}
131 changes: 131 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { APIRoute } from 'astro'
import { createParser, ParsedEvent, ReconnectInterval } from 'eventsource-parser'

const apiKey = import.meta.env.OPENAI_API_KEY
const apiUrl = import.meta.env.OPENAI_API_URL

export const post: APIRoute = async (context) => {
const body = await context.request.json()
Expand All @@ -13,7 +14,7 @@ export const post: APIRoute = async (context) => {
return new Response('No input text')
}

const completion = await fetch('https://api.openai.com/v1/chat/completions', {
const completion = await fetch(`${apiUrl}/v1/chat/completions`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
Expand Down Expand Up @@ -47,7 +48,7 @@ export const post: APIRoute = async (context) => {
// ],
// }
const json = JSON.parse(data)
const text = json.choices[0].delta?.content
const text = json.choices[0].delta?.content
const queue = encoder.encode(text)
controller.enqueue(queue)
} catch (e) {
Expand Down

0 comments on commit 0c9c70d

Please sign in to comment.