Merge pull request #5694 from continuedev/dallin/cancelable-apply
Make Apply Streaming Cancelable
This commit is contained in:
commit
90d5aebd75
56 changed files with 459 additions and 319 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { streamResponse } from "@continuedev/fetch";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import { removeQuotesAndEscapes } from "../../util/index.js";
|
||||
import { streamResponse } from "../../llm/stream.js";
|
||||
|
||||
const HttpSlashCommand: SlashCommand = {
|
||||
name: "http",
|
||||
|
|
|
|||
135
core/core.ts
135
core/core.ts
|
|
@ -35,7 +35,6 @@ import { TTS } from "./util/tts";
|
|||
|
||||
import {
|
||||
ContextItemWithId,
|
||||
DiffLine,
|
||||
IdeSettings,
|
||||
ModelDescription,
|
||||
RangeInFile,
|
||||
|
|
@ -62,61 +61,7 @@ import { LLMLogger } from "./llm/logger";
|
|||
import { llmStreamChat } from "./llm/streamChat";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
|
||||
// This function is used for jetbrains inline edit and apply
|
||||
async function* streamDiffLinesGenerator(
|
||||
configHandler: ConfigHandler,
|
||||
abortedMessageIds: Set<string>,
|
||||
msg: Message<ToCoreProtocol["streamDiffLines"][0]>,
|
||||
): AsyncGenerator<DiffLine> {
|
||||
const {
|
||||
highlighted,
|
||||
prefix,
|
||||
suffix,
|
||||
input,
|
||||
language,
|
||||
modelTitle,
|
||||
includeRulesInSystemMessage,
|
||||
} = msg.data;
|
||||
|
||||
const { config } = await configHandler.loadConfig();
|
||||
if (!config) {
|
||||
throw new Error("Failed to load config");
|
||||
}
|
||||
|
||||
// Title can be an edit, chat, or apply model
|
||||
// Fall back to chat
|
||||
const llm =
|
||||
config.modelsByRole.edit.find((m) => m.title === modelTitle) ??
|
||||
config.modelsByRole.apply.find((m) => m.title === modelTitle) ??
|
||||
config.modelsByRole.chat.find((m) => m.title === modelTitle) ??
|
||||
config.selectedModelByRole.chat;
|
||||
|
||||
if (!llm) {
|
||||
throw new Error("No model selected");
|
||||
}
|
||||
|
||||
// rules included for edit, NOT apply
|
||||
const rules = includeRulesInSystemMessage ? config.rules : undefined;
|
||||
|
||||
for await (const diffLine of streamDiffLines({
|
||||
highlighted,
|
||||
prefix,
|
||||
suffix,
|
||||
llm,
|
||||
rulesToInclude: rules,
|
||||
input,
|
||||
language,
|
||||
onlyOneInsertion: false,
|
||||
overridePrompt: undefined,
|
||||
})) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
break;
|
||||
}
|
||||
yield diffLine;
|
||||
}
|
||||
}
|
||||
import { StreamAbortManager } from "./util/abortManager";
|
||||
|
||||
export class Core {
|
||||
configHandler: ConfigHandler;
|
||||
|
|
@ -132,7 +77,18 @@ export class Core {
|
|||
this.globalContext.get("indexingPaused") === true,
|
||||
);
|
||||
|
||||
private abortedMessageIds: Set<string> = new Set();
|
||||
private messageAbortControllers = new Map<string, AbortController>();
|
||||
private addMessageAbortController(id: string): AbortController {
|
||||
const controller = new AbortController();
|
||||
this.messageAbortControllers.set(id, controller);
|
||||
controller.signal.addEventListener("abort", () => {
|
||||
this.messageAbortControllers.delete(id);
|
||||
});
|
||||
return controller;
|
||||
}
|
||||
private abortById(messageId: string) {
|
||||
this.messageAbortControllers.get(messageId)?.abort();
|
||||
}
|
||||
|
||||
invoke<T extends keyof ToCoreProtocol>(
|
||||
messageType: T,
|
||||
|
|
@ -301,7 +257,7 @@ export class Core {
|
|||
});
|
||||
|
||||
on("abort", (msg) => {
|
||||
this.abortedMessageIds.add(msg.messageId);
|
||||
this.abortById(msg.data ?? msg.messageId);
|
||||
});
|
||||
|
||||
on("ping", (msg) => {
|
||||
|
|
@ -470,27 +426,28 @@ export class Core {
|
|||
}
|
||||
});
|
||||
|
||||
on("llm/streamChat", (msg) =>
|
||||
llmStreamChat(
|
||||
on("llm/streamChat", (msg) => {
|
||||
const abortController = this.addMessageAbortController(msg.messageId);
|
||||
return llmStreamChat(
|
||||
this.configHandler,
|
||||
this.abortedMessageIds,
|
||||
abortController,
|
||||
msg,
|
||||
this.ide,
|
||||
this.messenger,
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
on("llm/complete", async (msg) => {
|
||||
const model = (await this.configHandler.loadConfig()).config
|
||||
?.selectedModelByRole.chat;
|
||||
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
const model = config?.selectedModelByRole.chat;
|
||||
if (!model) {
|
||||
throw new Error("No chat model selected");
|
||||
}
|
||||
const abortController = this.addMessageAbortController(msg.messageId);
|
||||
|
||||
const completion = await model.complete(
|
||||
msg.data.prompt,
|
||||
new AbortController().signal,
|
||||
abortController.signal,
|
||||
msg.data.completionOptions,
|
||||
);
|
||||
return completion;
|
||||
|
|
@ -532,9 +489,47 @@ export class Core {
|
|||
this.completionProvider.cancel();
|
||||
});
|
||||
|
||||
on("streamDiffLines", (msg) =>
|
||||
streamDiffLinesGenerator(this.configHandler, this.abortedMessageIds, msg),
|
||||
);
|
||||
on("streamDiffLines", async (msg) => {
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
if (!config) {
|
||||
throw new Error("Failed to load config");
|
||||
}
|
||||
|
||||
const { data } = msg;
|
||||
|
||||
// Title can be an edit, chat, or apply model
|
||||
// Fall back to chat
|
||||
const llm =
|
||||
config.modelsByRole.edit.find((m) => m.title === data.modelTitle) ??
|
||||
config.modelsByRole.apply.find((m) => m.title === data.modelTitle) ??
|
||||
config.modelsByRole.chat.find((m) => m.title === data.modelTitle) ??
|
||||
config.selectedModelByRole.chat;
|
||||
|
||||
if (!llm) {
|
||||
throw new Error("No model selected");
|
||||
}
|
||||
|
||||
return streamDiffLines({
|
||||
highlighted: data.highlighted,
|
||||
prefix: data.prefix,
|
||||
suffix: data.suffix,
|
||||
llm,
|
||||
// rules included for edit, NOT apply
|
||||
rulesToInclude: data.includeRulesInSystemMessage
|
||||
? config.rules
|
||||
: undefined,
|
||||
input: data.input,
|
||||
language: data.language,
|
||||
onlyOneInsertion: false,
|
||||
overridePrompt: undefined,
|
||||
abortControllerId: data.fileUri ?? "current-file-stream", // not super important since currently cancelling apply will cancel all streams it's one file at a time
|
||||
});
|
||||
});
|
||||
|
||||
on("cancelApply", async (msg) => {
|
||||
const abortManager = StreamAbortManager.getInstance();
|
||||
abortManager.clear();
|
||||
});
|
||||
|
||||
on("completeOnboarding", this.handleCompleteOnboarding.bind(this));
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const RECURSIVE_PROMPT = `Continue EXACTLY where you left`;
|
|||
|
||||
export async function* recursiveStream(
|
||||
llm: ILLM,
|
||||
abortController: AbortController,
|
||||
prompt: ChatMessage[] | string,
|
||||
prediction: Prediction | undefined,
|
||||
currentBuffer = "",
|
||||
|
|
@ -28,7 +29,7 @@ export async function* recursiveStream(
|
|||
// let whiteSpaceAtEndOfBuffer = buffer.match(/\s*$/)?.[0] ?? ""; // attempts at fixing whitespace bug with recursive boundaries
|
||||
|
||||
if (typeof prompt === "string") {
|
||||
const generator = llm.streamComplete(prompt, new AbortController().signal, {
|
||||
const generator = llm.streamComplete(prompt, abortController.signal, {
|
||||
raw: true,
|
||||
prediction: undefined,
|
||||
reasoning: false,
|
||||
|
|
@ -50,6 +51,7 @@ export async function* recursiveStream(
|
|||
// // TODO - Prediction capabilities lost because of partial input
|
||||
// yield* recursiveStream(
|
||||
// llm,
|
||||
// abortController,
|
||||
// continuationPrompt,
|
||||
// undefined,
|
||||
// buffer,
|
||||
|
|
@ -60,7 +62,7 @@ export async function* recursiveStream(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
const generator = llm.streamChat(prompt, new AbortController().signal, {
|
||||
const generator = llm.streamChat(prompt, abortController.signal, {
|
||||
prediction,
|
||||
reasoning: false,
|
||||
});
|
||||
|
|
@ -90,6 +92,7 @@ export async function* recursiveStream(
|
|||
// await generator.return(DUD_PROMPT_LOG);
|
||||
// yield* recursiveStream(
|
||||
// llm,
|
||||
// abortController,
|
||||
// continuationPrompt,
|
||||
// undefined,
|
||||
// buffer,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { streamDiff } from "../diff/streamDiff";
|
|||
import { streamLines } from "../diff/util";
|
||||
import { getSystemMessageWithRules } from "../llm/rules/getSystemMessageWithRules";
|
||||
import { gptEditPrompt } from "../llm/templates/edit";
|
||||
import { StreamAbortManager } from "../util/abortManager";
|
||||
import { findLast } from "../util/findLast";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
import { recursiveStream } from "./recursiveStream";
|
||||
|
|
@ -63,6 +64,7 @@ export async function* streamDiffLines({
|
|||
highlighted,
|
||||
suffix,
|
||||
llm,
|
||||
abortControllerId,
|
||||
input,
|
||||
language,
|
||||
onlyOneInsertion,
|
||||
|
|
@ -73,12 +75,15 @@ export async function* streamDiffLines({
|
|||
highlighted: string;
|
||||
suffix: string;
|
||||
llm: ILLM;
|
||||
abortControllerId: string;
|
||||
input: string;
|
||||
language: string | undefined;
|
||||
onlyOneInsertion: boolean;
|
||||
overridePrompt: ChatMessage[] | undefined;
|
||||
rulesToInclude: RuleWithSource[] | undefined;
|
||||
}): AsyncGenerator<DiffLine> {
|
||||
const abortManager = StreamAbortManager.getInstance();
|
||||
const abortController = abortManager.get(abortControllerId);
|
||||
void Telemetry.capture(
|
||||
"inlineEdit",
|
||||
{
|
||||
|
|
@ -158,7 +163,7 @@ export async function* streamDiffLines({
|
|||
content: highlighted,
|
||||
};
|
||||
|
||||
const completion = recursiveStream(llm, prompt, prediction);
|
||||
const completion = recursiveStream(llm, abortController, prompt, prediction);
|
||||
|
||||
let lines = streamLines(completion);
|
||||
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1240,6 +1240,7 @@ export interface StreamDiffLinesPayload {
|
|||
language: string | undefined;
|
||||
modelTitle: string | undefined;
|
||||
includeRulesInSystemMessage: boolean;
|
||||
fileUri?: string;
|
||||
}
|
||||
|
||||
export interface HighlightedCodePayload {
|
||||
|
|
|
|||
|
|
@ -382,6 +382,9 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
// Error mapping to be more helpful
|
||||
if (!resp.ok) {
|
||||
if (resp.status === 499) {
|
||||
return resp; // client side cancellation
|
||||
}
|
||||
let text = await resp.text();
|
||||
if (resp.status === 404 && !resp.url.includes("/v1")) {
|
||||
const error = JSON.parse(text)?.error?.replace(/"/g, "'");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
class Anthropic extends BaseLLM {
|
||||
static providerName = "anthropic";
|
||||
|
|
@ -213,6 +213,10 @@ class Anthropic extends BaseLLM {
|
|||
signal,
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
if (json.type === "error") {
|
||||
|
|
|
|||
|
|
@ -134,10 +134,8 @@ class Asksage extends BaseLLM {
|
|||
body: JSON.stringify(args),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`API request failed with status ${response.status}: ${response.statusText}`,
|
||||
);
|
||||
if (response.status === 499) {
|
||||
return ""; // Aborted by user
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
|
@ -167,10 +165,8 @@ class Asksage extends BaseLLM {
|
|||
signal,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`API request failed with status ${response.status}: ${response.statusText}`,
|
||||
);
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { ChatMessage, CompletionOptions } from "../../index.js";
|
||||
import { renderChatMessage } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
export default class Cloudflare extends BaseLLM {
|
||||
static providerName = "cloudflare";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { streamJSON } from "@continuedev/fetch";
|
||||
import {
|
||||
ChatMessage,
|
||||
Chunk,
|
||||
|
|
@ -6,7 +7,6 @@ import {
|
|||
} from "../../index.js";
|
||||
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamJSON } from "../stream.js";
|
||||
|
||||
class Cohere extends BaseLLM {
|
||||
static providerName = "cohere";
|
||||
|
|
@ -84,6 +84,10 @@ class Cohere extends BaseLLM {
|
|||
signal,
|
||||
});
|
||||
|
||||
if (resp.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
if (options.stream === false) {
|
||||
const data = await resp.json();
|
||||
yield { role: "assistant", content: data.text };
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
import { osModelsEditPrompt } from "../templates/edit.js";
|
||||
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
|
|
|||
|
|
@ -132,12 +132,16 @@ class Flowise extends BaseLLM {
|
|||
): AsyncGenerator<ChatMessage> {
|
||||
const requestBody = this._getRequestBody(messages, options);
|
||||
const { socket, socketInfo } = await this._initializeSocket();
|
||||
const request = this.fetch(this._getChatUrl(), {
|
||||
const response = await this.fetch(this._getChatUrl(), {
|
||||
method: "POST",
|
||||
headers: this._getHeaders(),
|
||||
body: JSON.stringify({ ...requestBody, socketIOClientId: socket.id }),
|
||||
signal,
|
||||
}).then((res) => res.json());
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
while (await socketInfo.hasNextToken()) {
|
||||
yield { role: "assistant", content: socketInfo.getCurrentMessage() };
|
||||
|
|
@ -145,7 +149,7 @@ class Flowise extends BaseLLM {
|
|||
if (socketInfo.error) {
|
||||
socket.disconnect();
|
||||
try {
|
||||
yield { role: "assistant", content: (await request).text };
|
||||
yield { role: "assistant", content: await response.text() };
|
||||
} catch (error: any) {
|
||||
yield { role: "assistant", content: (error as Error).message ?? error };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { streamResponse } from "@continuedev/fetch";
|
||||
import { TRIAL_FIM_MODEL } from "../../config/onboarding.js";
|
||||
import { getHeaders } from "../../continueServer/stubs/headers.js";
|
||||
import { TRIAL_PROXY_URL } from "../../control-plane/client.js";
|
||||
|
|
@ -8,7 +9,6 @@ import {
|
|||
LLMOptions,
|
||||
} from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse } from "../stream.js";
|
||||
|
||||
class FreeTrial extends BaseLLM {
|
||||
static providerName = "free-trial";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { streamResponse } from "@continuedev/fetch";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
AssistantChatMessage,
|
||||
|
|
@ -10,7 +11,6 @@ import {
|
|||
} from "../../index.js";
|
||||
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse } from "../stream.js";
|
||||
import {
|
||||
GeminiChatContent,
|
||||
GeminiChatContentPart,
|
||||
|
|
@ -438,6 +438,9 @@ class Gemini extends BaseLLM {
|
|||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
const data = await response.json();
|
||||
yield { role: "assistant", content: data.candidates[0].content };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions } from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
class HuggingFaceInferenceAPI extends BaseLLM {
|
||||
static providerName = "huggingface-inference-api";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
class HuggingFaceTGI extends BaseLLM {
|
||||
private static MAX_STOP_TOKENS = 4;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
class LlamaCpp extends BaseLLM {
|
||||
static providerName = "llama.cpp";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
import { osModelsEditPrompt } from "../templates/edit.js";
|
||||
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Mutex } from "async-mutex";
|
|||
import { JSONSchema7, JSONSchema7Object } from "json-schema";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { streamResponse } from "@continuedev/fetch";
|
||||
import {
|
||||
ChatMessage,
|
||||
ChatMessageRole,
|
||||
|
|
@ -12,7 +13,6 @@ import {
|
|||
import { renderChatMessage } from "../../util/messageContent.js";
|
||||
import { getRemoteModelInfo } from "../../util/ollamaHelper.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse } from "../stream.js";
|
||||
|
||||
type OllamaChatMessage = {
|
||||
role: ChatMessageRole;
|
||||
|
|
@ -457,6 +457,9 @@ class Ollama extends BaseLLM implements ModelInstaller {
|
|||
}
|
||||
|
||||
if (chatOptions.stream === false) {
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
const json = (await response.json()) as OllamaChatResponse;
|
||||
yield convertChatMessage(json);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
ChatCompletionMessageParam,
|
||||
} from "openai/resources/index";
|
||||
|
||||
import { streamSse } from "@continuedev/fetch";
|
||||
import {
|
||||
ChatMessage,
|
||||
CompletionOptions,
|
||||
|
|
@ -16,7 +17,6 @@ import {
|
|||
LlmApiRequestType,
|
||||
toChatBody,
|
||||
} from "../openaiTypeConverters.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
const NON_CHAT_MODELS = [
|
||||
"text-davinci-002",
|
||||
|
|
@ -352,6 +352,9 @@ class OpenAI extends BaseLLM {
|
|||
|
||||
// Handle non-streaming response
|
||||
if (body.stream === false) {
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
const data = await response.json();
|
||||
yield data.choices[0].message;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { Chunk, CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
import { osModelsEditPrompt } from "../templates/edit.js";
|
||||
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
|
@ -58,7 +58,7 @@ class SiliconFlow extends OpenAI {
|
|||
console.warn("[SiliconFlow] rerank: query is empty");
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
if (!chunks || chunks.length === 0) {
|
||||
console.warn("[SiliconFlow] rerank: chunks is empty");
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { GoogleAuth } from "google-auth-library";
|
||||
|
||||
import { streamResponse, streamSse } from "@continuedev/fetch";
|
||||
import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse, streamSse } from "../stream.js";
|
||||
|
||||
import Anthropic from "./Anthropic.js";
|
||||
import Gemini from "./Gemini.js";
|
||||
|
|
@ -95,6 +95,7 @@ class VertexAI extends BaseLLM {
|
|||
protected async *StreamChatAnthropic(
|
||||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const systemMessage = stripImages(
|
||||
messages.filter((m) => m.role === "system")[0]?.content ?? "",
|
||||
|
|
@ -128,8 +129,13 @@ class VertexAI extends BaseLLM {
|
|||
]
|
||||
: systemMessage,
|
||||
}),
|
||||
signal,
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
if (options.stream === false) {
|
||||
const data = await response.json();
|
||||
yield { role: "assistant", content: data.content[0].text };
|
||||
|
|
@ -150,6 +156,7 @@ class VertexAI extends BaseLLM {
|
|||
private async *streamChatGemini(
|
||||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const apiURL = new URL(
|
||||
`publishers/google/models/${options.model}:streamGenerateContent`,
|
||||
|
|
@ -160,6 +167,7 @@ class VertexAI extends BaseLLM {
|
|||
const response = await this.fetch(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
for await (const message of this.geminiInstance.processGeminiResponse(
|
||||
streamResponse(response),
|
||||
|
|
@ -171,6 +179,7 @@ class VertexAI extends BaseLLM {
|
|||
private async *streamChatBison(
|
||||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const instances = messages.map((message) => ({ prompt: message.content }));
|
||||
|
||||
|
|
@ -193,7 +202,11 @@ class VertexAI extends BaseLLM {
|
|||
const response = await this.fetch(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
const data = await response.json();
|
||||
yield { role: "assistant", content: data.predictions[0].content };
|
||||
}
|
||||
|
|
@ -203,6 +216,7 @@ class VertexAI extends BaseLLM {
|
|||
protected async *StreamChatMistral(
|
||||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const apiBase = this.apiBase!;
|
||||
const apiURL = new URL(
|
||||
|
|
@ -228,6 +242,7 @@ class VertexAI extends BaseLLM {
|
|||
const response = await this.fetch(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
|
||||
for await (const chunk of streamSse(response)) {
|
||||
|
|
@ -304,6 +319,9 @@ class VertexAI extends BaseLLM {
|
|||
}),
|
||||
signal,
|
||||
});
|
||||
if (resp.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
// Streaming is not supported by code-gecko
|
||||
// TODO: convert to non-streaming fim method when one exist in continue.
|
||||
yield (await resp.json()).predictions[0].content;
|
||||
|
|
@ -323,14 +341,14 @@ class VertexAI extends BaseLLM {
|
|||
? this.geminiInstance.removeSystemMessage(messages)
|
||||
: messages;
|
||||
if (this.vertexProvider === "gemini") {
|
||||
yield* this.streamChatGemini(convertedMsgs, options);
|
||||
yield* this.streamChatGemini(convertedMsgs, options, signal);
|
||||
} else if (this.vertexProvider === "mistral") {
|
||||
yield* this.StreamChatMistral(messages, options);
|
||||
yield* this.StreamChatMistral(messages, options, signal);
|
||||
} else if (this.vertexProvider === "anthropic") {
|
||||
yield* this.StreamChatAnthropic(messages, options);
|
||||
yield* this.StreamChatAnthropic(messages, options, signal);
|
||||
} else {
|
||||
if (options.model.includes("bison")) {
|
||||
yield* this.streamChatBison(convertedMsgs, options);
|
||||
yield* this.streamChatBison(convertedMsgs, options, signal);
|
||||
} else {
|
||||
throw new Error(`Unsupported model: ${options.model}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
import { streamResponse, streamSse } from "@continuedev/fetch";
|
||||
import {
|
||||
ChatMessage,
|
||||
Chunk,
|
||||
CompletionOptions,
|
||||
LLMOptions,
|
||||
} from "../../index.js";
|
||||
import {
|
||||
fromChatCompletionChunk,
|
||||
} from "../openaiTypeConverters.js";
|
||||
import { renderChatMessage } from "../../util/messageContent.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
import { streamResponse, streamSse } from "../stream.js";
|
||||
import { fromChatCompletionChunk } from "../openaiTypeConverters.js";
|
||||
|
||||
let watsonxToken = {
|
||||
expiration: 0,
|
||||
|
|
@ -86,7 +83,7 @@ class WatsonX extends BaseLLM {
|
|||
}
|
||||
|
||||
_getEndpoint(endpoint: string): string {
|
||||
return `${this.apiBase}/ml/v1/${this.deploymentId ? `deployments/${this.deploymentId}/` : ""}text/${endpoint}_stream?version=${this.apiVersion}`
|
||||
return `${this.apiBase}/ml/v1/${this.deploymentId ? `deployments/${this.deploymentId}/` : ""}text/${endpoint}_stream?version=${this.apiVersion}`;
|
||||
}
|
||||
|
||||
static providerName = "watsonx";
|
||||
|
|
@ -182,7 +179,6 @@ class WatsonX extends BaseLLM {
|
|||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
): AsyncGenerator<string> {
|
||||
|
||||
await this.updateWatsonxToken();
|
||||
|
||||
const stopSequences = options.stop?.slice(0, 6) ?? [];
|
||||
|
|
@ -214,44 +210,38 @@ class WatsonX extends BaseLLM {
|
|||
payload.project_id = this.projectId;
|
||||
}
|
||||
|
||||
var response = await this.fetch(url, {
|
||||
const response = await this.fetch(url, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(payload),
|
||||
signal,
|
||||
});
|
||||
|
||||
if (!response.ok || response.body === null) {
|
||||
throw new Error(
|
||||
"Something went wrong. No response received, check your connection",
|
||||
);
|
||||
} else {
|
||||
for await (const value of streamResponse(response)) {
|
||||
const lines = value.split("\n");
|
||||
let generatedChunk = "";
|
||||
let generatedTextIndex = undefined;
|
||||
lines.forEach((el: string) => {
|
||||
// console.log(`${el}`);
|
||||
if (el.startsWith("id:")) {
|
||||
generatedTextIndex = parseInt(el.replace(/^id:\s+/, ""));
|
||||
if (isNaN(generatedTextIndex)) {
|
||||
console.error(`Unable to parse stream chunk ID: ${el}`);
|
||||
}
|
||||
} else if (el.startsWith("data:")) {
|
||||
const dataStr = el.replace(/^data:\s+/, "");
|
||||
try {
|
||||
const data = JSON.parse(dataStr);
|
||||
data.results.forEach((result: any) => {
|
||||
generatedChunk += result.generated_text || "";
|
||||
});
|
||||
} catch (e) {
|
||||
// parsing error is expected with streaming response
|
||||
// console.error(`Error parsing JSON string: ${dataStr}`, e);
|
||||
}
|
||||
for await (const value of streamResponse(response)) {
|
||||
const lines = value.split("\n");
|
||||
let generatedChunk = "";
|
||||
let generatedTextIndex = undefined;
|
||||
lines.forEach((el: string) => {
|
||||
// console.log(`${el}`);
|
||||
if (el.startsWith("id:")) {
|
||||
generatedTextIndex = parseInt(el.replace(/^id:\s+/, ""));
|
||||
if (isNaN(generatedTextIndex)) {
|
||||
console.error(`Unable to parse stream chunk ID: ${el}`);
|
||||
}
|
||||
});
|
||||
yield generatedChunk
|
||||
}
|
||||
} else if (el.startsWith("data:")) {
|
||||
const dataStr = el.replace(/^data:\s+/, "");
|
||||
try {
|
||||
const data = JSON.parse(dataStr);
|
||||
data.results.forEach((result: any) => {
|
||||
generatedChunk += result.generated_text || "";
|
||||
});
|
||||
} catch (e) {
|
||||
// parsing error is expected with streaming response
|
||||
// console.error(`Error parsing JSON string: ${dataStr}`, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
yield generatedChunk;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -267,7 +257,7 @@ class WatsonX extends BaseLLM {
|
|||
const headers = this._getHeaders();
|
||||
|
||||
const payload: any = {
|
||||
messages: messages,
|
||||
messages: messages,
|
||||
max_tokens: options.maxTokens ?? 1024,
|
||||
stop: stopSequences,
|
||||
frequency_penalty: options.frequencyPenalty || 1,
|
||||
|
|
@ -281,36 +271,30 @@ class WatsonX extends BaseLLM {
|
|||
|
||||
if (!!options.temperature) {
|
||||
payload.temperature = options.temperature;
|
||||
}
|
||||
}
|
||||
if (!!options.topP) {
|
||||
payload.top_p = options.topP;
|
||||
}
|
||||
if (!!options.tools) {
|
||||
payload.tools = options.tools;
|
||||
if (options.toolChoice) {
|
||||
payload.tool_choice = options.toolChoice;
|
||||
payload.tool_choice = options.toolChoice;
|
||||
} else {
|
||||
payload.tool_choice_option = "auto";
|
||||
payload.tool_choice_option = "auto";
|
||||
}
|
||||
}
|
||||
|
||||
var response = await this.fetch(url, {
|
||||
const response = await this.fetch(url, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(payload),
|
||||
signal,
|
||||
});
|
||||
|
||||
if (!response.ok || response.body === null) {
|
||||
throw new Error(
|
||||
"Something went wrong. No response received, check your connection",
|
||||
);
|
||||
} else {
|
||||
for await (const value of streamSse(response)) {
|
||||
const chunk = fromChatCompletionChunk(value);
|
||||
if (chunk) {
|
||||
yield chunk;
|
||||
}
|
||||
for await (const value of streamSse(response)) {
|
||||
const chunk = fromChatCompletionChunk(value);
|
||||
if (chunk) {
|
||||
yield chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
import { Readable } from "stream";
|
||||
import { streamSse } from "./stream";
|
||||
|
||||
function createMockResponse(sseLines: string[]): Response {
|
||||
// Create a Readable stream that emits the SSE lines
|
||||
const stream = new Readable({
|
||||
read() {
|
||||
for (const line of sseLines) {
|
||||
this.push(line + "\n\n");
|
||||
}
|
||||
this.push(null); // End of stream
|
||||
}
|
||||
}) as any;
|
||||
|
||||
// Minimal Response mock
|
||||
return {
|
||||
status: 200,
|
||||
body: stream,
|
||||
text: async () => "",
|
||||
} as unknown as Response;
|
||||
}
|
||||
|
||||
describe("streamSse", () => {
|
||||
it("yields parsed SSE data objects that ends with `data:[DONE]`", async () => {
|
||||
const sseLines = [
|
||||
'data: {"foo": "bar"}',
|
||||
'data: {"baz": 42}',
|
||||
'data:[DONE]'
|
||||
];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const results = [];
|
||||
for await (const data of streamSse(response)) {
|
||||
results.push(data);
|
||||
}
|
||||
|
||||
expect(results).toEqual([
|
||||
{ foo: "bar" },
|
||||
{ baz: 42 }
|
||||
]);
|
||||
});
|
||||
|
||||
it("yields parsed SSE data objects that ends with `data: [DONE]` (with a space before [DONE]", async () => {
|
||||
const sseLines = [
|
||||
'data: {"foo": "bar"}',
|
||||
'data: {"baz": 42}',
|
||||
'data: [DONE]'
|
||||
];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const results = [];
|
||||
for await (const data of streamSse(response)) {
|
||||
results.push(data);
|
||||
}
|
||||
|
||||
expect(results).toEqual([
|
||||
{ foo: "bar" },
|
||||
{ baz: 42 }
|
||||
]);
|
||||
});
|
||||
|
||||
it("throws on malformed JSON", async () => {
|
||||
const sseLines = [
|
||||
'data: {"foo": "bar"',
|
||||
'data:[DONE]'
|
||||
];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const iterator = streamSse(response)[Symbol.asyncIterator]();
|
||||
await expect(iterator.next()).rejects.toThrow(/Malformed JSON/);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
async function* toAsyncIterable(
|
||||
export async function* toAsyncIterable(
|
||||
nodeReadable: NodeJS.ReadableStream,
|
||||
): AsyncGenerator<Uint8Array> {
|
||||
for await (const chunk of nodeReadable) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { TTS } from "../util/tts";
|
|||
|
||||
export async function* llmStreamChat(
|
||||
configHandler: ConfigHandler,
|
||||
abortedMessageIds: Set<string>,
|
||||
abortController: AbortController,
|
||||
msg: Message<ToCoreProtocol["llm/streamChat"][0]>,
|
||||
ide: IDE,
|
||||
messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
|
|
@ -75,52 +75,44 @@ export async function* llmStreamChat(
|
|||
selectedCode,
|
||||
config,
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
fetchwithRequestOptions(
|
||||
url,
|
||||
{
|
||||
...init,
|
||||
signal: abortController.signal,
|
||||
},
|
||||
config.requestOptions,
|
||||
),
|
||||
completionOptions,
|
||||
});
|
||||
const checkActiveInterval = setInterval(() => {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
clearInterval(checkActiveInterval);
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
if (abortController.signal.aborted) {
|
||||
next = await gen.return(errorPromptLog);
|
||||
break;
|
||||
}
|
||||
}, 100);
|
||||
try {
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
next = await gen.return(errorPromptLog);
|
||||
clearInterval(checkActiveInterval);
|
||||
break;
|
||||
}
|
||||
if (next.value) {
|
||||
yield {
|
||||
role: "assistant",
|
||||
content: next.value,
|
||||
};
|
||||
}
|
||||
next = await gen.next();
|
||||
if (next.value) {
|
||||
yield {
|
||||
role: "assistant",
|
||||
content: next.value,
|
||||
};
|
||||
}
|
||||
if (!next.done) {
|
||||
throw new Error("Will never happen");
|
||||
}
|
||||
|
||||
return next.value;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
clearInterval(checkActiveInterval);
|
||||
next = await gen.next();
|
||||
}
|
||||
if (!next.done) {
|
||||
throw new Error("Will never happen");
|
||||
}
|
||||
|
||||
return next.value;
|
||||
} else {
|
||||
const gen = model.streamChat(
|
||||
messages,
|
||||
new AbortController().signal,
|
||||
abortController.signal,
|
||||
completionOptions,
|
||||
);
|
||||
let next = await gen.next();
|
||||
while (!next.done) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
if (abortController.signal.aborted) {
|
||||
next = await gen.return(errorPromptLog);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
20
core/package-lock.json
generated
20
core/package-lock.json
generated
|
|
@ -14,9 +14,9 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.6",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@continuedev/openai-adapters": "^1.0.25",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
@ -2927,9 +2927,10 @@
|
|||
"link": true
|
||||
},
|
||||
"node_modules/@continuedev/fetch": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.6.tgz",
|
||||
"integrity": "sha512-QpB9cHgEw5avoouFR0qm7/XTo44SrVfkGAmzbDTui2P9djj+DYvj+0yaJ8e/Ubyc5PUjFTUS2YnRar7NfYpHIg==",
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.10.tgz",
|
||||
"integrity": "sha512-RBUXtm/VDz+9Itgw+CxrHXwVXoHCAedGzPOgA7gS5HZ9lObaeCJgEfzmfbln1ocFsfqSFmn5X5wSE7DHgfxpVA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
|
@ -2944,14 +2945,15 @@
|
|||
"integrity": "sha512-/htL7p4li3zQSwn9bXkI23WRpZNklWTPzRSSG3Fd5gvYW8cizjhlf7OzeDdKxBfi1S0lpqMm0VwHlx3KjMKLpw=="
|
||||
},
|
||||
"node_modules/@continuedev/openai-adapters": {
|
||||
"version": "1.0.19",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/openai-adapters/-/openai-adapters-1.0.19.tgz",
|
||||
"integrity": "sha512-9bfgTHPThRZAIn5T/zaWvKhMgVDFgpP3zr9DIkBT5THRNIrbbWd6VrguNEp9ASlX85ohNiXnk+jiC/FfFcH++w==",
|
||||
"version": "1.0.25",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/openai-adapters/-/openai-adapters-1.0.25.tgz",
|
||||
"integrity": "sha512-YG7bcAlUk3BnqIOZw+ClmxmZU6G3OaaZqbhfqgiCnJem5i7oDy0pkAVHjig4iRTQkpvDokKmBXCH9wmQNRbWNw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@azure/openai": "^1.0.0-beta.12",
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"@continuedev/config-yaml": "^1.0.51",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"dotenv": "^16.5.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.6",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@continuedev/openai-adapters": "^1.0.25",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
// Special
|
||||
ping: [string, string];
|
||||
abort: [undefined, void];
|
||||
cancelApply: [undefined, void];
|
||||
|
||||
// History
|
||||
"history/list": [ListHistoryOptions, SessionMetadata[]];
|
||||
|
|
|
|||
37
core/util/abortManager.ts
Normal file
37
core/util/abortManager.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
export class StreamAbortManager {
|
||||
private static instance: StreamAbortManager;
|
||||
private controllers: Map<string, AbortController>;
|
||||
|
||||
private constructor() {
|
||||
this.controllers = new Map();
|
||||
}
|
||||
|
||||
public static getInstance(): StreamAbortManager {
|
||||
if (!StreamAbortManager.instance) {
|
||||
StreamAbortManager.instance = new StreamAbortManager();
|
||||
}
|
||||
return StreamAbortManager.instance;
|
||||
}
|
||||
|
||||
public get(id: string): AbortController {
|
||||
let controller = this.controllers.get(id);
|
||||
if (!controller) {
|
||||
controller = new AbortController();
|
||||
this.controllers.set(id, controller);
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
public abort(id: string): void {
|
||||
const controller = this.controllers.get(id);
|
||||
if (controller) {
|
||||
controller.abort();
|
||||
this.controllers.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.controllers.forEach((controller) => controller.abort());
|
||||
this.controllers.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ class DiffManager(private val project: Project) : DumbAware {
|
|||
)
|
||||
continuePluginService.ideProtocolClient?.deleteAtIndex(diffInfo.stepIndex)
|
||||
continuePluginService.ideProtocolClient?.sendAcceptRejectDiff(false, diffInfo.stepIndex)
|
||||
|
||||
continuePluginService.coreMessenger?.request("cancelApply", null, null) {}
|
||||
cleanUpFile(file)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ class DiffStreamHandler(
|
|||
suffix = suffix,
|
||||
language = virtualFile?.fileType?.name,
|
||||
modelTitle = modelTitle,
|
||||
includeRulesInSystemMessage = includeRulesInSystemMessage
|
||||
includeRulesInSystemMessage = includeRulesInSystemMessage,
|
||||
fileUri = virtualFile?.url
|
||||
),
|
||||
null
|
||||
) { response ->
|
||||
|
|
@ -289,7 +290,6 @@ class DiffStreamHandler(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private fun handleFinishedResponse() {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
// Since we only call onLastDiffLine() when we reach a "same" line, we need to handle the case where
|
||||
|
|
|
|||
|
|
@ -244,7 +244,8 @@ data class StreamDiffLinesPayload(
|
|||
val input: String,
|
||||
val language: String?,
|
||||
val modelTitle: String?,
|
||||
val includeRulesInSystemMessage: Boolean
|
||||
val includeRulesInSystemMessage: Boolean,
|
||||
val fileUri: String?
|
||||
)
|
||||
|
||||
data class AcceptOrRejectDiffPayload(
|
||||
|
|
|
|||
13
extensions/vscode/package-lock.json
generated
13
extensions/vscode/package-lock.json
generated
|
|
@ -10,7 +10,7 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
|
|
@ -107,9 +107,9 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.6",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@continuedev/openai-adapters": "^1.0.25",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
@ -708,9 +708,10 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@continuedev/fetch": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.3.tgz",
|
||||
"integrity": "sha512-cGNCUEVnDfC+3O/n1PV+oYhS5yZRLR1Q7Njg929kVbA8kRHe5a3VdKINfFzWdKprOU4wipsXSliciZHCpbJJ9g==",
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.10.tgz",
|
||||
"integrity": "sha512-RBUXtm/VDz+9Itgw+CxrHXwVXoHCAedGzPOgA7gS5HZ9lObaeCJgEfzmfbln1ocFsfqSFmn5X5wSE7DHgfxpVA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
|
|
|||
|
|
@ -661,7 +661,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ async function processDiff(
|
|||
action: "accept" | "reject",
|
||||
sidebar: ContinueGUIWebviewViewProvider,
|
||||
ide: VsCodeIde,
|
||||
core: Core,
|
||||
verticalDiffManager: VerticalDiffManager,
|
||||
newFileUri?: string,
|
||||
streamId?: string,
|
||||
|
|
@ -121,6 +122,9 @@ async function processDiff(
|
|||
|
||||
// Clear vertical diffs depending on action
|
||||
verticalDiffManager.clearForfileUri(newOrCurrentUri, action === "accept");
|
||||
if (action === "reject") {
|
||||
core.invoke("cancelApply", undefined);
|
||||
}
|
||||
|
||||
if (streamId) {
|
||||
const fileContent = await ide.readFile(newOrCurrentUri);
|
||||
|
|
@ -236,18 +240,20 @@ const getCommandsMap: (
|
|||
"accept",
|
||||
sidebar,
|
||||
ide,
|
||||
core,
|
||||
verticalDiffManager,
|
||||
newFileUri,
|
||||
streamId,
|
||||
),
|
||||
|
||||
"continue.rejectDiff": async (newFilepath?: string, streamId?: string) =>
|
||||
"continue.rejectDiff": async (newFileUri?: string, streamId?: string) =>
|
||||
processDiff(
|
||||
"reject",
|
||||
sidebar,
|
||||
ide,
|
||||
core,
|
||||
verticalDiffManager,
|
||||
newFilepath,
|
||||
newFileUri,
|
||||
streamId,
|
||||
),
|
||||
"continue.acceptVerticalDiffBlock": (fileUri?: string, index?: number) => {
|
||||
|
|
@ -573,11 +579,15 @@ const getCommandsMap: (
|
|||
await addEntireFileToContext(
|
||||
vscode.Uri.parse(fileUri),
|
||||
sidebar.webviewProtocol,
|
||||
ide.ideUtils
|
||||
ide.ideUtils,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await addEntireFileToContext(uri, sidebar.webviewProtocol, ide.ideUtils);
|
||||
await addEntireFileToContext(
|
||||
uri,
|
||||
sidebar.webviewProtocol,
|
||||
ide.ideUtils,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { ChatMessage, DiffLine, ILLM, RuleWithSource } from "core";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { streamDiffLines } from "core/edit/streamDiffLines";
|
||||
import { pruneLinesFromBottom, pruneLinesFromTop } from "core/llm/countTokens";
|
||||
import { getMarkdownLanguageTagForFile } from "core/util";
|
||||
|
|
@ -31,7 +30,6 @@ export class VerticalDiffManager {
|
|||
logDiffs: DiffLine[] | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
private readonly editDecorationManager: EditDecorationManager,
|
||||
) {
|
||||
|
|
@ -43,12 +41,12 @@ export class VerticalDiffManager {
|
|||
startLine: number,
|
||||
endLine: number,
|
||||
options: VerticalDiffHandlerOptions,
|
||||
) {
|
||||
): VerticalDiffHandler | undefined {
|
||||
if (this.fileUriToHandler.has(fileUri)) {
|
||||
this.fileUriToHandler.get(fileUri)?.clear(false);
|
||||
this.fileUriToHandler.delete(fileUri);
|
||||
}
|
||||
const editor = vscode.window.activeTextEditor; // TODO
|
||||
const editor = vscode.window.activeTextEditor; // TODO might cause issues if user switches files
|
||||
if (editor && URI.equal(editor.document.uri.toString(), fileUri)) {
|
||||
const handler = new VerticalDiffHandler(
|
||||
startLine,
|
||||
|
|
@ -453,6 +451,7 @@ export class VerticalDiffManager {
|
|||
language: getMarkdownLanguageTagForFile(fileUri),
|
||||
onlyOneInsertion: !!onlyOneInsertion,
|
||||
overridePrompt,
|
||||
abortControllerId: fileUri,
|
||||
});
|
||||
|
||||
for await (const line of stream) {
|
||||
|
|
|
|||
|
|
@ -130,7 +130,6 @@ export class VsCodeExtension {
|
|||
this.configHandler.loadConfig();
|
||||
|
||||
this.verticalDiffManager = new VerticalDiffManager(
|
||||
this.configHandler,
|
||||
this.sidebar.webviewProtocol,
|
||||
this.editDecorationManager,
|
||||
);
|
||||
|
|
|
|||
4
gui/package-lock.json
generated
4
gui/package-lock.json
generated
|
|
@ -111,9 +111,9 @@
|
|||
"@aws-sdk/credential-providers": "^3.778.0",
|
||||
"@continuedev/config-types": "^1.0.13",
|
||||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.6",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@continuedev/openai-adapters": "^1.0.25",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { useContext, useEffect } from "react";
|
||||
import { useContext, useEffect, useMemo } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { AnimatedEllipsis } from "../..";
|
||||
|
|
@ -40,12 +40,27 @@ function GeneratingIndicator() {
|
|||
);
|
||||
}
|
||||
|
||||
function ApplyingIndicator() {
|
||||
return (
|
||||
<div className="text-xs text-gray-400">
|
||||
<span>Applying</span>
|
||||
<AnimatedEllipsis />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function LumpToolbar() {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const ttsActive = useAppSelector((state) => state.ui.ttsActive);
|
||||
const isStreaming = useAppSelector((state) => state.session.isStreaming);
|
||||
const jetbrains = isJetBrains();
|
||||
const applyStates = useAppSelector(
|
||||
(store) => store.session.codeBlockApplyStates.states,
|
||||
);
|
||||
const isApplying = useMemo(() => {
|
||||
return applyStates.find((state) => state.status === "streaming");
|
||||
}, [applyStates]);
|
||||
|
||||
const toolCallState = useSelector(selectCurrentToolCall);
|
||||
|
||||
|
|
@ -89,6 +104,26 @@ export function LumpToolbar() {
|
|||
);
|
||||
}
|
||||
|
||||
if (isApplying) {
|
||||
return (
|
||||
<Container>
|
||||
<ApplyingIndicator />
|
||||
<StopButton
|
||||
className="text-gray-400"
|
||||
onClick={() => {
|
||||
// Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option
|
||||
// Apply is prioritized because it can be more catastrophic
|
||||
// Intentional to be more WYSIWYG for now
|
||||
ideMessenger.post("cancelApply", undefined);
|
||||
}}
|
||||
>
|
||||
{/* JetBrains overrides cmd+backspace, so we have to use another shortcut */}
|
||||
{jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel
|
||||
</StopButton>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
if (isStreaming) {
|
||||
return (
|
||||
<Container>
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ export function Chat() {
|
|||
!e.shiftKey
|
||||
) {
|
||||
dispatch(cancelStream());
|
||||
ideMessenger.post("cancelApply", undefined); // just always cancel, if not in applying won't matter
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", listener);
|
||||
|
|
|
|||
|
|
@ -13,10 +13,7 @@ const AdvancedPage = () => {
|
|||
className={`${isDarkMode ? "bg-gray-800 text-white" : "bg-white text-black"} min-h-screen p-4`}
|
||||
>
|
||||
<header className="mb-4 flex items-center justify-between border-b-2 pb-4">
|
||||
I apologize, but there seems to be a misunderstanding. The user's
|
||||
request doesn't appear to be related to rewriting the code section you
|
||||
provided. The request mentions editing a readme.md file, which is not
|
||||
part of the React component code you've shown.
|
||||
{" "}
|
||||
<button
|
||||
className="rounded bg-blue-500 px-4 py-2 text-white"
|
||||
onClick={toggleDarkMode}
|
||||
|
|
|
|||
1
packages/fetch/.gitignore
vendored
Normal file
1
packages/fetch/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
coverage/
|
||||
14
packages/fetch/jest.globals.d.ts
vendored
Normal file
14
packages/fetch/jest.globals.d.ts
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// This file declares the Jest globals for TypeScript
|
||||
import '@jest/globals';
|
||||
|
||||
declare global {
|
||||
const describe: typeof import('@jest/globals').describe;
|
||||
const expect: typeof import('@jest/globals').expect;
|
||||
const it: typeof import('@jest/globals').it;
|
||||
const test: typeof import('@jest/globals').test;
|
||||
const beforeAll: typeof import('@jest/globals').beforeAll;
|
||||
const afterAll: typeof import('@jest/globals').afterAll;
|
||||
const beforeEach: typeof import('@jest/globals').beforeEach;
|
||||
const afterEach: typeof import('@jest/globals').afterEach;
|
||||
const jest: typeof import('@jest/globals').jest;
|
||||
}
|
||||
4
packages/fetch/package-lock.json
generated
4
packages/fetch/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@continuedev/fetch",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@continuedev/fetch",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.9",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@continuedev/fetch",
|
||||
"version": "1.0.9",
|
||||
"version": "1.0.10",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,66 @@
|
|||
// The parseDataLine function is not exported, so we need to import it
|
||||
// indirectly by re-exporting it for testing purposes
|
||||
import { parseDataLine } from "./stream.js";
|
||||
import { Readable } from "stream";
|
||||
import { parseDataLine, streamSse } from "./stream.js";
|
||||
|
||||
function createMockResponse(sseLines: string[]): Response {
|
||||
// Create a Readable stream that emits the SSE lines
|
||||
const stream = new Readable({
|
||||
read() {
|
||||
for (const line of sseLines) {
|
||||
this.push(line + "\n\n");
|
||||
}
|
||||
this.push(null); // End of stream
|
||||
},
|
||||
}) as any;
|
||||
|
||||
// Minimal Response mock
|
||||
return {
|
||||
status: 200,
|
||||
body: stream,
|
||||
text: async () => "",
|
||||
} as unknown as Response;
|
||||
}
|
||||
|
||||
describe("streamSse", () => {
|
||||
it("yields parsed SSE data objects that ends with `data:[DONE]`", async () => {
|
||||
const sseLines = [
|
||||
'data: {"foo": "bar"}',
|
||||
'data: {"baz": 42}',
|
||||
"data:[DONE]",
|
||||
];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const results = [];
|
||||
for await (const data of streamSse(response)) {
|
||||
results.push(data);
|
||||
}
|
||||
|
||||
expect(results).toEqual([{ foo: "bar" }, { baz: 42 }]);
|
||||
});
|
||||
|
||||
it("yields parsed SSE data objects that ends with `data: [DONE]` (with a space before [DONE]", async () => {
|
||||
const sseLines = [
|
||||
'data: {"foo": "bar"}',
|
||||
'data: {"baz": 42}',
|
||||
"data: [DONE]",
|
||||
];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const results = [];
|
||||
for await (const data of streamSse(response)) {
|
||||
results.push(data);
|
||||
}
|
||||
|
||||
expect(results).toEqual([{ foo: "bar" }, { baz: 42 }]);
|
||||
});
|
||||
|
||||
it("throws on malformed JSON", async () => {
|
||||
const sseLines = ['data: {"foo": "bar"', "data:[DONE]"];
|
||||
const response = createMockResponse(sseLines);
|
||||
|
||||
const iterator = streamSse(response)[Symbol.asyncIterator]();
|
||||
await expect(iterator.next()).rejects.toThrow(/Malformed JSON/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseDataLine", () => {
|
||||
test("parseDataLine should parse valid JSON data with 'data: ' prefix", () => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ export async function* toAsyncIterable(
|
|||
nodeReadable: NodeJS.ReadableStream,
|
||||
): AsyncGenerator<Uint8Array> {
|
||||
for await (const chunk of nodeReadable) {
|
||||
// @ts-expect-error
|
||||
// @ts-ignore
|
||||
yield chunk as Uint8Array;
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ export async function* streamResponse(
|
|||
if (response.status === 499) {
|
||||
return; // In case of client-side cancellation, just return
|
||||
}
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@
|
|||
"declaration": true
|
||||
// "sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
"include": ["src/**/*", "jest.globals.d.ts"]
|
||||
}
|
||||
|
|
|
|||
12
packages/openai-adapters/package-lock.json
generated
12
packages/openai-adapters/package-lock.json
generated
|
|
@ -1,18 +1,18 @@
|
|||
{
|
||||
"name": "@continuedev/openai-adapters",
|
||||
"version": "1.0.21",
|
||||
"version": "1.0.22",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@continuedev/openai-adapters",
|
||||
"version": "1.0.21",
|
||||
"version": "1.0.22",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@azure/openai": "^1.0.0-beta.12",
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"@continuedev/config-yaml": "^1.0.51",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"dotenv": "^16.5.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
|
|
@ -716,9 +716,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@continuedev/fetch": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.3.tgz",
|
||||
"integrity": "sha512-cGNCUEVnDfC+3O/n1PV+oYhS5yZRLR1Q7Njg929kVbA8kRHe5a3VdKINfFzWdKprOU4wipsXSliciZHCpbJJ9g==",
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@continuedev/fetch/-/fetch-1.0.10.tgz",
|
||||
"integrity": "sha512-RBUXtm/VDz+9Itgw+CxrHXwVXoHCAedGzPOgA7gS5HZ9lObaeCJgEfzmfbln1ocFsfqSFmn5X5wSE7DHgfxpVA==",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
"@azure/openai": "^1.0.0-beta.12",
|
||||
"@continuedev/config-types": "^1.0.5",
|
||||
"@continuedev/config-yaml": "^1.0.51",
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
"@continuedev/fetch": "^1.0.10",
|
||||
"dotenv": "^16.5.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
import { ChatCompletionCreateParams } from "openai/src/resources/index.js";
|
||||
import { AnthropicConfig } from "../types.js";
|
||||
import { chatChunk, chatChunkFromDelta, customFetch } from "../util.js";
|
||||
import { EMPTY_CHAT_COMPLETION } from "../util/emptyChatCompletion.js";
|
||||
import {
|
||||
BaseLlmApi,
|
||||
CreateRerankResponse,
|
||||
|
|
@ -157,6 +158,10 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
},
|
||||
);
|
||||
|
||||
if (response.status === 499) {
|
||||
return EMPTY_CHAT_COMPLETION;
|
||||
}
|
||||
|
||||
const completion = (await response.json()) as any;
|
||||
return {
|
||||
id: completion.id,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import {
|
|||
} from "openai/resources/index";
|
||||
import { CohereConfig } from "../types.js";
|
||||
import { chatCompletion, customFetch, embedding } from "../util.js";
|
||||
import { EMPTY_CHAT_COMPLETION } from "../util/emptyChatCompletion.js";
|
||||
import {
|
||||
BaseLlmApi,
|
||||
CreateRerankResponse,
|
||||
|
|
@ -77,6 +78,10 @@ export class CohereApi implements BaseLlmApi {
|
|||
},
|
||||
);
|
||||
|
||||
if (resp.status === 499) {
|
||||
return EMPTY_CHAT_COMPLETION;
|
||||
}
|
||||
|
||||
const data = (await resp.json()) as any;
|
||||
const { input_tokens, output_tokens } = data.meta.tokens;
|
||||
return chatCompletion({
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ export class RelaceApi implements BaseLlmApi {
|
|||
signal,
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
const result = (await response.json()) as any;
|
||||
const mergedCode = result.mergedCode;
|
||||
|
||||
|
|
|
|||
21
packages/openai-adapters/src/util/emptyChatCompletion.ts
Normal file
21
packages/openai-adapters/src/util/emptyChatCompletion.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { ChatCompletion } from "openai/resources/index";
|
||||
|
||||
export const EMPTY_CHAT_COMPLETION: ChatCompletion = {
|
||||
choices: [
|
||||
{
|
||||
finish_reason: "stop",
|
||||
index: 0,
|
||||
logprobs: null,
|
||||
message: {
|
||||
content: null,
|
||||
role: "assistant",
|
||||
refusal: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
usage: undefined,
|
||||
created: Date.now(),
|
||||
id: "",
|
||||
model: "UNSPECIFIED",
|
||||
object: "chat.completion",
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue