Skip to content

Commit 406a565

Browse files
committed
/api/videos will generate summaries using all APIs
1 parent 0826d72 commit 406a565

File tree

4 files changed

+23
-74
lines changed

4 files changed

+23
-74
lines changed

services/video-search/src/config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dotenv/config';
22

3-
const {
3+
let {
44
npm_package_name,
55
npm_package_version,
66
PORT,
@@ -34,6 +34,10 @@ const {
3434
USE,
3535
} = process.env;
3636

37+
if (typeof USE === 'string') {
38+
USE = USE.toLowerCase();
39+
}
40+
3741
const DEFAULT_VIDEO_INDEX_NAME = 'idx-videos';
3842
const DEFAULT_VIDEO_PREFIX = 'video:';
3943
const DEFAULT_VECTOR_SET = 'video-vectors';
@@ -101,8 +105,9 @@ export default {
101105
OPENAI_SUMMARY_PREFIX ?? `openai-${DEFAULT_SUMMARY_PREFIX}`,
102106
},
103107
use: {
104-
GOOGLE: USE === 'GOOGLE',
105-
HF: USE === 'HF',
106-
OPENAI: USE === 'OPENAI',
108+
DEFAULT: USE ?? 'openai',
109+
GOOGLE: USE === 'google',
110+
HF: USE === 'hf',
111+
OPENAI: USE === 'openai',
107112
},
108113
};

services/video-search/src/router.ts

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,13 @@ function getApi(api?: 'google' | 'hf' | 'openai') {
1010
if (typeof api === 'string') {
1111
api = api.toLowerCase() as 'google' | 'hf' | 'openai';
1212
}
13+
const defaultAPI = config.use.DEFAULT;
1314

14-
const useGoogle = api === 'google' || (!api && config.use.GOOGLE);
15-
const useHf = api === 'hf' || (!api && config.use.HF);
16-
const useOpenai = api === 'openai' || (!api && config.use.OPENAI);
17-
18-
if (useGoogle) {
19-
return {
20-
summarize: google.summarize,
21-
store: google.store,
22-
search: google.search,
23-
};
24-
} else if (useHf) {
25-
return {
26-
summarize: hf.summarize,
27-
store: hf.store,
28-
search: hf.search,
29-
};
30-
} else {
31-
return {
32-
summarize: openai.summarize,
33-
store: openai.store,
34-
search: openai.search,
35-
};
36-
}
15+
return {
16+
google,
17+
hf,
18+
openai,
19+
}[api ?? defaultAPI] as typeof openai;
3720
}
3821

3922
const defaultApi = getApi();
@@ -77,24 +60,23 @@ async function search({
7760

7861
router.post('/videos', async (req, res) => {
7962
const { videos } = req.body as { videos: string[] };
80-
const useApi = req.headers['x-use-api'] as
81-
| 'google'
82-
| 'hf'
83-
| 'openai'
84-
| undefined;
85-
const api = getApi(useApi);
63+
const apis: ['google', 'hf', 'openai'] = ['google', 'hf', 'openai'];
8664

8765
try {
88-
await loadVideos({ api, videos });
66+
await Promise.all(
67+
apis.map((api) => {
68+
return loadVideos({ api: getApi(api), videos });
69+
}),
70+
);
8971

9072
res.status(200).json({ message: 'Videos loaded' });
9173
} catch (e) {
92-
log.error('Unexpected error in /videos/load', {
74+
log.error('Unexpected error in /videos', {
9375
error: {
9476
message: (e as Error).message,
9577
stack: (e as Error).stack,
9678
},
97-
location: 'router.videos.google.load',
79+
location: 'router.videos',
9880
});
9981

10082
res.status(500).json({ error: (e as Error).message });

services/video-search/src/script.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

services/video-search/src/templates/videos.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ The transcript of the video will also be used as the basis for a question and an
1212
Provide some examples questions and answers that could be asked about the video. Make these questions very specific.
1313
1414
Total output will be a summary of the video and a list of example questions the user could ask of the video.
15-
Total output must have a maximum length of 8192 tokens.
1615
1716
SUMMARY AND QUESTIONS:
1817
`;
@@ -35,7 +34,6 @@ Provide some examples questions and answers that could be asked about the video.
3534
these questions very specific.
3635
If the context isn't useful, return the original summary and questions.
3736
Total output will be a summary of the video and a list of example questions the user could ask of the video.
38-
Total output must have a maximum length of 8192 tokens.
3937
4038
SUMMARY AND QUESTIONS:
4139
`;

0 commit comments

Comments
 (0)