🚧 dev data logging
This commit is contained in:
parent
0c1afdeecf
commit
0053cab91a
7 changed files with 45 additions and 13 deletions
7
core/llm/types.d.ts
vendored
7
core/llm/types.d.ts
vendored
|
|
@ -34,16 +34,17 @@ interface ContextItem {
|
|||
interface ChatHistoryItem {
|
||||
message: ChatMessage;
|
||||
contextItems: ContextItem[];
|
||||
promptLogs?: [string, string][]; // [prompt, completion]
|
||||
}
|
||||
|
||||
type ChatHistory = ChatHistoryItem[];
|
||||
|
||||
export {
|
||||
CompletionOptions,
|
||||
ChatMessage,
|
||||
ChatMessageRole,
|
||||
ChatHistory,
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
ChatMessageRole,
|
||||
CompletionOptions,
|
||||
ContextItem,
|
||||
ContextItemId,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,3 +39,7 @@ export function devDataPath(): string {
|
|||
}
|
||||
return sPath;
|
||||
}
|
||||
|
||||
export function getDevDataFilePath(fileName: string): string {
|
||||
return path.join(devDataPath(), fileName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { FileEdit } from "core/types";
|
||||
import { getConfigJsonPath } from "core/util/paths";
|
||||
import { getConfigJsonPath, getDevDataFilePath } from "core/util/paths";
|
||||
import { writeFileSync } from "fs";
|
||||
import * as io from "socket.io-client";
|
||||
import * as vscode from "vscode";
|
||||
import { ideProtocolClient, windowId } from "./activation/activate";
|
||||
|
|
@ -329,6 +330,12 @@ export function getSidebarContent(
|
|||
vscode.window.showErrorMessage(data.message);
|
||||
break;
|
||||
}
|
||||
case "logDevData": {
|
||||
const filepath: string = getDevDataFilePath(data.message.tableName);
|
||||
const jsonLine = JSON.stringify(data.message.data);
|
||||
writeFileSync(filepath, `${jsonLine}\n`, { flag: "a" });
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from "..";
|
||||
import { RootStore } from "../../redux/store";
|
||||
import { getFontSize } from "../../util";
|
||||
import { logDevData } from "../../util/ide";
|
||||
import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview";
|
||||
|
||||
interface StepContainerProps {
|
||||
|
|
@ -79,15 +80,12 @@ function StepContainer(props: StepContainerProps) {
|
|||
const [feedback, setFeedback] = useState<boolean | undefined>(undefined);
|
||||
|
||||
const sendFeedback = (feedback: boolean) => {
|
||||
// TODO: Feedback
|
||||
// setFeedback(feedback);
|
||||
// console.log(sessionHistory, props.index);
|
||||
// const logs = sessionHistory[props.index].logs;
|
||||
// if (!logs || logs.length < 1) return;
|
||||
// const prompt = logs[0].split("#########\n")[1];
|
||||
// const completion = props.item.message.content;
|
||||
// console.log(prompt, completion, client);
|
||||
// client?.sendPromptCompletionFeedback("chat", prompt, completion, feedback);
|
||||
setFeedback(feedback);
|
||||
if (props.item.promptLogs?.length) {
|
||||
for (const [prompt, completion] of props.item.promptLogs) {
|
||||
logDevData("chat", { prompt, completion, feedback });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
|
|||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import {
|
||||
addContextItems,
|
||||
addLogs,
|
||||
resubmitAtIndex,
|
||||
setInactive,
|
||||
streamUpdate,
|
||||
|
|
@ -134,12 +135,25 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
// Determine if the input is a slash command
|
||||
let commandAndInput = getSlashCommandForInput(input);
|
||||
|
||||
const logs = [];
|
||||
const writeLog = async (log: string) => {
|
||||
logs.push(log);
|
||||
};
|
||||
defaultModel.writeLog = writeLog;
|
||||
if (!commandAndInput) {
|
||||
await _streamNormalInput(messages);
|
||||
} else {
|
||||
const [slashCommand, commandInput] = commandAndInput;
|
||||
await _streamSlashCommand(messages, slashCommand, commandInput);
|
||||
}
|
||||
|
||||
defaultModel.writeLog = undefined;
|
||||
const pairedLogs = [];
|
||||
for (let i = 0; i < logs.length; i += 2) {
|
||||
pairedLogs.push([logs[i], logs[i + 1]]);
|
||||
}
|
||||
dispatch(addLogs(pairedLogs));
|
||||
|
||||
dispatch(setInactive());
|
||||
} catch (e) {
|
||||
errorPopup(e.message);
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ export const stateSlice = createSlice({
|
|||
defaultModelTitle,
|
||||
};
|
||||
},
|
||||
addLogs: (state, { payload }: { payload: [string, string][] }) => {
|
||||
state.history[state.history.length - 1].promptLogs.push(...payload);
|
||||
},
|
||||
addContextItemsAtIndex: (state, action) => {
|
||||
if (action.payload.index < state.history.length) {
|
||||
return {
|
||||
|
|
@ -372,5 +375,6 @@ export const {
|
|||
setEditingAtIds,
|
||||
setDefaultModel,
|
||||
setConfig,
|
||||
addLogs,
|
||||
} = stateSlice.actions;
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
|
|
@ -65,3 +65,7 @@ export async function withProgress(title: string, fn: () => Promise<any>) {
|
|||
export function errorPopup(message: string) {
|
||||
postToIde("errorPopup", { message });
|
||||
}
|
||||
|
||||
export function logDevData(tableName: string, data: any) {
|
||||
postToIde("logDevData", { tableName, data });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue