Skip to content

Commit 5894ec4

Browse files
committed
add rag search example prompt
1 parent 734433a commit 5894ec4

File tree

4 files changed

+59
-56
lines changed

4 files changed

+59
-56
lines changed

src/prompts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { PromptBase } from '../types.js';
2-
import { latestInstagramPostPrompt } from './latest-instagram-post.js';
2+
import { latestNewsOnTopicPrompt } from './latest-news-on-topic.js';
33

44
/**
55
* List of all enabled prompts.
66
*/
77
export const prompts: PromptBase[] = [
8-
latestInstagramPostPrompt,
8+
latestNewsOnTopicPrompt,
99
];

src/prompts/latest-instagram-post.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { PromptArgument } from '@modelcontextprotocol/sdk/types.js';
2+
3+
import { fixedAjvCompile } from '../tools/utils.js';
4+
import type { PromptBase } from '../types.js';
5+
import { ajv } from '../utils/ajv.js';
6+
7+
/**
8+
* Prompt MCP arguments list.
9+
*/
10+
const args: PromptArgument[] = [
11+
{
12+
name: 'topic',
13+
description: 'The topic to retrieve the latest news on.',
14+
required: true,
15+
},
16+
{
17+
name: 'timespan',
18+
description: 'The timespan for which to retrieve news articles. Defaults to "7 days". For example "1 day", "3 days", "7 days", "1 month", etc.',
19+
required: false,
20+
},
21+
];
22+
23+
/**
24+
* Prompt AJV arguments schema for validation.
25+
*/
26+
const argsSchema = fixedAjvCompile(ajv, {
27+
type: 'object',
28+
properties: {
29+
...Object.fromEntries(args.map((arg) => [arg.name, {
30+
type: 'string',
31+
description: arg.description,
32+
default: arg.default,
33+
examples: arg.examples,
34+
}])),
35+
},
36+
required: [...args.filter((arg) => arg.required).map((arg) => arg.name)],
37+
});
38+
39+
/**
40+
* Actual prompt definition.
41+
*/
42+
export const latestNewsOnTopicPrompt: PromptBase = {
43+
name: 'GetLatestNewsOnTopic',
44+
description: 'This prompt retrieves the latest news articles on a selected topic.',
45+
arguments: args,
46+
ajvValidate: argsSchema,
47+
render: (data) => {
48+
const currentDateUtc = new Date().toISOString().split('T')[0];
49+
const timespan = data.timespan && data.timespan.trim() !== '' ? data.timespan : '7 days';
50+
return `I want you to use the RAG web browser to search the web for the latest news on the "${data.topic}" topic. Retrieve news from the last ${timespan}. The RAG web browser accepts a query parameter that supports all Google input, including filters and flags—be sure to use them to accomplish my goal. Today is ${currentDateUtc} UTC.`;
51+
},
52+
};

tests/integration/suite.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ToolListChangedNotificationSchema } from '@modelcontextprotocol/sdk/typ
44
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
55

66
import { defaults, HelperTools } from '../../src/const.js';
7+
import { latestNewsOnTopicPrompt } from '../../src/prompts/latest-news-on-topic.js';
78
import { addRemoveTools, defaultTools, toolCategories, toolCategoriesEnabledByDefault } from '../../src/tools/index.js';
89
import type { ISearchActorsResult } from '../../src/tools/store_collection.js';
910
import { actorNameToToolName } from '../../src/tools/utils.js';
@@ -459,17 +460,17 @@ export function createIntegrationTestsSuite(
459460
it('should be able to get prompt by name', async () => {
460461
const client = await createClientFn();
461462

462-
const username = 'apify';
463+
const topic = 'apify';
463464
const prompt = await client.getPrompt({
464-
name: 'LatestInstagramPostPrompt',
465+
name: latestNewsOnTopicPrompt.name,
465466
arguments: {
466-
username,
467+
topic,
467468
},
468469
});
469470

470471
const message = prompt.messages[0];
471472
expect(message).toBeDefined();
472-
expect(message.content.text).toContain(username);
473+
expect(message.content.text).toContain(topic);
473474

474475
await client.close();
475476
});

0 commit comments

Comments
 (0)