Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/commands/slash/built-in-legacy/commit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SlashCommand } from "../../../index.js";
import { renderChatMessage } from "../../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../../util/messageContent.js";

const CommitMessageCommand: SlashCommand = {
name: "commit",
Expand All @@ -18,7 +18,7 @@ const CommitMessageCommand: SlashCommand = {
[{ role: "user", content: prompt }],
abortController.signal,
)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
},
};
Expand Down
4 changes: 2 additions & 2 deletions core/commands/slash/built-in-legacy/draftIssue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChatMessage, SlashCommand } from "../../../index.js";
import { removeQuotesAndEscapes } from "../../../util/index.js";
import { renderChatMessage } from "../../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../../util/messageContent.js";

const PROMPT = (
input: string,
Expand Down Expand Up @@ -49,7 +49,7 @@ const DraftIssueCommand: SlashCommand = {
abortController.signal,
)) {
body += chunk.content;
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}

const url = `${params.repositoryUrl}/issues/new?title=${encodeURIComponent(
Expand Down
4 changes: 2 additions & 2 deletions core/commands/slash/built-in-legacy/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ignore from "ignore";
import type { FileType, IDE, SlashCommand } from "../../..";
import { getGlobalContinueIgArray } from "../../../indexing/continueignore";
import { DEFAULT_IGNORE, gitIgArrayFromFile } from "../../../indexing/ignore";
import { renderChatMessage } from "../../../util/messageContent";
import { renderChatMessageWithoutThinking } from "../../../util/messageContent";
import {
findUriInDirs,
getUriPathBasename,
Expand Down Expand Up @@ -48,7 +48,7 @@ const OnboardSlashCommand: SlashCommand = {
[{ role: "user", content: prompt }],
abortController.signal,
)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
},
};
Expand Down
4 changes: 2 additions & 2 deletions core/commands/slash/built-in-legacy/review.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatMessage, SlashCommand } from "../../../index.js";
import { renderChatMessage } from "../../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../../util/messageContent.js";

const prompt = `
Review the following code, focusing on Readability, Maintainability, Code Smells, Speed, and Memory Performance. Provide feedback with these guidelines:
Expand Down Expand Up @@ -47,7 +47,7 @@ const ReviewMessageCommand: SlashCommand = {
[{ role: "user", content: content }],
abortController.signal,
)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
},
};
Expand Down
6 changes: 4 additions & 2 deletions core/diff/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { distance } from "fastest-levenshtein";

import { ChatMessage } from "../index.js";
import { renderChatMessage } from "../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../util/messageContent.js";

export type LineStream = AsyncGenerator<string>;

