* 🎨 refactor out react context * 🎨 refactor local storage * 🎨 refactor IdeMessenger * 🔥 removing unused files * 🚚 move scripts * ✅ setup VSCode integration testing * 🎨 fix test-related stuff * 🚧 testing * 🎨 tweak terminal cmd+L * 🧑💻 install biome in core * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 run biome check in binary * 🧑💻 global biome config * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 fix a few biome warnings * 🚧 WIP on protocols * 🚧 progress, organizing, about to remove webviewCore protocol * 🚧 now running * 🚧 move indexing code to core * 🚧 WIP on JetBrains indexing implementation * 🎨 finish listDir * 🚧 gui fixes * 🏷️ update IMessenger.on return type * 🐛 fix jetbrains types + IDE detection * 🧑💻 set up debugging for binary with TcpMessenger * 👷 fix prepackage.js * 🧑💻 turn off debug mode for intellij * 🐛 merge fixes * 🐛 fixes after refactor * 🐛 merge fixes * 💄 increase font size in JB * 🔀 merge changes * 🩹 small fixes * 🐛 fix jetbrains build * 🩹 more jetbrains fixes * 🎨 jetbrains improvements * 🐛 fix lancedb prob in jetbrains build * 👷 update jetbrains build process * ✨ intellij problems context provider * 👷 add script utils file * 💚 fix jetbrains build regression * 🎨 dynamic import transformers.js * 🩹 small jetbrains updates * ✨ folder context provider in jetbrains * 🎨 many more jetbrains improvements * 🔀 merge fixes * ⚡️ small improvements * 🎨 tell users transformers.js not supported * 🎨 trial updates * 📝 update jetbrains readmej * ⚡️ only use smaller context for local autocomplete models * ⚡️ improve bracket filter * ✨ global .continue/.prompts folder * 💄 improved model setup process * 🥅 display VSCode req errs
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { CompletionOptions, LLMOptions, ModelProvider } from "../../index.js";
|
|
import { BaseLLM } from "../index.js";
|
|
import { streamSse } from "../stream.js";
|
|
|
|
class HuggingFaceTGI extends BaseLLM {
|
|
static providerName: ModelProvider = "huggingface-tgi";
|
|
static defaultOptions: Partial<LLMOptions> = {
|
|
apiBase: "http://localhost:8080/",
|
|
};
|
|
|
|
constructor(options: LLMOptions) {
|
|
super(options);
|
|
|
|
this.fetch(new URL("info", this.apiBase), {
|
|
method: "GET",
|
|
}).then(async (response) => {
|
|
if (response.status !== 200) {
|
|
console.warn(
|
|
"Error calling Hugging Face TGI /info endpoint: ",
|
|
await response.text(),
|
|
);
|
|
return;
|
|
}
|
|
const json = await response.json();
|
|
this.model = json.model_id;
|
|
this.contextLength = Number.parseInt(json.max_input_length);
|
|
});
|
|
}
|
|
|
|
private _convertArgs(options: CompletionOptions, prompt: string) {
|
|
const finalOptions = {
|
|
max_new_tokens: options.maxTokens,
|
|
best_of: 1,
|
|
temperature: options.temperature,
|
|
top_p: options.topP,
|
|
top_k: options.topK,
|
|
presence_penalty: options.presencePenalty,
|
|
frequency_penalty: options.frequencyPenalty,
|
|
stop: options.stop,
|
|
};
|
|
|
|
return finalOptions;
|
|
}
|
|
|
|
protected async *_streamComplete(
|
|
prompt: string,
|
|
options: CompletionOptions,
|
|
): AsyncGenerator<string> {
|
|
const args = this._convertArgs(options, prompt);
|
|
|
|
const response = await this.fetch(
|
|
new URL("generate_stream", this.apiBase),
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ inputs: prompt, parameters: args }),
|
|
},
|
|
);
|
|
|
|
for await (const value of streamSse(response)) {
|
|
yield value.token.text;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default HuggingFaceTGI;
|