Skip to content

Commit a88f906

Browse files
committed
AI test fixes
1 parent 0182bd5 commit a88f906

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

packages/ai-bot/tests/prompt-construction-test.ts

+35-29
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
Tool,
2525
CardMessageContent,
2626
} from 'https://cardstack.com/base/matrix-event';
27-
import { EventStatus, IRoomEvent } from 'matrix-js-sdk';
27+
import { EventStatus } from 'matrix-js-sdk';
2828
import { CardDef } from 'https://cardstack.com/base/card-api';
2929
import { readFileSync } from 'fs-extra';
3030
import * as path from 'path';
@@ -961,7 +961,7 @@ example.pdf: Unsupported file type: application/pdf. For now, only text files ar
961961
},
962962
];
963963

964-
const functions = getTools(history, '@aibot:localhost');
964+
const functions = getTools(history, [], '@aibot:localhost');
965965
assert.equal(functions.length, 1);
966966
assert.deepEqual(functions[0], {
967967
type: 'function',
@@ -1031,7 +1031,7 @@ example.pdf: Unsupported file type: application/pdf. For now, only text files ar
10311031
},
10321032
];
10331033

1034-
const functions = getTools(history, '@aibot:localhost');
1034+
const functions = getTools(history, [], '@aibot:localhost');
10351035
assert.equal(functions.length, 1);
10361036
assert.deepEqual(functions[0], {
10371037
type: 'function',
@@ -1143,7 +1143,7 @@ example.pdf: Unsupported file type: application/pdf. For now, only text files ar
11431143
},
11441144
];
11451145

