-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: retrieve conversation metadata when loading conversation #27
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
|
||
import { ApiResponse } from '@opensearch-project/opensearch/.'; | ||
import { TransportRequestPromise } from '@opensearch-project/opensearch/lib/Transport'; | ||
import { AgentFrameworkTrace } from '../../../common/utils/llm_chat/traces'; | ||
import { OpenSearchClient } from '../../../../../src/core/server'; | ||
import { | ||
|
@@ -29,37 +30,38 @@ export class AgentFrameworkStorageService implements StorageService { | |
private readonly messageParsers: MessageParser[] = [] | ||
) {} | ||
async getSession(sessionId: string): Promise<ISession> { | ||
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([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenSearch Dashboards supports batching concurrent requests when enabling Does the ML Commons plugin support batch requests? Could potentially save some time for total roundtrip so that it just batches these two requests together instead of making two requests and waiting for two responses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks kavilla, I do not think there is a mechanism in current opensearchClient that can batch concurrent requests to backend plugin. ML_common only gives APIs to retrieve the data we need. And it is better that Node.js has no knowledge about the implementation detail of how backend store these data. As for roundtrip, I think that will be OK because we send these two requests in parallel and thus we only need to pay for one roundtrip time. |
||
this.client.transport.request({ | ||
method: 'GET', | ||
path: `/_plugins/_ml/memory/conversation/${sessionId}/_list`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: #22 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done for this. |
||
}) as TransportRequestPromise< | ||
ApiResponse<{ | ||
interactions: Interaction[]; | ||
}> | ||
>, | ||
this.client.transport.request({ | ||
method: 'GET', | ||
path: `/_plugins/_ml/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: Interaction[] = [...interactionsResp.body.interactions]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the spread needed or is this just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, thanks for catching. |
||
|
||
/** | ||
* 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An epoch is easy to convert into string or Date both in Browser and Node.js. For a string type, it is hard tell which format it is using from the type declaration. |
||
updatedTimeMs: +new Date(conversation.body.updated_time), | ||
messages: finalMessages, | ||
interactions: finalInteractions, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i think api response can go in this import statement as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done for that.