Skip to content

Commit 4db1e47

Browse files
committed
feat: Rename ENABLE_STREAMING to EMULATE_STREAMING in config and CLI
1 parent 63051ae commit 4db1e47

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/config/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ const GITHUB_OAUTH_SCOPES = [
1111
export const ENV = {
1212
GITHUB_CLIENT_ID,
1313
GITHUB_OAUTH_SCOPES,
14-
ENABLE_STREAMING: false,
14+
EMULATE_STREAMING: false,
1515
}

src/lib/cli.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ const args = {
77
default: false,
88
description: "Show this help message",
99
},
10-
stream: {
11-
alias: "s",
10+
"emulate-streaming": {
1211
type: "boolean",
13-
default: true,
14-
// citty will automatically convert this to --no-stream
15-
description: "Disable streaming response for chat completions",
12+
default: false,
13+
description: "Emulate streaming response for chat completions",
1614
},
1715
port: {
1816
alias: "p",
@@ -29,7 +27,14 @@ export interface CliOptions {
2927
}
3028

3129
export async function parseCli() {
32-
const command = defineCommand({ args })
30+
const command = defineCommand({
31+
args,
32+
meta: {
33+
name: "copilot-api",
34+
description:
35+
"A wrapper around GitHub Copilot API to make it OpenAI compatible, making it usable for other tools.",
36+
},
37+
})
3338
const options = parseArgs<typeof args>(Bun.argv, args)
3439

3540
if (options.help) {

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { initialize } from "./lib/initialization"
66
import { server } from "./server"
77

88
const options = await parseCli()
9-
ENV.ENABLE_STREAMING = options.stream
9+
ENV.EMULATE_STREAMING = options["emulate-streaming"]
1010

1111
await initialize()
1212

src/routes/chat-completions/route.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ export const completionRoutes = new Hono()
1111

1212
completionRoutes.post("/chat/completions", (c) => {
1313
try {
14-
if (ENV.ENABLE_STREAMING) {
15-
return handlerStreaming(c)
16-
} else {
14+
if (ENV.EMULATE_STREAMING) {
1715
return handler(c)
16+
} else {
17+
return handlerStreaming(c)
1818
}
1919
} catch (error) {
2020
if (error instanceof FetchError) {
2121
consola.error(`Request failed: ${error.message}`, error.response?._data)
2222
}
23+
consola.error(error)
24+
2325
throw error
2426
}
2527
})

0 commit comments

Comments
 (0)