1146-
const functions = getTools(history, '@aibot:localhost');
1146+
const functions = getTools(history, [], '@aibot:localhost');
11471147
assert.equal(functions.length, 1);
11481148
if (functions.length > 0) {
11491149
assert.deepEqual(functions[0], {
@@ -1335,13 +1335,15 @@ test('if tool calls are required, ensure they are set', async () => {
13351335
});
13361336

13371337
test('Create search function calls', () => {
1338-
const history: IRoomEvent[] = [
1338+
const history: DiscreteMatrixEvent[] = [
13391339
{
13401340
type: 'm.room.message',
1341+
room_id: 'room-id-1',
13411342
sender: '@ian:localhost',
13421343
content: {
13431344
msgtype: APP_BOXEL_MESSAGE_MSGTYPE,
13441345
body: 'set the name to dave',
1346+
format: 'org.matrix.custom.html',
13451347
formatted_body: '<p>set the name to dave</p>\n',
13461348
data: {
13471349
context: {
@@ -1354,19 +1356,20 @@ test('Create search function calls', () => {
13541356
origin_server_ts: 1696813813166,
13551357
unsigned: {
13561358
age: 115498,
1359+
transaction_id: 'm1722242836705.8',
13571360
},
13581361
event_id: '$AZ65GbUls1UdpiOPD_AfSVu8RyiFYN1vltmUKmUnV4c',
1359-
age: 115498,
1362+
status: EventStatus.SENT,
13601363
},
13611364
];
13621365

1363-
const functions = getTools(history, '@aibot:localhost');
1366+
const functions = getTools(history, [], '@aibot:localhost');
13641367
assert.equal(functions.length, 1);
13651368
assert.deepEqual(functions[0], getSearchTool());
13661369
});
13671370

13681371
test('Return host result of tool call back to open ai', async () => {
1369-
const history: IRoomEvent[] = [
1372+
const history: DiscreteMatrixEvent[] = [
13701373
{
13711374
type: 'm.room.message',
13721375
room_id: 'room-id-1',
@@ -1479,9 +1482,10 @@ test('Return host result of tool call back to open ai', async () => {
14791482
origin_server_ts: 1722242833562,
14801483
unsigned: {
14811484
age: 20470,
1485+
transaction_id: 'm1722242836705.1',
14821486
},
14831487
event_id: '$p_NQ4tvokzQrIkT24Wj08mdAxBBvmdLOz6ph7UQfMDw',
1484-
age: 20470,
1488+
status: EventStatus.SENT,
14851489
},
14861490
{
14871491
type: 'm.room.message',
@@ -1493,13 +1497,6 @@ test('Return host result of tool call back to open ai', async () => {
14931497
formatted_body:
14941498
'It looks like you want to search for card instances based on the "Author" card you provided. Just for clarity, would you like to search for more cards based on the "Author" module type or something else specific?\n\nFor example, do you want to find all card instances of type "Author" or a different type of card/module?',
14951499
format: 'org.matrix.custom.html',
1496-
'm.new_content': {
1497-
body: 'It looks like you want to search for card instances based on the "Author" card you provided. Just for clarity, would you like to search for more cards based on the "Author" module type or something else specific?\n\nFor example, do you want to find all card instances of type "Author" or a different type of card/module?',
1498-
msgtype: 'm.text',
1499-
formatted_body:
1500-
'It looks like you want to search for card instances based on the "Author" card you provided. Just for clarity, would you like to search for more cards based on the "Author" module type or something else specific?\n\nFor example, do you want to find all card instances of type "Author" or a different type of card/module?',
1501-
format: 'org.matrix.custom.html',
1502-
},
15031500
isStreamingFinished: true,
15041501
'm.relates_to': {
15051502
rel_type: 'm.replace',
@@ -1509,10 +1506,10 @@ test('Return host result of tool call back to open ai', async () => {
15091506
origin_server_ts: 1722242836727,
15101507
unsigned: {
15111508
age: 17305,
1512-
transaction_id: 'm1722242836705.8',
1509+
transaction_id: 'm1722242836705.2',
15131510
},
15141511
event_id: 'message-event-id-1',
1515-
age: 17305,
1512+
status: EventStatus.SENT,
15161513
},
15171514
{
15181515
type: 'm.room.message',
@@ -1626,9 +1623,10 @@ test('Return host result of tool call back to open ai', async () => {
16261623
origin_server_ts: 1722242847418,
16271624
unsigned: {
16281625
age: 6614,
1626+
transaction_id: 'm1722242836705.3',
16291627
},
16301628
event_id: '$FO2XfB0xFiTpm5FmOUiWQqFh_DPQSr4zix41Vj3eqNc',
1631-
age: 6614,
1629+
status: EventStatus.SENT,
16321630
},
16331631
{
16341632
type: 'm.room.message',
@@ -1667,7 +1665,7 @@ test('Return host result of tool call back to open ai', async () => {
16671665
transaction_id: 'm1722242849075.10',
16681666
},
16691667
event_id: 'command-event-id-1',
1670-
age: 4938,
1668+
status: EventStatus.SENT,
16711669
},
16721670
{
16731671
type: APP_BOXEL_COMMAND_RESULT_EVENT_TYPE,
@@ -1681,7 +1679,8 @@ test('Return host result of tool call back to open ai', async () => {
16811679
},
16821680
msgtype: APP_BOXEL_COMMAND_RESULT_WITH_OUTPUT_MSGTYPE,
16831681
data: {
1684-
card: JSON.stringify({
1682+
cardEventId: 'command-result-id-1',
1683+
card: {
16851684
data: {
16861685
type: 'card',
16871686
attributes: {
@@ -1707,23 +1706,30 @@ test('Return host result of tool call back to open ai', async () => {
17071706
},
17081707
],
17091708
},
1709+
meta: {
1710+
adoptsFrom: {
1711+
module: 'https://cardstack.com/base/search-results',
1712+
name: 'SearchResults',
1713+
},
1714+
},
17101715
},
1711-
}),
1716+
},
17121717
},
17131718
},
17141719
origin_server_ts: 1722242853988,
17151720
unsigned: {
17161721
age: 44,
1722+
transaction_id: 'm1722242836705.4',
17171723
},
17181724
event_id: 'command-result-id-1',
1719-
age: 44,
1725+
status: EventStatus.SENT,
17201726
},
17211727
];
1722-
const tools = getTools(history, '@ai-bot:localhost');
1728+
const tools = getTools(history, [], '@ai-bot:localhost');
17231729
const result = await getModifyPrompt(history, '@ai-bot:localhost', tools);
17241730
assert.equal(result[5].role, 'tool');
17251731
assert.equal(result[5].tool_call_id, 'tool-call-id-1');
1726-
const expected = `Command applied, with result card: "{\\"data\\":{\\"type\\":\\"card\\",\\"attributes\\":{\\"title\\":\\"Search Results\\",\\"description\\":\\"Here are the search results\\",\\"results\\":[{\\"data\\":{\\"type\\":\\"card\\",\\"id\\":\\"http://localhost:4201/drafts/Author/1\\",\\"attributes\\":{\\"firstName\\":\\"Alice\\",\\"lastName\\":\\"Enwunder\\",\\"photo\\":null,\\"body\\":\\"Alice is a software engineer at Google.\\",\\"description\\":null,\\"thumbnailURL\\":null},\\"meta\\":{\\"adoptsFrom\\":{\\"module\\":\\"../author\\",\\"name\\":\\"Author\\"}}}}]}}}".`;
1732+
const expected = `Command applied, with result card: {"data":{"type":"card","attributes":{"title":"Search Results","description":"Here are the search results","results":[{"data":{"type":"card","id":"http://localhost:4201/drafts/Author/1","attributes":{"firstName":"Alice","lastName":"Enwunder","photo":null,"body":"Alice is a software engineer at Google.","description":null,"thumbnailURL":null},"meta":{"adoptsFrom":{"module":"../author","name":"Author"}}}}]},"meta":{"adoptsFrom":{"module":"https://cardstack.com/base/search-results","name":"SearchResults"}}}}.`;
17271733

17281734
assert.equal(result[5].content!.trim(), expected.trim());
17291735
});
@@ -1806,14 +1812,14 @@ test('Tools calls are connected to their results', async () => {
18061812
);
18071813
});
18081814

1809-
test('Tools on enabled skills are available in prompt', () => {
1815+
test('Tools on enabled skills are available in prompt', async () => {
18101816
const eventList: DiscreteMatrixEvent[] = JSON.parse(
18111817
readFileSync(
18121818
path.join(__dirname, 'resources/chats/enabled-skill-with-commands.json'),
18131819
),
18141820
);
18151821

1816-
const { tools } = getPromptParts(eventList, '@aibot:localhost');
1822+
const { tools } = await getPromptParts(eventList, '@aibot:localhost');
18171823
assert.true(tools.length > 0, 'Should have tools available');
18181824

18191825
// Verify that the tools array contains the command from the skill
@@ -1826,14 +1832,14 @@ test('Tools on enabled skills are available in prompt', () => {
18261832
);
18271833
});
18281834

1829-
test('No tools are available if skill is not enabled', () => {
1835+
test('No tools are available if skill is not enabled', async () => {
18301836
const eventList: DiscreteMatrixEvent[] = JSON.parse(
18311837
readFileSync(
18321838
path.join(__dirname, 'resources/chats/disabled-skill-with-commands.json'),
18331839
),
18341840
);
18351841

1836-
const { tools } = getPromptParts(eventList, '@aibot:localhost');
1842+
const { tools } = await getPromptParts(eventList, '@aibot:localhost');
18371843
// we should not have any tools available
18381844
assert.true(tools.length == 0, 'Should not have tools available');
18391845
});

0 commit comments

Comments
 (0)