Skip to content

Commit

Permalink
e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Aug 13, 2024
1 parent 6cbbfc8 commit 8a4364a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ConversationTurnEventToolsProvider } from './event-tools-provider';
*/
export class BedrockConverseAdapter {
private readonly allTools: Array<ToolDefinition>;
private readonly allExecutableTools: Array<ExecutableTool>;
private readonly executableTools: Array<ExecutableTool>;
private readonly clientTools: Array<ToolDefinition>;
private readonly executableToolByName: Map<string, ExecutableTool> =
new Map();
Expand All @@ -38,14 +38,14 @@ export class BedrockConverseAdapter {
),
eventToolsProvider = new ConversationTurnEventToolsProvider(event)
) {
this.allExecutableTools = [
this.executableTools = [
...eventToolsProvider.getEventTools(),
...additionalTools,
];
this.clientTools = this.event.toolsConfiguration?.clientTools ?? [];
this.allTools = [...this.allExecutableTools, ...this.clientTools];
this.allTools = [...this.executableTools, ...this.clientTools];
const duplicateTools = new Set<string>();
this.allExecutableTools.forEach((t) => {
this.executableTools.forEach((t) => {
if (this.executableToolByName.has(t.name)) {
duplicateTools.add(t.name);
}
Expand Down Expand Up @@ -122,7 +122,7 @@ export class BedrockConverseAdapter {
};

private createToolConfiguration = (): ToolConfiguration | undefined => {
if (this.allExecutableTools.length === 0) {
if (this.allTools.length === 0) {
return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ class ConversationHandlerTestProject extends TestProjectBase {
clientConfig.data.url,
apolloClient
);

await this.assertDefaultConversationHandlerCanExecuteTurnWithClientTool(
backendId,
authenticatedUserCredentials.accessToken,
clientConfig.data.url,
apolloClient
);
}

private assertDefaultConversationHandlerCanExecuteTurn = async (
Expand Down Expand Up @@ -320,6 +327,71 @@ class ConversationHandlerTestProject extends TestProjectBase {
);
};

private assertDefaultConversationHandlerCanExecuteTurnWithClientTool = async (
backendId: BackendIdentifier,
accessToken: string,
graphqlApiEndpoint: string,
apolloClient: ApolloClient<NormalizedCacheObject>
): Promise<void> => {
const defaultConversationHandlerFunction = (
await this.resourceFinder.findByBackendIdentifier(
backendId,
'AWS::Lambda::Function',
(name) => name.includes('default')
)
)[0];

// send event
const event: ConversationTurnEvent = {
conversationId: randomUUID().toString(),
currentMessageId: randomUUID().toString(),
graphqlApiEndpoint: graphqlApiEndpoint,
messages: [
{
role: 'user',
content: [
{
text: 'What is the temperature in Seattle?',
},
],
},
],
request: {
headers: { authorization: accessToken },
},
toolsConfiguration: {
clientTools: [
{
name: 'thermometer',
description: 'Provides the current temperature for a given city.',
inputSchema: {
json: {
type: 'object',
properties: {
city: {
type: 'string',
description: 'string',
},
},
required: [],
},
},
},
],
},
...commonEventProperties,
};
const response = await this.executeConversationTurn(
event,
defaultConversationHandlerFunction,
apolloClient
);
// Assert that tool was used. I.e. that LLM used value returned by the tool.
assert.match(response.content, /Seattle/);
assert.match(response.content, /toolUse/);
assert.match(response.content, /toolUseId/);
};

private assertCustomConversationHandlerCanExecuteTurn = async (
backendId: BackendIdentifier,
accessToken: string,
Expand Down

0 comments on commit 8a4364a

Please sign in to comment.