File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,12 +8,10 @@ export interface State {
88 models ?: ModelsResponse
99 vsCodeVersion ?: string
1010
11- estimateToken : boolean
1211 manualApprove : boolean
1312}
1413
1514export const state : State = {
1615 accountType : "individual" ,
17- estimateToken : true ,
1816 manualApprove : false ,
1917}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { countTokens } from "gpt-tokenizer/model/gpt-4o"
22
33import type { Message } from "~/services/copilot/create-chat-completions"
44
5- export const getTokenLength = ( messages : Array < Message > ) => {
5+ export const getTokenCount = ( messages : Array < Message > ) => {
66 const input = messages . filter ( ( m ) => m . role !== "assistant" )
77 const output = messages . filter ( ( m ) => m . role === "assistant" )
88
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ interface RunServerOptions {
1515 port: number
1616 verbose: boolean
1717 business: boolean
18+ manual: boolean
1819}
1920
2021export async function runServer ( options : RunServerOptions ) : Promise < void > {
@@ -28,6 +29,8 @@ export async function runServer(options: RunServerOptions): Promise<void> {
2829 consola . info ( "Using business plan GitHub account" )
2930 }
3031
32+ state . manualApprove = options . manual
33+
3134 await ensurePaths ( )
3235 await cacheVSCodeVersion ( )
3336 await setupGitHubToken ( )
@@ -62,6 +65,11 @@ const main = defineCommand({
6265 default : false ,
6366 description : "Use a business plan GitHub Account" ,
6467 } ,
68+ manual : {
69+ type : "boolean" ,
70+ default : false ,
71+ description : "Enable manual request approval" ,
72+ } ,
6573 } ,
6674 run ( { args } ) {
6775 const port = Number . parseInt ( args . port , 10 )
@@ -70,6 +78,7 @@ const main = defineCommand({
7078 port,
7179 verbose : args . verbose ,
7280 business : args . business ,
81+ manual : args . manual ,
7382 } )
7483 } ,
7584} )
Original file line number Diff line number Diff line change 11import type { Context } from "hono"
22
3+ import consola from "consola"
34import { streamSSE , type SSEMessage } from "hono/streaming"
45
56import { isNullish } from "~/lib/is-nullish"
67import { state } from "~/lib/state"
8+ import { getTokenCount } from "~/lib/tokenizer"
79import {
810 createChatCompletions ,
911 type ChatCompletionResponse ,
@@ -13,6 +15,16 @@ import {
1315export async function handleCompletion ( c : Context ) {
1416 let payload = await c . req . json < ChatCompletionsPayload > ( )
1517
18+ consola . info ( "Current token count:" , getTokenCount ( payload . messages ) )
19+
20+ if ( state . manualApprove ) {
21+ const response = await consola . prompt ( `Accept incoming request?` , {
22+ type : "confirm" ,
23+ } )
24+
25+ if ( ! response ) throw new Error ( "Request cancelled" )
26+ }
27+
1628 if ( isNullish ( payload . max_tokens ) ) {
1729 const selectedModel = state . models ?. data . find (
1830 ( model ) => model . id === payload . model ,
You can’t perform that action at this time.
0 commit comments