Skip to content

Commit 1ad3d7f

Browse files
authored
Merge pull request #4866 from owtaylor/rich-llm-logging
Rich LLM logging
2 parents de2921d + 6e54e7f commit 1ad3d7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2551
-188
lines changed

Diff for: binary/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
process.env.IS_BINARY = "true";
22
import { Command } from "commander";
33
import { Core } from "core/core";
4+
import { LLMLogFormatter } from "core/llm/logFormatter";
45
import { FromCoreProtocol, ToCoreProtocol } from "core/protocol";
56
import { IMessenger } from "core/protocol/messenger";
67
import { getCoreLogsPath, getPromptLogsPath } from "core/util/paths";
@@ -33,9 +34,8 @@ program.action(async () => {
3334
const ide = new IpcIde(messenger);
3435
const promptLogsPath = getPromptLogsPath();
3536

36-
new Core(messenger, ide, async (text) => {
37-
fs.appendFileSync(promptLogsPath, text + "\n\n");
38-
});
37+
const core = new Core(messenger, ide);
38+
new LLMLogFormatter(core.llmLogger, fs.createWriteStream(promptLogsPath));
3939

4040
console.log("[binary] Core started");
4141
} catch (e) {

Diff for: core/config/ConfigHandler.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IDE,
1313
IdeSettings,
1414
ILLM,
15+
ILLMLogger,
1516
} from "../index.js";
1617
import Ollama from "../llm/llms/Ollama.js";
1718
import { GlobalContext } from "../util/GlobalContext.js";
@@ -48,12 +49,11 @@ export class ConfigHandler {
4849
constructor(
4950
private readonly ide: IDE,
5051
private ideSettingsPromise: Promise<IdeSettings>,
51-
private readonly writeLog: (text: string) => Promise<void>,
52+
private llmLogger: ILLMLogger,
5253
sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
5354
) {
5455
this.ide = ide;
5556
this.ideSettingsPromise = ideSettingsPromise;
56-
this.writeLog = writeLog;
5757
this.controlPlaneClient = new ControlPlaneClient(
5858
sessionInfoPromise,
5959
ideSettingsPromise,
@@ -65,7 +65,7 @@ export class ConfigHandler {
6565
ide,
6666
ideSettingsPromise,
6767
this.controlPlaneClient,
68-
writeLog,
68+
this.llmLogger,
6969
),
7070
this.ide,
7171
);
@@ -184,7 +184,7 @@ export class ConfigHandler {
184184
this.controlPlaneClient,
185185
this.ide,
186186
this.ideSettingsPromise,
187-
this.writeLog,
187+
this.llmLogger,
188188
assistant.rawYaml,
189189
orgScopeId,
190190
);
@@ -229,7 +229,7 @@ export class ConfigHandler {
229229
this.controlPlaneClient,
230230
this.ide,
231231
this.ideSettingsPromise,
232-
this.writeLog,
232+
this.llmLogger,
233233
this.reloadConfig.bind(this),
234234
);
235235

@@ -292,7 +292,7 @@ export class ConfigHandler {
292292
this.ide,
293293
this.ideSettingsPromise,
294294
this.controlPlaneClient,
295-
this.writeLog,
295+
this.llmLogger,
296296
assistant,
297297
);
298298
});

Diff for: core/config/load.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
IdeSettings,
2828
IdeType,
2929
ILLM,
30+
ILLMLogger,
3031
LLMOptions,
3132
ModelDescription,
3233
RerankerDescription,
@@ -222,7 +223,7 @@ async function intermediateToFinalConfig(
222223
ideSettings: IdeSettings,
223224
ideInfo: IdeInfo,
224225
uniqueId: string,
225-
writeLog: (log: string) => Promise<void>,
226+
llmLogger: ILLMLogger,
226227
workOsAccessToken: string | undefined,
227228
loadPromptFiles: boolean = true,
228229
allowFreeTrial: boolean = true,
@@ -238,7 +239,7 @@ async function intermediateToFinalConfig(
238239
ide.readFile.bind(ide),
239240
uniqueId,
240241
ideSettings,
241-
writeLog,
242+
llmLogger,
242243
config.completionOptions,
243244
config.systemMessage,
244245
);
@@ -260,7 +261,7 @@ async function intermediateToFinalConfig(
260261
ide.readFile.bind(ide),
261262
uniqueId,
262263
ideSettings,
263-
writeLog,
264+
llmLogger,
264265
copyOf(config.completionOptions),
265266
config.systemMessage,
266267
);
@@ -280,7 +281,7 @@ async function intermediateToFinalConfig(
280281
} else {
281282
const llm = new CustomLLMClass({
282283
...desc,
283-
options: { ...desc.options, writeLog } as any,
284+
options: { ...desc.options, logger: llmLogger } as any,
284285
});
285286
if (llm.model === "AUTODETECT") {
286287
try {
@@ -289,7 +290,11 @@ async function intermediateToFinalConfig(
289290
(modelName) =>
290291
new CustomLLMClass({
291292
...desc,
292-
options: { ...desc.options, model: modelName, writeLog },
293+
options: {
294+
...desc.options,
295+
model: modelName,
296+
logger: llmLogger,
297+
},
293298
}),
294299
);
295300

@@ -343,7 +348,7 @@ async function intermediateToFinalConfig(
343348
ide.readFile.bind(ide),
344349
uniqueId,
345350
ideSettings,
346-
writeLog,
351+
llmLogger,
347352
config.completionOptions,
348353
config.systemMessage,
349354
);
@@ -831,7 +836,7 @@ async function loadContinueConfigFromJson(
831836
ideSettings: IdeSettings,
832837
ideInfo: IdeInfo,
833838
uniqueId: string,
834-
writeLog: (log: string) => Promise<void>,
839+
llmLogger: ILLMLogger,
835840
workOsAccessToken: string | undefined,
836841
overrideConfigJson: SerializedContinueConfig | undefined,
837842
): Promise<ConfigResult<ContinueConfig>> {
@@ -931,7 +936,7 @@ async function loadContinueConfigFromJson(
931936
ideSettings,
932937
ideInfo,
933938
uniqueId,
934-
writeLog,
939+
llmLogger,
935940
workOsAccessToken,
936941
);
937942
return {

Diff for: core/config/profile/ControlPlaneProfileLoader.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ContinueConfig,
88
IDE,
99
IdeSettings,
10+
ILLMLogger,
1011
SerializedContinueConfig,
1112
} from "../../index.js";
1213
import { ProfileDescription } from "../ProfileLifecycleManager.js";
@@ -27,7 +28,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
2728
private readonly controlPlaneClient: ControlPlaneClient,
2829
private readonly ide: IDE,
2930
private ideSettingsPromise: Promise<IdeSettings>,
30-
private writeLog: (message: string) => Promise<void>,
31+
private llmLogger: ILLMLogger,
3132
private readonly onReload: () => void,
3233
) {
3334
this.description = {
@@ -65,7 +66,7 @@ export default class ControlPlaneProfileLoader implements IProfileLoader {
6566
this.ide,
6667
this.ideSettingsPromise,
6768
this.controlPlaneClient,
68-
this.writeLog,
69+
this.llmLogger,
6970
serializedConfig,
7071
undefined,
7172
undefined,

Diff for: core/config/profile/LocalProfileLoader.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
22

33
import { ControlPlaneClient } from "../../control-plane/client.js";
4-
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
4+
import { ContinueConfig, IDE, IdeSettings, ILLMLogger } from "../../index.js";
55
import { ProfileDescription } from "../ProfileLifecycleManager.js";
66

77
import { getPrimaryConfigFilePath } from "../../util/paths.js";
@@ -17,7 +17,7 @@ export default class LocalProfileLoader implements IProfileLoader {
1717
private ide: IDE,
1818
private ideSettingsPromise: Promise<IdeSettings>,
1919
private controlPlaneClient: ControlPlaneClient,
20-
private writeLog: (message: string) => Promise<void>,
20+
private llmLogger: ILLMLogger,
2121
private overrideAssistantFile?:
2222
| { path: string; content: string }
2323
| undefined,
@@ -59,7 +59,7 @@ export default class LocalProfileLoader implements IProfileLoader {
5959
this.ide,
6060
this.ideSettingsPromise,
6161
this.controlPlaneClient,
62-
this.writeLog,
62+
this.llmLogger,
6363
undefined,
6464
undefined,
6565
undefined,

Diff for: core/config/profile/PlatformProfileLoader.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AssistantUnrolled, ConfigResult } from "@continuedev/config-yaml";
22

33
import { ControlPlaneClient } from "../../control-plane/client.js";
44
import { getControlPlaneEnv } from "../../control-plane/env.js";
5-
import { ContinueConfig, IDE, IdeSettings } from "../../index.js";
5+
import { ContinueConfig, IDE, IdeSettings, ILLMLogger } from "../../index.js";
66
import { ProfileDescription } from "../ProfileLifecycleManager.js";
77

88
import doLoadConfig from "./doLoadConfig.js";
@@ -30,7 +30,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
3030
private readonly controlPlaneClient: ControlPlaneClient,
3131
private readonly ide: IDE,
3232
private ideSettingsPromise: Promise<IdeSettings>,
33-
private writeLog: (message: string) => Promise<void>,
33+
private llmLogger: ILLMLogger,
3434
readonly description: ProfileDescription,
3535
private readonly orgScopeId: string | null,
3636
) {}
@@ -44,7 +44,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
4444
controlPlaneClient: ControlPlaneClient,
4545
ide: IDE,
4646
ideSettingsPromise: Promise<IdeSettings>,
47-
writeLog: (message: string) => Promise<void>,
47+
llmLogger: ILLMLogger,
4848
rawYaml: string,
4949
orgScopeId: string | null,
5050
): Promise<PlatformProfileLoader> {
@@ -74,7 +74,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
7474
controlPlaneClient,
7575
ide,
7676
ideSettingsPromise,
77-
writeLog,
77+
llmLogger,
7878
description,
7979
orgScopeId,
8080
);
@@ -93,7 +93,7 @@ export default class PlatformProfileLoader implements IProfileLoader {
9393
this.ide,
9494
this.ideSettingsPromise,
9595
this.controlPlaneClient,
96-
this.writeLog,
96+
this.llmLogger,
9797
undefined,
9898
this.configResult.config,
9999
{

Diff for: core/config/profile/doLoadConfig.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ContinueRcJson,
1313
IDE,
1414
IdeSettings,
15+
ILLMLogger,
1516
SerializedContinueConfig,
1617
Tool,
1718
} from "../../";
@@ -39,7 +40,7 @@ export default async function doLoadConfig(
3940
ide: IDE,
4041
ideSettingsPromise: Promise<IdeSettings>,
4142
controlPlaneClient: ControlPlaneClient,
42-
writeLog: (message: string) => Promise<void>,
43+
llmLogger: ILLMLogger,
4344
overrideConfigJson: SerializedContinueConfig | undefined,
4445
overrideConfigYaml: AssistantUnrolled | undefined,
4546
platformConfigMetadata: PlatformConfigMetadata | undefined,
@@ -74,7 +75,7 @@ export default async function doLoadConfig(
7475
ideSettings,
7576
ideInfo,
7677
uniqueId,
77-
writeLog,
78+
llmLogger,
7879
workOsAccessToken,
7980
overrideConfigYaml,
8081
platformConfigMetadata,
@@ -92,7 +93,7 @@ export default async function doLoadConfig(
9293
ideSettings,
9394
ideInfo,
9495
uniqueId,
95-
writeLog,
96+
llmLogger,
9697
workOsAccessToken,
9798
overrideConfigJson,
9899
);

0 commit comments

Comments
 (0)