diff --git a/common/types/chat_saved_object_attributes.ts b/common/types/chat_saved_object_attributes.ts index acfc8d71..118ca75f 100644 --- a/common/types/chat_saved_object_attributes.ts +++ b/common/types/chat_saved_object_attributes.ts @@ -18,7 +18,7 @@ export interface Interaction { export interface ISession { title: string; - version: number; + version?: number; createdTimeMs: number; updatedTimeMs: number; messages: IMessage[]; diff --git a/public/hooks/use_sessions.ts b/public/hooks/use_sessions.ts index 1f0789bd..8c863683 100644 --- a/public/hooks/use_sessions.ts +++ b/public/hooks/use_sessions.ts @@ -42,9 +42,9 @@ export const usePatchSession = () => { dispatch({ type: 'request', abortController }); return core.services.http .put(`${ASSISTANT_API.SESSION}/${sessionId}`, { - query: { + body: JSON.stringify({ title, - }, + }), signal: abortController.signal, }) .then((payload) => dispatch({ type: 'success', payload })) diff --git a/server/routes/chat_routes.ts b/server/routes/chat_routes.ts index c234a42d..2d557236 100644 --- a/server/routes/chat_routes.ts +++ b/server/routes/chat_routes.ts @@ -99,7 +99,7 @@ const updateSessionRoute = { params: schema.object({ sessionId: schema.string(), }), - query: schema.object({ + body: schema.object({ title: schema.string(), }), }, @@ -225,7 +225,7 @@ export function registerChatRoutes(router: IRouter, routeOptions: RoutesOptions) try { const getResponse = await storageService.updateSession( request.params.sessionId, - request.query.title + request.body.title ); return response.ok({ body: getResponse }); } catch (error) { diff --git a/server/services/chat/olly_chat_service.ts b/server/services/chat/olly_chat_service.ts index 7e3723d1..93e08f9c 100644 --- a/server/services/chat/olly_chat_service.ts +++ b/server/services/chat/olly_chat_service.ts @@ -12,6 +12,7 @@ import { LLMModelFactory } from '../../olly/models/llm_model_factory'; import { PPLTools } from '../../olly/tools/tool_sets/ppl'; import { PPLGenerationRequestSchema } from '../../routes/langchain_routes'; import { ChatService } from './chat_service'; +import { ML_COMMONS_BASE_API } from '../../olly/models/constants'; const MEMORY_ID_FIELD = 'memory_id'; @@ -49,7 +50,7 @@ export class OllyChatService implements ChatService { } const agentFrameworkResponse = (await opensearchClient.transport.request({ method: 'POST', - path: `/_plugins/_ml/agents/${rootAgentId}/_execute`, + path: `${ML_COMMONS_BASE_API}/agents/${rootAgentId}/_execute`, body: { parameters: parametersPayload, }, diff --git a/server/services/storage/agent_framework_storage_service.ts b/server/services/storage/agent_framework_storage_service.ts index 06e7777a..bb01126d 100644 --- a/server/services/storage/agent_framework_storage_service.ts +++ b/server/services/storage/agent_framework_storage_service.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ApiResponse } from '@opensearch-project/opensearch/.'; +import { TransportRequestPromise, ApiResponse } from '@opensearch-project/opensearch/lib/Transport'; import { AgentFrameworkTrace } from '../../../common/utils/llm_chat/traces'; import { OpenSearchClient } from '../../../../../src/core/server'; import { @@ -16,6 +16,7 @@ import { GetSessionsSchema } from '../../routes/chat_routes'; import { StorageService } from './storage_service'; import { MessageParser } from '../../types'; import { MessageParserRunner } from '../../utils/message_parser_runner'; +import { ML_COMMONS_BASE_API } from '../../olly/models/constants'; export interface SessionOptResponse { success: boolean; @@ -29,37 +30,38 @@ export class AgentFrameworkStorageService implements StorageService { private readonly messageParsers: MessageParser[] = [] ) {} async getSession(sessionId: string): Promise { - const session = (await this.client.transport.request({ - method: 'GET', - path: `/_plugins/_ml/memory/conversation/${sessionId}/_list`, - })) as ApiResponse<{ - interactions: Interaction[]; - }>; + const [interactionsResp, conversation] = await Promise.all([ + this.client.transport.request({ + method: 'GET', + path: `${ML_COMMONS_BASE_API}/memory/conversation/${sessionId}/_list`, + }) as TransportRequestPromise< + ApiResponse<{ + interactions: Interaction[]; + }> + >, + this.client.transport.request({ + method: 'GET', + path: `${ML_COMMONS_BASE_API}/memory/conversation/${sessionId}`, + }) as TransportRequestPromise< + ApiResponse<{ + conversation_id: string; + create_time: string; + updated_time: string; + name: string; + }> + >, + ]); const messageParserRunner = new MessageParserRunner(this.messageParsers); - const finalInteractions: Interaction[] = [...session.body.interactions]; + const finalInteractions = interactionsResp.body.interactions; - /** - * Sort interactions according to create_time - */ - finalInteractions.sort((interactionA, interactionB) => { - const { create_time: createTimeA } = interactionA; - const { create_time: createTimeB } = interactionB; - const createTimeMSA = +new Date(createTimeA); - const createTimeMSB = +new Date(createTimeB); - if (isNaN(createTimeMSA) || isNaN(createTimeMSB)) { - return 0; - } - return createTimeMSA - createTimeMSB; - }); let finalMessages: IMessage[] = []; for (const interaction of finalInteractions) { finalMessages = [...finalMessages, ...(await messageParserRunner.run(interaction))]; } return { - title: 'test', - version: 1, - createdTimeMs: Date.now(), - updatedTimeMs: Date.now(), + title: conversation.body.name, + createdTimeMs: +new Date(conversation.body.create_time), + updatedTimeMs: +new Date(conversation.body.updated_time), messages: finalMessages, interactions: finalInteractions, }; @@ -101,7 +103,7 @@ export class AgentFrameworkStorageService implements StorageService { const sessions = await this.client.transport.request({ method: 'GET', - path: `/_plugins/_ml/memory/conversation/_search`, + path: `${ML_COMMONS_BASE_API}/memory/conversation/_search`, body: requestParams, }); @@ -140,7 +142,7 @@ export class AgentFrameworkStorageService implements StorageService { try { const response = await this.client.transport.request({ method: 'DELETE', - path: `/_plugins/_ml/memory/conversation/${sessionId}/_delete`, + path: `${ML_COMMONS_BASE_API}/memory/conversation/${sessionId}/_delete`, }); if (response.statusCode === 200) { return { @@ -162,7 +164,7 @@ export class AgentFrameworkStorageService implements StorageService { try { const response = await this.client.transport.request({ method: 'PUT', - path: `/_plugins/_ml/memory/conversation/${sessionId}/_update`, + path: `${ML_COMMONS_BASE_API}/memory/conversation/${sessionId}/_update`, body: { name: title, }, @@ -187,7 +189,7 @@ export class AgentFrameworkStorageService implements StorageService { try { const response = (await this.client.transport.request({ method: 'GET', - path: `/_plugins/_ml/memory/trace/${interactionId}/_list`, + path: `${ML_COMMONS_BASE_API}/memory/trace/${interactionId}/_list`, })) as ApiResponse<{ traces: Array<{ conversation_id: string;