Skip to content

Commit 84f49ae

Browse files
author
pitrat
committed
feat: implement OpenAI-powered search routing (tscircuit#97)
1 parent 3d430c8 commit 84f49ae

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

routes/api/search.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,14 @@ export default withWinterSpec({
8080
price: extractSmallQuantityPrice(c.price),
8181
}))
8282

83-
return ctx.json({
84-
components: req.query.full ? fullComponents : components,
85-
})
83+
return ctx.json({ components: req.query.full ? fullComponents : components })
8684
}
8785

8886
// 1. Check for OpenAI key
89-
let openai
87+
let openai;
9088
try {
9189
openai = getOpenAiClient()
9290
} catch (err) {
93-
// If not configured, only fail for complex queries
9491
const isComplex = q && (q.split(" ").length > 1 || /[0-9]/.test(q))
9592
if (isComplex) {
9693
return ctx.error(400, {
@@ -125,10 +122,7 @@ Output format: {"table": string, "filters": object, "q": string}`,
125122
}
126123

127124
// 3. Specialized Search
128-
let specQuery = ctx.db
129-
.selectFrom(routing.table as any)
130-
.selectAll()
131-
.limit(limit)
125+
let specQuery = ctx.db.selectFrom(routing.table as any).selectAll().limit(limit)
132126
for (const [k, v] of Object.entries(routing.filters || {})) {
133127
specQuery = specQuery.where(k as any, "=", v as any)
134128
}

0 commit comments

Comments
 (0)