Skip to content

Commit e8369aa

Browse files
authored
Merge pull request #64 from donvito/feature/web-search
Feature/web search
2 parents fb9e422 + 3e7af10 commit e8369aa

File tree

13 files changed

+1232
-41
lines changed

13 files changed

+1232
-41
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Since APIs are ready to use, you don't need to understand prompt engineering. Ju
2929
| **/api/rewrite** | Rewrite text with instructions (improve, shorten, fix grammar, tone) |
3030
| **/api/compose** | Compose short-form text given a topic |
3131
| **/api/pdf-summarizer** | Extract and summarize content from PDF documents with AI |
32+
| **/api/web-search** | Perform web searches and get AI-powered summaries of results |
3233

3334
### Image Processing
3435

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### Summarization Request
2+
POST http://localhost:3000/api/v1/summarize
3+
Content-Type: application/json
4+
5+
{
6+
"payload": {
7+
"text": "Customer John Doe: Hello, I need help with my recent order. I received the wrong item. Agent Jane Smith: Hi! I'm sorry to hear that. Could you please provide your order number so I can look into this for you? Customer John Doe: Sure, the order number is 123456789. I ordered a wireless mouse, but I received a wired one instead. Agent Jane Smith: Thank you for the information. Let me check your order details. Please hold on a moment. Customer John Doe: Okay, take your time. Agent Jane Smith: Thanks for waiting. I see that the order was for a wired mouse. It appears there was an inventory mistake. I apologize for the inconvenience. Customer John Doe: That's frustrating. Can you send me the correct item? Agent Jane Smith: Absolutely. I will initiate the process to send the wireless mouse to you immediately. You will receive it within 3-5 business days. Would you like a return label for the wired mouse? Customer John Doe: Yes, that would be great. Thank you. Agent Jane Smith: You're welcome! I will email you the return shipping label shortly. Is there anything else I can assist you with today? Customer John Doe: No, that's all. Thanks for your help. Agent Jane Smith: My pleasure! Have a great day!",
8+
"maxLength": 150
9+
},
10+
"config": {
11+
"provider": "lmstudio",
12+
"model": "gemma-3-4b-it",
13+
"temperature": 0,
14+
"stream": false
15+
}
16+
}

idea-http-scripts/WebSearch.http

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### Web Search Request
2+
POST http://localhost:3000/api/v1/web-search
3+
Content-Type: application/json
4+
5+
{
6+
"payload": {
7+
"query": "Latest AI trends 2025",
8+
"limit": 5,
9+
"sources": ["web"]
10+
},
11+
"config": {
12+
"provider": "lmstudio",
13+
"model": "gemma-3-4b-it",
14+
"stream": false
15+
}
16+
}
17+
18+
19+
20+
### Expected Response Structure:
21+
# The response will contain:
22+
# - searchResult: Natural language summary of search results with links included
23+
# - provider: AI provider used
24+
# - model: Model used
25+
# - usage: Token usage information
26+
# - apiVersion: API version
27+
28+
###
29+
30+
POST http://localhost:3000/api/v1/web-search
31+
Content-Type: application/json
32+
33+
{
34+
"payload": {
35+
"query": "Latest AI trends 2025",
36+
"limit": 5,
37+
"sources": ["web"]
38+
},
39+
"config": {
40+
"provider": "openai",
41+
"model": "gpt-4.1-nano",
42+
"stream": false
43+
}
44+
}
45+

src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function configureApiSecurity(app: OpenAPIHono, tokenConfig: string) {
5757
path === '/api/v1/outline-demo' ||
5858
path === '/api/v1/pdf-summarizer-demo' ||
5959
path === '/api/v1/pdf-translate-demo' ||
60+
path === '/api/v1/web-search-demo' ||
6061
path === '/api/models' ||
6162
path === '/api/jsoneditor' ||
6263
// Public read-only service catalog for demos

src/config/models.json

Lines changed: 40 additions & 39 deletions
Large diffs are not rendered by default.

src/config/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path'
33

44
export type ModelCapability =
55
| 'summarize'
6+
| 'web-search'
67
| 'pdf-summarizer'
78
| 'pdf-translate'
89
| 'rewrite'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { OpenAPIHono, createRoute } from '@hono/zod-openapi'
2+
import { readFileSync } from 'fs'
3+
import { join } from 'path'
4+
5+
const router = new OpenAPIHono()
6+
7+
const demoRoute = createRoute({
8+
method: 'get',
9+
path: '/',
10+
responses: {
11+
200: {
12+
description: 'Returns the WebSearch demo page.',
13+
content: {
14+
'text/html': {
15+
schema: { type: 'string' }
16+
}
17+
}
18+
}
19+
},
20+
tags: ['Demos']
21+
})
22+
23+
function getWebSearchDemoHtml() {
24+
const templatePath = join(process.cwd(), 'src', 'templates', 'webSearchDemo.html')
25+
return readFileSync(templatePath, 'utf-8')
26+
}
27+
28+
router.openapi(demoRoute, (c) => c.html(getWebSearchDemoHtml()))
29+
30+
export default {
31+
handler: router,
32+
mountPath: 'web-search-demo'
33+
}

src/routes/v1/services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const modelsSchema = z.object({
7070
available: z.boolean()
7171
})
7272

73-
const capabilityEnum = z.enum(['summarize', 'pdf-summarizer', 'pdf-translate', 'rewrite', 'compose', 'keywords', 'sentiment', 'emailReply', 'vision', 'askText', 'translate', 'meetingNotes', 'planning', 'outline'])
73+
const capabilityEnum = z.enum(['summarize', 'web-search', 'pdf-summarizer', 'pdf-translate', 'rewrite', 'compose', 'keywords', 'sentiment', 'emailReply', 'vision', 'askText', 'translate', 'meetingNotes', 'planning', 'outline'])
7474
const byProviderSchema = z.record(z.array(z.string()))
7575
const providerViewSchema = z.record(z.array(z.object({
7676
name: z.string(),
@@ -81,6 +81,7 @@ const providerViewSchema = z.record(z.array(z.object({
8181
source: z.literal('config'),
8282
byCapability: z.object({
8383
summarize: byProviderSchema,
84+
'web-search': byProviderSchema,
8485
'pdf-summarizer': byProviderSchema,
8586
'pdf-translate': byProviderSchema,
8687
rewrite: byProviderSchema,
@@ -115,6 +116,7 @@ async function handleGetModels(c: Context) {
115116
if (source === 'config') {
116117
const byCapability = {
117118
summarize: getModelsByCapability('summarize'),
119+
'web-search': getModelsByCapability('web-search'),
118120
'pdf-summarizer': getModelsByCapability('pdf-summarizer'),
119121
'pdf-translate': getModelsByCapability('pdf-translate'),
120122
rewrite: getModelsByCapability('rewrite'),

0 commit comments

Comments
 (0)