Expand Down Expand Up @@ -108,7 +108,9 @@ export async function* streamLines(
try {
for await (const update of streamCompletion) {
const chunk =
typeof update === "string" ? update : renderChatMessage(update);
typeof update === "string"
? update
: renderChatMessageWithoutThinking(update);
buffer += chunk;
const lines = buffer.split("\n");
buffer = lines.pop() ?? "";
Expand Down
7 changes: 5 additions & 2 deletions core/llm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import { isAbortError } from "../util/isAbortError.js";
import { isLemonadeInstalled } from "../util/lemonadeHelper.js";
import { Logger } from "../util/Logger.js";
import mergeJson from "../util/merge.js";
import { renderChatMessage } from "../util/messageContent.js";
import {
renderChatMessage,
renderChatMessageWithoutThinking,
} from "../util/messageContent.js";
import { isOllamaInstalled } from "../util/ollamaHelper.js";
import { TokensBatchingService } from "../util/TokensBatchingService.js";
import { withExponentialBackoff } from "../util/withExponentialBackoff.js";
Expand Down Expand Up @@ -964,7 +967,7 @@ export abstract class BaseLLM implements ILLM {
) {
let completion = "";
for await (const message of this.streamChat(messages, signal, options)) {
completion += renderChatMessage(message);
completion += renderChatMessageWithoutThinking(message);
}
return { role: "assistant" as const, content: completion };
}
Expand Down
8 changes: 6 additions & 2 deletions core/llm/llms/Anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
Usage,
} from "../../index.js";
import { safeParseToolCallArgs } from "../../tools/parseArgs.js";
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
import {
renderChatMessage,
renderChatMessageWithoutThinking,
stripImages,
} from "../../util/messageContent.js";
import { extractBase64FromDataUrl } from "../../util/url.js";
import { DEFAULT_REASONING_TOKENS } from "../constants.js";
import { BaseLLM } from "../index.js";
Expand Down Expand Up @@ -258,7 +262,7 @@ class Anthropic extends BaseLLM {
): AsyncGenerator<string> {
const messages = [{ role: "user" as const, content: prompt }];
for await (const update of this._streamChat(messages, signal, options)) {
yield renderChatMessage(update);
yield renderChatMessageWithoutThinking(update);
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/llm/llms/Bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import type { CompletionOptions } from "../../index.js";
import { ChatMessage, Chunk, LLMOptions, MessageContent } from "../../index.js";
import { safeParseToolCallArgs } from "../../tools/parseArgs.js";
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
import {
renderChatMessageWithoutThinking,
stripImages,
} from "../../util/messageContent.js";
import { parseDataUrl } from "../../util/url.js";
import { BaseLLM } from "../index.js";
import { PROVIDER_TOOL_SUPPORT } from "../toolSupport.js";
Expand Down Expand Up @@ -100,7 +103,7 @@ class Bedrock extends BaseLLM {
): AsyncGenerator<string> {
const messages = [{ role: "user" as const, content: prompt }];
for await (const update of this._streamChat(messages, signal, options)) {
yield renderChatMessage(update);
yield renderChatMessageWithoutThinking(update);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/llm/llms/Cloudflare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { streamSse } from "@continuedev/fetch";
import { ChatMessage, CompletionOptions } from "../../index.js";
import { renderChatMessage } from "../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";

export default class Cloudflare extends BaseLLM {
Expand Down Expand Up @@ -59,7 +59,7 @@ export default class Cloudflare extends BaseLLM {
signal,
options,
)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
}
}
7 changes: 5 additions & 2 deletions core/llm/llms/Cohere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
CompletionOptions,
LLMOptions,
} from "../../index.js";
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
import {
renderChatMessageWithoutThinking,
stripImages,
} from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";
import { DEFAULT_REASONING_TOKENS } from "../constants.js";

Expand Down Expand Up @@ -148,7 +151,7 @@ class Cohere extends BaseLLM {
): AsyncGenerator<string> {
const messages = [{ role: "user" as const, content: prompt }];
for await (const update of this._streamChat(messages, signal, options)) {
yield renderChatMessage(update);
yield renderChatMessageWithoutThinking(update);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/llm/llms/CustomLLM.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatMessage, CompletionOptions, CustomLLM } from "../../index.js";
import { renderChatMessage } from "../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";

class CustomLLMClass extends BaseLLM {
Expand Down Expand Up @@ -76,7 +76,7 @@ class CustomLLMClass extends BaseLLM {
if (typeof content === "string") {
yield content;
} else {
yield renderChatMessage(content);
yield renderChatMessageWithoutThinking(content);
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/llm/llms/Flowise.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import socketIOClient, { Socket } from "socket.io-client";

import { ChatMessage, CompletionOptions, LLMOptions } from "../../index.js";
import { renderChatMessage } from "../../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";

interface IFlowiseApiOptions {
Expand Down Expand Up @@ -121,7 +121,7 @@ class Flowise extends BaseLLM {
): AsyncGenerator<string> {
const message: ChatMessage = { role: "user", content: prompt };
for await (const chunk of this._streamChat([message], signal, options)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/llm/llms/Gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
ToolCallDelta,
} from "../../index.js";
import { safeParseToolCallArgs } from "../../tools/parseArgs.js";
import { renderChatMessage, stripImages } from "../../util/messageContent.js";
import {
renderChatMessageWithoutThinking,
stripImages,
} from "../../util/messageContent.js";
import { extractBase64FromDataUrl } from "../../util/url.js";
import { BaseLLM } from "../index.js";
import { LlmApiRequestType } from "../openaiTypeConverters.js";
Expand Down Expand Up @@ -89,7 +92,7 @@ class Gemini extends BaseLLM {
signal,
options,
)) {
yield renderChatMessage(message);
yield renderChatMessageWithoutThinking(message);
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/llm/llms/OpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
LLMOptions,
Tool,
} from "../../index.js";
import { renderChatMessage } from "../../util/messageContent.js";
import {
renderChatMessage,
renderChatMessageWithoutThinking,
} from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";
import {
fromChatCompletionChunk,
Expand Down Expand Up @@ -430,7 +433,7 @@ class OpenAI extends BaseLLM {
signal,
options,
)) {
yield renderChatMessage(chunk);
yield renderChatMessageWithoutThinking(chunk);
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/llm/llms/VertexAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { AuthClient, GoogleAuth, JWT, auth } 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 {
renderChatMessageWithoutThinking,
stripImages,
} from "../../util/messageContent.js";
import { BaseLLM } from "../index.js";

import { LlmApiRequestType } from "../openaiTypeConverters.js";
Expand Down Expand Up @@ -489,7 +492,7 @@ class VertexAI extends BaseLLM {
signal,
options,
)) {
yield renderChatMessage(message);
yield renderChatMessageWithoutThinking(message);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/util/historyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path";

import { languageForFilepath } from "../autocomplete/constants/AutocompleteLanguageInfo.js";
import { ChatMessage, IDE } from "../index.js";
import { renderChatMessage } from "../util/messageContent.js";
import { renderChatMessageWithoutThinking } from "../util/messageContent.js";
import { getContinueGlobalPath } from "../util/paths.js";

// If useful elsewhere, helper funcs should move to core/util/index.ts or similar
Expand Down Expand Up @@ -45,7 +45,7 @@ export function toMarkDown(history: ChatMessage[], time?: Date): string {
let content = `### [Continue](https://continue.dev) session transcript\n Exported: ${time.toLocaleString()}`;

for (const msg of history) {
let msgText = renderChatMessage(msg);
let msgText = renderChatMessageWithoutThinking(msg);
if (!msgText) {
continue; // Skip messages without content
}
Expand Down
5 changes: 5 additions & 0 deletions core/util/messageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function stripImages(messageContent: MessageContent): string {
.join("\n");
}

export function renderChatMessageWithoutThinking(message: ChatMessage): string {
if (message.role === "thinking") return "";
return renderChatMessage(message);
}

export function renderChatMessage(message: ChatMessage): string {
switch (message?.role) {
case "user":
Expand Down
Loading