release parallel test
This commit is contained in:
parent
0dc727e781
commit
1c8a447dc7
@ -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>> {
|
||||
const _id = uuidv4();
|
||||
|
||||
return new Promise<RestFulResponse>((resolve, reject) => {
|
||||
this.addCommandListener(command, (data) => {
|
||||
resolve(data as RestFulResponse);
|
||||
}, { once: true });
|
||||
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
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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;
|
||||
|
@ -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 => {
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
|
||||
|
@ -26,12 +26,18 @@ export async function routeMessage(command: string, data: any, webview: PostMess
|
||||
|
||||
// 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()
|
||||
}
|
||||
|
@ -92,6 +92,8 @@ export async function streamingChatCompletion(
|
||||
}
|
||||
}
|
||||
|
||||
console.log('sessionId finish ' + sessionId);
|
||||
|
||||
// 传输结束,移除对应的 stream
|
||||
if (sessionId) {
|
||||
chatStreams.delete(sessionId);
|
||||
|
@ -110,6 +110,7 @@ wss.on('connection', (ws) => {
|
||||
webview.postMessage({
|
||||
command: 'web/launch-signature',
|
||||
data: {
|
||||
_id: data._id,
|
||||
code: 200,
|
||||
msg: option.items
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user