From 5caf3e669175f87dae4dc47250dcd1a897d0ceec Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 31 Dec 2024 19:29:13 -0500 Subject: [PATCH] fix autocomplete through platform --- core/config/yaml/loadYaml.ts | 4 +++- core/llm/llms/OpenAI.ts | 8 ++++++++ core/llm/llms/stubs/ContinueProxy.ts | 25 ++++++++----------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 77b858630..2d79f826c 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -146,7 +146,9 @@ async function configYamlToContinueConfig( platformConfigMetadata, ); continueConfig.models.push(...llms); - } else if (model.roles?.includes("autocomplete")) { + } + + if (model.roles?.includes("autocomplete")) { // Autocomplete models array const llms = await llmsFromModelConfig( model, diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index aa7d81917..506069217 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -113,6 +113,10 @@ class OpenAI extends BaseLLM { }; } + protected extraBodyProperties(): Record { + return {}; + } + protected getMaxStopWords(): number { const url = new URL(this.apiBase!); @@ -271,6 +275,7 @@ class OpenAI extends BaseLLM { body: JSON.stringify({ ...args, stream: true, + ...this.extraBodyProperties(), }), signal, }); @@ -316,6 +321,7 @@ class OpenAI extends BaseLLM { // We call it toolCalls, they call it tool_calls tool_calls: m.toolCalls, tool_call_id: m.toolCallId, + ...this.extraBodyProperties(), })) as any; const response = await this.fetch(this._getEndpoint("chat/completions"), { method: "POST", @@ -359,6 +365,7 @@ class OpenAI extends BaseLLM { presence_penalty: options.presencePenalty, stop: options.stop, stream: true, + ...this.extraBodyProperties(), }), headers: { "Content-Type": "application/json", @@ -405,6 +412,7 @@ class OpenAI extends BaseLLM { body: JSON.stringify({ input: chunks, model: this.model, + ...this.extraBodyProperties(), }), headers: { Authorization: `Bearer ${this.apiKey}`, diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index f98e2d739..59d05b115 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -2,13 +2,7 @@ import { ControlPlaneProxyInfo } from "../../../control-plane/analytics/IAnalyti import { Telemetry } from "../../../util/posthog.js"; import OpenAI from "../OpenAI.js"; -import { ChatCompletionCreateParams } from "@continuedev/openai-adapters"; -import type { - ChatMessage, - Chunk, - CompletionOptions, - LLMOptions, -} from "../../../index.js"; +import type { Chunk, LLMOptions } from "../../../index.js"; class ContinueProxy extends OpenAI { set controlPlaneProxyInfo(value: ControlPlaneProxyInfo) { @@ -33,17 +27,14 @@ class ContinueProxy extends OpenAI { useLegacyCompletionsEndpoint: false, }; - protected _convertArgs( - options: CompletionOptions, - messages: ChatMessage[], - ): ChatCompletionCreateParams { - const args: any = super._convertArgs(options, messages); - args.continueProperties = { - apiKey: this.actualApiKey, - apiBase: this.actualApiBase, - apiKeySecret: this.apiKeySecret, + protected extraBodyProperties(): Record { + return { + continueProperties: { + apiKey: this.actualApiKey, + apiBase: this.actualApiBase, + apiKeySecret: this.apiKeySecret, + }, }; - return args; } protected _getHeaders() {