Skip to content

Commit 7e59ba3

Browse files
author
Jicheng Lu
committed
add instruction log page
1 parent b5769e7 commit 7e59ba3

File tree

9 files changed

+437
-0
lines changed

9 files changed

+437
-0
lines changed

src/lib/helpers/types/instructTypes.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,32 @@
1111
* @property {string} [instruction]
1212
* @property {string} [provider]
1313
* @property {string} [model]
14+
* @property {string?} [template]
1415
* @property {import('$conversationTypes').ConversationStateModel[]} [states]
1516
*/
1617

18+
/**
19+
* @typedef {Object} InstructLogFilter
20+
* @property {number} page - The page number
21+
* @property {number} size - The page size
22+
* @property {string[]?} [agentIds]
23+
* @property {string[]?} [providers]
24+
* @property {string[]?} [models]
25+
* @property {string[]?} [templateNames]
26+
*/
27+
28+
/**
29+
* @typedef {Object} InstructionLogModel
30+
* @property {string} [id]
31+
* @property {string?} [agent_id]
32+
* @property {string?} [agent_name]
33+
* @property {string} provider
34+
* @property {string} model
35+
* @property {string?} [template_name]
36+
* @property {string} user_message
37+
* @property {string?} [system_instruction]
38+
* @property {string} completion_text
39+
* @property {Date} created_time
40+
*/
41+
1742
export default {};

src/lib/helpers/utils/common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,13 @@ export function truncateByPrefix(str, prefix) {
6767
}
6868

6969
return str.replace(prefix, '');
70+
}
71+
72+
73+
/**
74+
* @param {any[]} arr
75+
* @param {string | number} key
76+
*/
77+
export function removeDuplicates(arr, key) {
78+
return [...new Map(arr.map(item => [item[key], item])).values()];
7079
}

src/lib/scss/custom/pages/_instruction.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,21 @@
8282
gap: 30px;
8383
justify-content: center;
8484
}
85+
}
86+
87+
.instruction-log-col {
88+
max-width: 150px;
89+
}
90+
91+
.instruction-log-detail-container {
92+
display: flex;
93+
flex-direction: column;
94+
gap: 20px;
95+
padding: 10px 5px;
96+
97+
.instruction-log-message {
98+
overflow-y: auto;
99+
max-height: 350px;
100+
scrollbar-width: none;
101+
}
85102
}

src/lib/services/api-endpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const endpoints = {
4545
// agent instruct
4646
instructCompletionUrl: `${host}/instruct/{agentId}`,
4747
chatCompletionUrl: `${host}/instruct/chat-completion`,
48+
instructLogUrl: `${host}/logger/instruction/log`,
4849

4950
// agent realtime interaction
5051
agentInitRealtimeSessionUrl: `${host}/agent/{agentId}/realtime/session`,

src/lib/services/instruct-service.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,23 @@ export async function sendChatCompletion(request) {
2222
const response = await axios.post(url, request);
2323
return response.data;
2424
}
25+
26+
27+
/**
28+
* Get instruction logs
29+
* @param {import('$instructTypes').InstructLogFilter} filter
30+
* @returns {Promise<import('$commonTypes').PagedItems<import('$instructTypes').InstructionLogModel>>}
31+
*/
32+
export async function getInstructionLogs(filter) {
33+
const url = endpoints.instructLogUrl;
34+
const response = await axios.get(url, {
35+
params: {
36+
...filter
37+
},
38+
paramsSerializer: {
39+
dots: true,
40+
indexes: null,
41+
}
42+
});
43+
return response.data;
44+
}

src/routes/page/instruction/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
4848
/** @type {string | null} */
4949
let selectedModel = null;
50+
51+
/** @type {string | null} */
52+
let selectedTemplate = null;
5053
5154
/** @type {import('$agentTypes').AgentModel[]} */
5255
let agents = [];
@@ -87,6 +90,7 @@
8790
agentId: selectedAgent?.id,
8891
provider: selectedProvider?.provider || DEFAULT_PROVIDER,
8992
model: selectedModel || DEFAULT_MODEL,
93+
template: selectedTemplate,
9094
states: formattedStates
9195
}).then(res => {
9296
result = res || '';
@@ -137,6 +141,7 @@
137141
instruction = selectedAgent?.instruction || '';
138142
139143
const template = e.detail.template || null;
144+
selectedTemplate = template?.name || null;
140145
if (!!template) {
141146
instruction = template?.content || '';
142147
}

0 commit comments

Comments
 (0)