Skip to content

Commit

Permalink
prioritize featured tools in search results (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville authored Aug 16, 2024
1 parent e4692ca commit f088803
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Prisma } from '@prisma/client'
import { PrismaClient } from '@prisma/client'
import type { Tool, ToolExample } from '@/lib/types'
import { FeaturedTools } from '@/lib/featured'

const prisma = new PrismaClient()
const all = -1
Expand Down Expand Up @@ -127,19 +128,30 @@ export async function getToolsForQuery(query: string, page: number, pageSize: nu
skip: skip > 0 && page != all ? skip : undefined,
})

const featured: Record<string, Tool[]> = {}
const tools: Record<string, Tool[]> = {}

// Add them to the results so that the ones with the query in the reference come first
for (const entry of toolEntriesWithReference) {
const parsedTool = entry.content as Tool[]
tools[entry.reference] = tools[entry.reference] || []
tools[entry.reference].push(...parsedTool)
if (FeaturedTools.has(entry.reference)) {
featured[entry.reference] = featured[entry.reference] || []
featured[entry.reference].push(...parsedTool)
} else {
tools[entry.reference] = tools[entry.reference] || []
tools[entry.reference].push(...parsedTool)
}
}

for (const entry of toolEntriesWithDescription) {
const parsedTool = entry.content as Tool[]
tools[entry.reference] = tools[entry.reference] || []
tools[entry.reference].push(...parsedTool)
if (FeaturedTools.has(entry.reference)) {
featured[entry.reference] = featured[entry.reference] || []
featured[entry.reference].push(...parsedTool)
} else {
tools[entry.reference] = tools[entry.reference] || []
tools[entry.reference].push(...parsedTool)
}
}

const totalCount = await prisma.toolEntry.count({
Expand All @@ -161,5 +173,5 @@ export async function getToolsForQuery(query: string, page: number, pageSize: nu
}
})

return { tools, totalCount }
return { tools: {...featured, ...tools}, totalCount }
}
41 changes: 41 additions & 0 deletions src/lib/featured.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const FeaturedTools = new Set<string>([
"github.com/gptscript-ai/gpt4-v-vision@gateway",
"github.com/gptscript-ai/dalle-image-generation@gateway",
"github.com/gptscript-ai/answers-from-the-internet",
"github.com/gptscript-ai/search-website",
"github.com/gptscript-ai/browser",
"github.com/gptscript-ai/tools/apis/slack/write",
"github.com/gptscript-ai/tools/apis/notion/write",
"github.com/gptscript-ai/tools/apis/trello",
"github.com/gptscript-ai/tools/apis/outlook/mail/manage",
"github.com/gptscript-ai/tools/apis/outlook/calendar/manage",
"github.com/gptscript-ai/[email protected]",
"github.com/gptscript-ai/structured-data-querier",
"github.com/gptscript-ai/json-query",
"github.com/gptscript-ai/context/filesystem",
"github.com/gptscript-ai/context/workspace",
"github.com/gptscript-ai/tools/clis/github",
"github.com/gptscript-ai/tools/clis/aws",
"github.com/gptscript-ai/tools/clis/azure",
"github.com/gptscript-ai/tools/clis/digitalocean",
"github.com/gptscript-ai/tools/clis/eksctl",
"github.com/gptscript-ai/tools/clis/atlas",
"github.com/gptscript-ai/tools/clis/gcp",
"github.com/gptscript-ai/tools/clis/k8s",
"github.com/gptscript-ai/tools/clis/supabase",
"sys.append",
"sys.download",
"sys.exec",
"sys.find",
"sys.getenv",
"sys.http.html2text",
"sys.http.get",
"sys.http.post",
"sys.ls",
"sys.prompt",
"sys.read",
"sys.remove",
"sys.stat",
"sys.time.now",
"sys.write",
])

0 comments on commit f088803

Please sign in to comment.