-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from opensearch-project/feature/switch-chat-api
feat: use agent framework API to generate answer
Showing
9 changed files
with
163 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
server/services/storage/agent_framework_storage_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ApiResponse } from '@opensearch-project/opensearch/.'; | ||
import { OpenSearchClient } from '../../../../../src/core/server'; | ||
import { LLM_INDEX } from '../../../common/constants/llm'; | ||
import { | ||
IInput, | ||
IMessage, | ||
IOutput, | ||
ISession, | ||
ISessionFindResponse, | ||
} from '../../../common/types/chat_saved_object_attributes'; | ||
import { GetSessionsSchema } from '../../routes/chat_routes'; | ||
import { StorageService } from './storage_service'; | ||
|
||
export class AgentFrameworkStorageService implements StorageService { | ||
constructor(private readonly client: OpenSearchClient) {} | ||
async getSession(sessionId: string): Promise<ISession> { | ||
const session = (await this.client.transport.request({ | ||
method: 'GET', | ||
path: `/_plugins/_ml/memory/conversation/${sessionId}`, | ||
})) as ApiResponse<{ | ||
interactions: Array<{ | ||
input: string; | ||
response: string; | ||
parent_interaction_id: string; | ||
interaction_id: string; | ||
}>; | ||
}>; | ||
return { | ||
title: 'test', | ||
version: 1, | ||
createdTimeMs: Date.now(), | ||
updatedTimeMs: Date.now(), | ||
messages: session.body.interactions | ||
.filter((item) => !item.parent_interaction_id) | ||
.reduce((total, current) => { | ||
const inputItem: IInput = { | ||
type: 'input', | ||
contentType: 'text', | ||
content: current.input, | ||
}; | ||
const outputItems: IOutput[] = [ | ||
{ | ||
type: 'output', | ||
contentType: 'markdown', | ||
content: current.response, | ||
traceId: current.interaction_id, | ||
}, | ||
]; | ||
return [...total, inputItem, ...outputItems]; | ||
}, [] as IMessage[]), | ||
}; | ||
} | ||
|
||
async getSessions(query: GetSessionsSchema): Promise<ISessionFindResponse> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
async saveMessages( | ||
title: string, | ||
sessionId: string | undefined, | ||
messages: IMessage[] | ||
): Promise<{ sessionId: string; messages: IMessage[] }> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
deleteSession(sessionId: string): Promise<{}> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
updateSession(sessionId: string, title: string): Promise<{}> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters