Skip to content

Commit

Permalink
feat: optimize
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Nov 22, 2023
1 parent 8331a95 commit d598bff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/tabs/chat/chat_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import { EuiFlyoutBody, EuiFlyoutFooter, EuiPage, EuiPageBody, EuiSpacer } from '@elastic/eui';
import React, { useCallback, useState } from 'react';
import cs from 'classnames';
import { useObservable } from 'react-use';
import { useChatContext } from '../../contexts/chat_context';
import { useChatState } from '../../hooks/use_chat_state';
import { ChatPageContent } from './chat_page_content';
import { ChatInputControls } from './controls/chat_input_controls';
import { useObservable } from 'react-use';
import { useCore } from '../../contexts/core_context';

interface ChatPageProps {
Expand Down
4 changes: 1 addition & 3 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export class AssistantPlugin implements Plugin<AssistantPluginSetup, AssistantPl
});

// Register server side APIs
setupRoutes(router, {
messageParsers: this.messageParsers,
});
setupRoutes(router);

core.savedObjects.registerType(chatSavedObject);
core.savedObjects.registerType(chatConfigSavedObject);
Expand Down
11 changes: 7 additions & 4 deletions server/routes/chat_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const updateSessionRoute = {
},
};

export function registerChatRoutes(router: IRouter, routeOptions: RoutesOptions) {
export function registerChatRoutes(router: IRouter) {
const createStorageService = (context: RequestHandlerContext) =>
new AgentFrameworkStorageService(context.core.opensearch.client.asCurrentUser);
const createChatService = () => new OllyChatService();
Expand Down Expand Up @@ -134,7 +134,7 @@ export function registerChatRoutes(router: IRouter, routeOptions: RoutesOptions)
body: {
messages: finalMessage.messages,
sessionId: outputs.memoryId,
title: finalMessage.title
title: finalMessage.title,
},
});
} catch (error) {
Expand Down Expand Up @@ -272,13 +272,16 @@ export function registerChatRoutes(router: IRouter, routeOptions: RoutesOptions)
const outputs = await chatService.requestLLM(
{ messages, input, sessionId },
context,
request as any
// @ts-ignore
request
);
const title = input.content.substring(0, 50);
const saveMessagesResponse = await storageService.saveMessages(
title,
sessionId,
[...messages, input, ...outputs.messages].filter((message) => message.content !== 'AbortError')
[...messages, input, ...outputs.messages].filter(
(message) => message.content !== 'AbortError'
)
);
return response.ok({
body: { ...saveMessagesResponse, title },
Expand Down
4 changes: 2 additions & 2 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IRouter } from '../../../../src/core/server';
import { registerChatRoutes } from './chat_routes';
import { registerLangchainRoutes } from './langchain_routes';

export function setupRoutes(router: IRouter, options: RoutesOptions) {
registerChatRoutes(router, options);
export function setupRoutes(router: IRouter) {
registerChatRoutes(router);
registerLangchainRoutes(router);
}
8 changes: 4 additions & 4 deletions server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface AssistantPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AssistantPluginStart {}

export interface IMessageParserHelper {
addMessage: (message: IMessage) => boolean;
}

export interface Interaction {
input: string;
response: string;
conversation_id: string;
interaction_id: string;
create_time: string;
additional_info: Record<string, unknown>;
}

export interface MessageParser {
Expand Down

0 comments on commit d598bff

Please sign in to comment.