Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions convex/lib/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,40 @@ export async function generateEmbedding(text: string) {
return emptyEmbedding()
}

const response = await fetch('https://api.openai.com/v1/embeddings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: EMBEDDING_MODEL,
input: text,
}),
})
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 10000) // 10 second timeout

if (!response.ok) {
const message = await response.text()
throw new Error(`Embedding failed: ${message}`)
}
try {
const response = await fetch('https://api.openai.com/v1/embeddings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: EMBEDDING_MODEL,
input: text,
}),
signal: controller.signal,
})

if (!response.ok) {
const message = await response.text()
throw new Error(`Embedding failed: ${message}`)
}

const payload = (await response.json()) as {
data?: Array<{ embedding: number[] }>
const payload = (await response.json()) as {
data?: Array<{ embedding: number[] }>
}
const embedding = payload.data?.[0]?.embedding
if (!embedding) throw new Error('Embedding missing from response')
return embedding
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
throw new Error('OpenAI API request timed out after 10 seconds')
}
throw error
} finally {
clearTimeout(timeoutId)
}
const embedding = payload.data?.[0]?.embedding
if (!embedding) throw new Error('Embedding missing from response')
return embedding
}
2 changes: 1 addition & 1 deletion convex/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const hydrateResults = internalQuery({
}),
)

return entries.filter((entry): entry is HydratedEntry => entry !== null)
return entries.filter((entry) => entry !== null) as HydratedEntry[]
},
})

Expand Down
24 changes: 12 additions & 12 deletions src/routes/skills/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ export function SkillsIndex() {

return (
<main className="section">
<header className="skills-header">
<div>
<h1 className="section-title" style={{ marginBottom: 8 }}>
Skills
</h1>
<p className="section-subtitle" style={{ marginBottom: 0 }}>
{isLoadingSkills
? 'Loading skills…'
: `Browse the skill library${highlightedOnly ? ' (highlighted)' : ''}.`}
</p>
</div>
<header className="skills-header-top">
<h1 className="section-title" style={{ marginBottom: 8 }}>
Skills
</h1>
<p className="section-subtitle" style={{ marginBottom: 0 }}>
{isLoadingSkills
? 'Loading skills…'
: `Browse the skill library${highlightedOnly ? ' (highlighted)' : ''}.`}
</p>
</header>
<div className="skills-container">
<div className="skills-toolbar">
<div className="skills-search">
<input
Expand Down Expand Up @@ -323,7 +323,6 @@ export function SkillsIndex() {
</button>
</div>
</div>
</header>

{isLoadingSkills ? (
<div className="card">
Expand Down Expand Up @@ -394,6 +393,7 @@ export function SkillsIndex() {
})}
</div>
)}
</div>

{canLoadMore ? (
<div
Expand Down
12 changes: 11 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,16 @@ code {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 20px;
max-width: 100%;
}

.skills-header-top {
margin-bottom: 22px;
}

.skills-container {
max-width: 900px;
margin: 0 auto;
}

.skills-header {
Expand All @@ -770,7 +780,7 @@ code {
border-radius: 18px;
border: 1px solid rgba(255, 107, 74, 0.18);
background: linear-gradient(135deg, var(--surface), var(--surface-muted));
min-width: min(520px, 100%);
margin-bottom: 22px;
}

.skills-search {
Expand Down