-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from dcSpark/feature/add-wikimedia-search-tit…
…les-tool feat: add wikimedia-search-titles tool
- Loading branch information
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,47 @@ | ||
import { expect } from '@jest/globals'; | ||
import { getToolTestClient } from '../../src/test/utils'; | ||
import * as path from 'path'; | ||
|
||
describe('Wikimedia Title Search Tool', () => { | ||
const toolPath = path.join(__dirname, 'tool.ts'); | ||
const client = getToolTestClient(); | ||
|
||
it('searches titles with default parameters', async () => { | ||
const response = await client.executeToolFromFile(toolPath, { | ||
query: 'artificial intelligence' | ||
}); | ||
console.log("Response: ", response); | ||
|
||
expect(response).toHaveProperty('titles'); | ||
expect(Array.isArray(response.titles)).toBe(true); | ||
expect(response.titles.length).toBeGreaterThan(0); | ||
expect(response.titles.length).toBeLessThanOrEqual(10); | ||
|
||
const firstResult = response.titles[0]; | ||
expect(firstResult).toHaveProperty('title'); | ||
expect(firstResult).toHaveProperty('description'); | ||
expect(firstResult).toHaveProperty('url'); | ||
expect(firstResult.url).toMatch(/^https:\/\/en\.wikipedia\.org\/wiki\//); | ||
}, 30000); | ||
|
||
it('respects limit parameter', async () => { | ||
const limit = 5; | ||
const response = await client.executeToolFromFile(toolPath, { | ||
query: 'artificial intelligence', | ||
limit | ||
}); | ||
|
||
expect(response.titles.length).toBeLessThanOrEqual(limit); | ||
}, 30000); | ||
|
||
it('handles custom project and language', async () => { | ||
const response = await client.executeToolFromFile(toolPath, { | ||
query: 'intelligence artificielle' | ||
}, { | ||
project: 'wikipedia', | ||
language: 'fr' | ||
}); | ||
|
||
expect(response.titles[0].url).toMatch(/^https:\/\/fr\.wikipedia\.org\/wiki\//); | ||
}, 30000); | ||
}); |
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,66 @@ | ||
{ | ||
"id": "wikimedia-search-titles", | ||
"version": "1.0.0", | ||
"name": "Wikimedia Title Search", | ||
"description": "Search Wikimedia pages by title with full-text search capabilities", | ||
"author": "Shinkai", | ||
"keywords": [ | ||
"wikimedia", | ||
"search", | ||
"wikipedia", | ||
"titles", | ||
"pages", | ||
"full-text" | ||
], | ||
"configurations": { | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "Wikimedia project (e.g., wikipedia)", | ||
"default": "wikipedia" | ||
}, | ||
"language": { | ||
"type": "string", | ||
"description": "Language code (e.g., en)", | ||
"default": "en" | ||
} | ||
}, | ||
"required": [] | ||
}, | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"query": { | ||
"type": "string", | ||
"description": "Search query for titles" | ||
}, | ||
"limit": { | ||
"type": "integer", | ||
"description": "Maximum number of results (1-50)", | ||
"minimum": 1, | ||
"maximum": 50, | ||
"default": 10 | ||
} | ||
}, | ||
"required": ["query"] | ||
}, | ||
"result": { | ||
"type": "object", | ||
"properties": { | ||
"titles": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"title": {"type": "string"}, | ||
"description": {"type": "string"}, | ||
"url": {"type": "string"} | ||
}, | ||
"required": ["title", "description", "url"] | ||
} | ||
} | ||
}, | ||
"required": ["titles"] | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"categoryId": "cc6ba888-3987-4e2a-af7e-3b137d997262" | ||
} |
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,50 @@ | ||
import axios from 'npm:axios'; | ||
|
||
type Configurations = { | ||
project?: string; | ||
language?: string; | ||
}; | ||
|
||
type Parameters = { | ||
query: string; | ||
limit?: number; | ||
}; | ||
|
||
type Result = { | ||
titles: Array<{ | ||
title: string; | ||
description: string; | ||
url: string; | ||
}>; | ||
}; | ||
|
||
export type Run<C extends Record<string, any>, I extends Record<string, any>, R extends Record<string, any>> = ( | ||
config: C, | ||
inputs: I | ||
) => Promise<R>; | ||
|
||
export const run: Run<Configurations, Parameters, Result> = async ( | ||
configurations: Configurations, | ||
params: Parameters | ||
): Promise<Result> => { | ||
const project = configurations?.project || 'wikipedia'; | ||
const language = configurations?.language || 'en'; | ||
const limit = params.limit || 10; | ||
|
||
const api_url = `https://api.wikimedia.org/core/v1/${project}/${language}/search/title`; | ||
|
||
const response = await axios.get(api_url, { | ||
params: { | ||
q: params.query, | ||
limit: Math.min(Math.max(1, limit), 50) | ||
} | ||
}); | ||
|
||
return { | ||
titles: response.data.pages.map((page: any) => ({ | ||
title: page.title, | ||
description: page.description || '', | ||
url: `https://${language}.${project}.org/wiki/${encodeURIComponent(page.title.replace(/ /g, '_'))}` | ||
})) | ||
}; | ||
}; |