-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'main' into assistant-capabilities
Signed-off-by: Songkan Tang <[email protected]>
- Loading branch information
Showing
14 changed files
with
276 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { API_BASE } from '../../common/constants/llm'; | ||
import { HttpSetup } from '../../../../src/core/public'; | ||
|
||
interface Options { | ||
dataSourceId?: string; | ||
} | ||
|
||
export class AssistantClient { | ||
constructor(private http: HttpSetup) {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
executeAgent = (agentId: string, parameters: Record<string, any>, options?: Options) => { | ||
return this.http.fetch({ | ||
method: 'POST', | ||
path: `${API_BASE}/agent/_execute`, | ||
body: JSON.stringify(parameters), | ||
query: { dataSourceId: options?.dataSourceId, agentId }, | ||
}); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
executeAgentByName = (agentName: string, parameters: Record<string, any>, options?: Options) => { | ||
return this.http.fetch({ | ||
method: 'POST', | ||
path: `${API_BASE}/agent/_execute`, | ||
body: JSON.stringify(parameters), | ||
query: { dataSourceId: options?.dataSourceId, agentName }, | ||
}); | ||
}; | ||
} |
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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { HttpSetup } from '../../../../src/core/public'; | ||
import { AssistantClient } from './assistant_client'; | ||
|
||
export interface AssistantServiceStart { | ||
client: AssistantClient; | ||
} | ||
|
||
export class AssistantService { | ||
constructor() {} | ||
|
||
setup() {} | ||
|
||
start(http: HttpSetup): AssistantServiceStart { | ||
const assistantClient = new AssistantClient(http); | ||
return { | ||
client: assistantClient, | ||
}; | ||
} | ||
|
||
stop() {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { schema } from '@osd/config-schema'; | ||
import { IRouter } from '../../../../src/core/server'; | ||
import { AGENT_API } from '../../common/constants/llm'; | ||
import { AssistantServiceSetup } from '../services/assistant_service'; | ||
|
||
export function registerAgentRoutes(router: IRouter, assistantService: AssistantServiceSetup) { | ||
router.post( | ||
{ | ||
path: AGENT_API.EXECUTE, | ||
validate: { | ||
body: schema.any(), | ||
query: schema.oneOf([ | ||
schema.object({ | ||
dataSourceId: schema.maybe(schema.string()), | ||
agentId: schema.string(), | ||
}), | ||
schema.object({ | ||
dataSourceId: schema.maybe(schema.string()), | ||
agentName: schema.string(), | ||
}), | ||
]), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
try { | ||
const assistantClient = assistantService.getScopedClient(req, context); | ||
if ('agentId' in req.query) { | ||
const response = await assistantClient.executeAgent(req.query.agentId, req.body); | ||
return res.ok({ body: response }); | ||
} | ||
const response = await assistantClient.executeAgentByName(req.query.agentName, req.body); | ||
return res.ok({ body: response }); | ||
} catch (e) { | ||
return res.internalError(); | ||
} | ||
}) | ||
); | ||
} |
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
Oops, something went wrong.