parent
0a493294cf
commit
960b2190bf
@ -0,0 +1,58 @@ |
||||
import * as vscode from 'vscode'; |
||||
|
||||
// common data structures and functions
|
||||
|
||||
export type FetchErrorCause = { |
||||
errno: number; |
||||
code: string; |
||||
syscall: string; |
||||
address: string; |
||||
port: number; |
||||
}; |
||||
|
||||
// a summary of the received data
|
||||
export type ResponseData = { |
||||
content: string; |
||||
tokens: number; |
||||
time: number; |
||||
}; |
||||
|
||||
// Show a message notification with a set timeout
|
||||
export async function showMessageWithTimeout(message: string, timeout: number): Promise<void> { |
||||
void vscode.window.withProgress( |
||||
{ |
||||
location: vscode.ProgressLocation.Notification, |
||||
title: message, |
||||
cancellable: false, |
||||
}, |
||||
(progress, token) => { |
||||
token.onCancellationRequested(() => {}); |
||||
|
||||
// This is magic I don't understand
|
||||
const p = new Promise<void>((resolve) => { |
||||
setTimeout(resolve, timeout); |
||||
}); |
||||
return p; |
||||
} |
||||
); |
||||
} |
||||
|
||||
// show a message on the status bar until the promise is resolved
|
||||
export async function showPendingStatusBar( |
||||
message: string, |
||||
operation: Promise<any> |
||||
): Promise<void> { |
||||
void vscode.window |
||||
.withProgress( |
||||
{ |
||||
location: vscode.ProgressLocation.Window, |
||||
title: message, |
||||
}, |
||||
() => operation |
||||
) |
||||
.then( |
||||
(aok) => {}, |
||||
(err) => {} |
||||
); |
||||
// we already resolve the operation elsewhere
|
||||
} |
@ -0,0 +1,116 @@ |
||||
import * as vscode from 'vscode'; |
||||
|
||||
// oogabooga/text-generation-webui OpenAI compatible API
|
||||
// https://github.com/oobabooga/text-generation-webui/wiki/12-%E2%80%90-OpenAI-API
|
||||
|
||||
type OpenAICompletionRequest = { |
||||
model?: string; // automatic
|
||||
prompt: string; |
||||
best_of?: number; // 1
|
||||
echo?: boolean; // false
|
||||
frequency_penalty?: number; // null
|
||||
logit_bias?: object; // null
|
||||
logprobs?: number; // 0
|
||||
max_tokens?: number; // 16
|
||||
n?: number; // 1
|
||||
presence_penalty?: number; // 0
|
||||
stop?: string; |
||||
stream?: boolean; // false
|
||||
suffix?: string; |
||||
temperature?: number; // 1
|
||||
top_p?: number; // 1
|
||||
user?: string; |
||||
preset?: string; |
||||
min_p?: number; // 1
|
||||
top_k?: number; // 1
|
||||
repetition_penalty?: number; // 1
|
||||
repetition_penalty_range?: number; // 1024
|
||||
typical_p?: number; // 1
|
||||
tfs?: number; // 1
|
||||
top_a?: number; // 0
|
||||
epsilon_cutoff?: number; // 0
|
||||
eta_cutoff?: number; // 0
|
||||
guidance_scale?: number; // 1
|
||||
negative_prompt?: string; // ""
|
||||
penalty_alpha?: number; // 0
|
||||
mirostat_mode?: number; // 0
|
||||
mirostat_tau?: number; // 5
|
||||
mirostat_eta?: number; // 0.1
|
||||
temperature_last?: boolean; // false
|
||||
do_sample?: boolean; // true
|
||||
seed?: number; // -1
|
||||
encoder_repetition_penalty?: number; // 1
|
||||
no_repeat_ngram_size?: number; // 0
|
||||
min_length?: number; // 0
|
||||
num_beams?: number; // 1
|
||||
length_penalty?: number; // 1
|
||||
early_stopping?: boolean; // false
|
||||
truncation_length?: number; // 0
|
||||
max_tokens_second?: number; // 0
|
||||
custom_token_bans?: string; // ""
|
||||
auto_max_new_tokens?: boolean; // false
|
||||
ban_eos_token?: boolean; // false
|
||||
add_bos_token?: boolean; // true
|
||||
skip_special_tokens?: boolean; // true
|
||||
grammar_string?: string; // ''
|
||||
}; |
||||
|
||||
type OpenAICompletionSuccessResponse = { |
||||
id: string; |
||||
choices: object[]; |
||||
created?: number; |
||||
model: string; |
||||
object?: string; |
||||
usage: object; |
||||
}; |
||||
|
||||
type OpenAICompletionFailureResponse = { |
||||
detail: { |
||||
loc: (string | number)[]; |
||||
msg: string; |
||||
type: string; |
||||
}[]; |
||||
}; |
||||
|
||||
type OpenAICompletionResponse = OpenAICompletionSuccessResponse | OpenAICompletionFailureResponse; |
||||
|
||||
export function createOpenAIAPIRequest( |
||||
config: vscode.WorkspaceConfiguration, |
||||
doc_before: string, |
||||
doc_after: string |
||||
): OpenAICompletionRequest { |
||||
let request: OpenAICompletionRequest = { |
||||
prompt: '', |
||||
max_tokens: config.get('llamaMaxtokens') as number, |
||||
mirostat_mode: config.get('llamaMirostat') as number, |
||||
repetition_penalty: config.get('llamaRepeatPenalty') as number, |
||||
frequency_penalty: config.get('llamaFrequencyPenalty,') as number, |
||||
presence_penalty: config.get('llamaPresencePenalty,') as number, |
||||
repetition_penalty_range: config.get('llamaRepeatCtx,') as number, |
||||
temperature: config.get('llamaTemperature') as number, |
||||
top_p: config.get('llamaTop_p') as number, |
||||
top_k: config.get('llamaTop_k') as number, |
||||
typical_p: config.get('llamaTypical_p') as number, |
||||
tfs: config.get('llamaTailfree_z,') as number, |
||||
seed: config.get('llamaSeed') as number, |
||||
stream: false, |
||||
}; |
||||
|
||||
const fim = config.get('fimEnabled') as boolean; |
||||
|
||||
if (fim === true) { |
||||
const fim_beg = config.get('fimBeginString') as string; |
||||
const fim_hole = config.get('fimHoleString') as string; |
||||
const fim_end = config.get('fimEndString') as string; |
||||
request.prompt = fim_beg + doc_before + fim_hole + doc_after + fim_end; |
||||
} else { |
||||
request.prompt = doc_before; |
||||
} |
||||
|
||||
return request; |
||||
} |
||||
|
||||
// for now only completions is implemented
|
||||
export function OpenAIAPIRequestEndpoint(config: vscode.WorkspaceConfiguration): string { |
||||
return '/v1/completions'; |
||||
} |
Loading…
Reference in new issue