Skip to content

Commit c92268a

Browse files
committed
fix: batch embedding requests
1 parent 2a0f885 commit c92268a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

server/api/clusters/[...repo].ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const linkedRepos: Record<string, string[]> = {
77
'nuxt/nuxt': ['vuejs/core', 'vitejs/vite', 'nitrojs/nitro'],
88
}
99

10+
const allowedRepos = ['nuxt/nuxt', 'vuejs/vue', 'vitejs/vite', 'nitrojs/nitro', 'danielroe/beasties']
11+
1012
export default defineCachedEventHandler(async (event) => {
1113
const [owner, repo] = getRouterParam(event, 'repo')?.split('/') || []
1214
if (!owner || !repo) {
@@ -17,11 +19,27 @@ export default defineCachedEventHandler(async (event) => {
1719
}
1820

1921
const source = `${owner}/${repo}`
22+
23+
if (!allowedRepos.includes(source)) {
24+
throw createError({
25+
status: 400,
26+
message: 'Repository not allowed',
27+
})
28+
}
29+
2030
const repos = [source, ...linkedRepos[source] || []]
2131
const issues = await Promise.all(repos.map(async repo => event.$fetch<Issue[]>(`/api/issues/${repo}`)))
2232
.then(r => r.flat())
2333

24-
const embeddings = await Promise.all(issues.map(async issue => getEmbeddingsForIssue(event, issue)))
34+
console.log('fetched', issues.length, 'issues')
35+
36+
const embeddings: number[][] = []
37+
38+
do {
39+
const batch = issues.splice(0, 100)
40+
embeddings.push(...await Promise.all(batch.map(async issue => getEmbeddingsForIssue(event, issue))))
41+
} while (issues.length)
42+
2543
const clusters = clusterEmbeddings(issues, embeddings)
2644
return clusters.filter((cluster) => {
2745
return cluster.some(issue => issue.repository?.owner?.name === owner && issue.repository?.name === repo)

server/api/issues/[...repo].ts

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { getLabels, type Issue } from '../../utils/github'
55
const labelsToExclude = ['documentation', 'invalid', 'enhancement']
66
const knownBots = new Set(['renovate', 'renovate[bot]'])
77

8+
const allowedRepos = ['nuxt/nuxt', 'vuejs/vue', 'vitejs/vite', 'nitrojs/nitro', 'danielroe/beasties']
9+
810
export default defineCachedEventHandler(async (event) => {
911
const [owner, repo] = getRouterParam(event, 'repo')?.split('/') || []
1012
if (!owner || !repo) {
@@ -14,6 +16,13 @@ export default defineCachedEventHandler(async (event) => {
1416
})
1517
}
1618

19+
if (!allowedRepos.includes(`${owner}/${repo}`)) {
20+
throw createError({
21+
status: 400,
22+
message: 'Repository not allowed',
23+
})
24+
}
25+
1726
const octokit = new Octokit({ auth: useRuntimeConfig(event).github.token })
1827

1928
// TODO: date/state filters?

0 commit comments

Comments
 (0)