release parallel test

This commit is contained in:
锦恢 2025-07-13 23:59:02 +08:00
parent 0dc727e781
commit 1c8a447dc7
9 changed files with 66 additions and 22 deletions

View File

@ -1,6 +1,7 @@
import { pinkLog, redLog } from '@/views/setting/util';
import { acquireVsCodeApi, electronApi, getPlatform } from './platform';
import { isReactive } from 'vue';
import { v4 as uuidv4 } from 'uuid';
export interface VSCodeMessage {
command: string;
@ -9,6 +10,7 @@ export interface VSCodeMessage {
}
export interface RestFulResponse<T = any> {
_id?: string
code: number;
msg: T;
}
@ -163,8 +165,8 @@ export class MessageBridge {
const command = message.command;
const data = message.data;
const handlers = this.handlers.get(command) || [];
handlers.forEach(handler => handler(data));
const handlers = this.handlers.get(command) || new Set();
handlers.forEach(handler => handler(data));
}
public postMessage(message: VSCodeMessage) {
@ -231,15 +233,22 @@ export class MessageBridge {
* @returns
*/
public commandRequest<T = any>(command: string, data?: ICommandRequestData): Promise<RestFulResponse<T>> {
return new Promise<RestFulResponse>((resolve, reject) => {
this.addCommandListener(command, (data) => {
resolve(data as RestFulResponse);
}, { once: true });
const _id = uuidv4();
return new Promise<RestFulResponse>((resolve, reject) => {
const handler = this.addCommandListener(command, (data) => {
if (data._id === _id) {
handler();
resolve(data as RestFulResponse);
}
}, { once: false });
this.postMessage({
command,
data: this.deserializeReactiveData(data)
command,
data: this.deserializeReactiveData({
_id,
...data
})
});
});
}

View File

@ -221,6 +221,7 @@ export class TaskLoop {
}, { once: false });
const doneHandler = this.bridge.addCommandListener('llm/chat/completions/done', data => {
if (data.sessionId !== sessionId) {
return;
}
@ -229,11 +230,12 @@ export class TaskLoop {
chunkHandler();
errorHandler();
doneHandler();
resolve({
stop: false
});
}, { once: true });
}, { once: false });
const errorHandler = this.bridge.addCommandListener('llm/chat/completions/error', data => {
if (data.sessionId !== sessionId) {
@ -246,13 +248,14 @@ export class TaskLoop {
});
chunkHandler();
errorHandler();
doneHandler();
resolve({
stop: true
});
}, { once: true });
}, { once: false });
this.bridge.postMessage({
command: 'llm/chat/completions',

View File

@ -182,7 +182,7 @@ const toolcallPercent = computed(() => {
.item-json {
border-radius: 4px;
padding: 6px 10px;
font-size: 15px;
font-size: 13px;
font-family: var(--code-font-family, monospace);
margin: 2px 0 8px 0;
white-space: pre-wrap;
@ -193,6 +193,7 @@ const toolcallPercent = computed(() => {
}
.code-container {
font-size: 13px;
margin-top: 10px;
border-radius: .3em;
padding: 0 10px;

View File

@ -51,6 +51,7 @@ export interface NodeDataView {
export interface DiagramContext {
preset: (type: string) => void,
render: () => void,
resetDataView: () => void,
state?: DiagramState,
setCaption: (value: string) => void
}
@ -178,7 +179,7 @@ export async function makeNodeTest(
context.render();
try {
const loop = new TaskLoop({ maxEpochs: 1 });
const loop = new TaskLoop({ maxEpochs: 1, verbose: 0 });
const usePrompt = (prompt || 'please call the tool {tool} to make some test').replace('{tool}', dataView.tool.name);
const chatStorage = {
messages: [],
@ -198,8 +199,6 @@ export async function makeNodeTest(
}
} as ChatStorage;
loop.setMaxEpochs(1);
let aiMockJson: any = undefined;
loop.registerOnToolCall(toolCall => {
@ -225,7 +224,7 @@ export async function makeNodeTest(
return toolCall;
});
loop.registerOnToolCalled(toolCalled => {
loop.registerOnToolCalled(toolCalled => {
dataView.toolcallTimecost = Date.now() - createAt - dataView.llmTimecost!;
if (toolCalled.state === MessageState.Success) {

View File

@ -188,7 +188,7 @@ const drawDiagram = async () => {
// edges
const reservedEdges = autoDetectDiagram?.edges;
if (reservedEdges && reservedEdges.length > 0) {
if (reservedEdges) {
for (const edge of reservedEdges) {
if (edge.sources && edge.targets && edge.sources.length > 0 && edge.targets.length > 0) {
edges.push({
@ -662,6 +662,24 @@ function getNodePopupStyle(node: any): any {
height: `${popupHeight}px`
};
}
//
function resetDataView() {
state.dataView.forEach((view, key) => {
state.dataView.set(key, {
...view,
status: 'waiting',
result: null,
createAt: undefined,
finishAt: undefined,
llmTimecost: undefined,
toolcallTimecost: undefined
});
});
}
context.resetDataView = resetDataView;
</script>
<style>

View File

@ -73,7 +73,7 @@
<script setup lang="ts">
import { computed, nextTick, provide, ref } from 'vue';
import Diagram from './diagram.vue';
import { makeNodeTest, makeParallelTest, topoSortParallel, type DiagramContext, type DiagramState } from './diagram';
import { makeNodeTest, topoSortParallel, type DiagramContext } from './diagram';
import { ElMessage } from 'element-plus';
import { useI18n } from 'vue-i18n';
@ -118,6 +118,7 @@ function setCaption(text: string) {
const context: DiagramContext = {
preset: () => { },
render: () => { },
resetDataView: () => { },
state: undefined,
setCaption
};
@ -149,6 +150,10 @@ async function onTestConfirm() {
tabStorage.autoDetectDiagram!.views = [];
//
context.resetDataView();
context.render();
if (state) {
const dispatches = topoSortParallel(state);

View File

@ -23,15 +23,21 @@ export async function routeMessage(command: string, data: any, webview: PostMess
try {
const res = await handler(data, webview);
// res.code = -1 代表当前请求不需要返回发送
if (res.code >= 0) {
webview.postMessage({ command, data: res });
webview.postMessage({
command, data: {
_id: data._id,
...res
}
});
}
} catch (error) {
// console.error(error);
webview.postMessage({
command, data: {
_id: data._id,
code: 500,
msg: (error as any).toString()
}

View File

@ -60,8 +60,8 @@ export async function streamingChatCompletion(
}
// 流式传输结果
for await (const chunk of stream) {
if (!chatStreams.has(sessionId)) {
for await (const chunk of stream) {
if (!chatStreams.has(sessionId)) {
// 如果流被中止,则停止循环
stream.controller.abort();
webview.postMessage({
@ -92,6 +92,8 @@ export async function streamingChatCompletion(
}
}
console.log('sessionId finish ' + sessionId);
// 传输结束,移除对应的 stream
if (sessionId) {
chatStreams.delete(sessionId);

View File

@ -110,6 +110,7 @@ wss.on('connection', (ws) => {
webview.postMessage({
command: 'web/launch-signature',
data: {
_id: data._id,
code: 200,
msg: option.items
}