From 0c77746a9155aa2f2723fa366c3cc64cb8a826df Mon Sep 17 00:00:00 2001 From: Simon <38082241+simon376@users.noreply.github.com> Date: Tue, 16 Jan 2024 18:05:51 +0100 Subject: [PATCH] =?UTF-8?q?Query=20=F0=9F=A4=97TGI=20/info=20endpoint=20to?= =?UTF-8?q?=20get=20model=20name=20and=20context=20window=20(#755)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * query TGI /info endpoint for model name and context length * remove commented-out line * add parseInt --------- Co-authored-by: Simon Müller --- core/llm/llms/HuggingFaceTGI.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/llm/llms/HuggingFaceTGI.ts b/core/llm/llms/HuggingFaceTGI.ts index 5170b8f87..2941589f8 100644 --- a/core/llm/llms/HuggingFaceTGI.ts +++ b/core/llm/llms/HuggingFaceTGI.ts @@ -8,6 +8,25 @@ class HuggingFaceTGI extends BaseLLM { apiBase: "http://localhost:8080", }; + constructor(options: LLMOptions) { + super(options); + + this.fetch(`${this.apiBase}/info`, { + 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 = parseInt(json.max_input_length); + }); + } + private _convertArgs(options: CompletionOptions, prompt: string) { const finalOptions = { max_new_tokens: options.maxTokens,