Skip to content

Commit

Permalink
Merge pull request #737 from StampyAI/sundry-fixes
Browse files Browse the repository at this point in the history
Fix reference order
  • Loading branch information
mruwnik authored Jun 19, 2024
2 parents 49a698f + 3efd857 commit 8ae392e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/components/Feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Feedback = ({
<CompositeButton secondary>
<Action
pageid={pageid}
showText={!!labels}
showtext={(!!labels).toString()}
actionType={ActionType.HELPFUL}
disabled={voted}
hint={upHint}
Expand All @@ -71,7 +71,7 @@ const Feedback = ({
/>
<Action
pageid={pageid}
showText={!!labels}
showtext={(!!labels).toString()}
hint={downHint}
actionType={ActionType.UNHELPFUL}
disabled={voted}
Expand Down
24 changes: 10 additions & 14 deletions app/hooks/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,19 @@ export const findCitations: (text: string, citations: Citation[]) => Map<string,
) => {
// figure out what citations are in the response, and map them appropriately
const cite_map = new Map<string, Citation>()
const byRef = citations.reduce((acc, c) => ({...acc, [c.reference]: c}), {}) as {
[k: string]: Citation
}
let index = 1
const refs = [...text.matchAll(/\[(\d+)\]/g)]
refs.forEach(([_, num]) => {
if (!num || cite_map.has(num)) return
const citation = byRef[num as keyof typeof byRef]
if (!citation) return

// scan a regex for [x] over the response. If x isn't in the map, add it.
// (note: we're actually doing this twice - once on parsing, once on render.
// if that looks like a problem, we could swap from strings to custom ropes).
const regex = /\[(\d+)\]/g
let match
while ((match = regex.exec(text)) !== null) {
const ref = match[1]
if (!ref || cite_map.has(ref!)) continue

const citation = citations[parseInt(ref, 10)]
if (!citation) continue
cite_map.set(num, {...citation, index: index++})
})

cite_map.set(ref!, {...citation, index})
index++
}
return cite_map
}

Expand Down
Empty file removed app/routes/questions.editors.tsx
Empty file.
Binary file removed public/favicon-min-512.png
Binary file not shown.
Binary file removed public/favicon-min.ico
Binary file not shown.

0 comments on commit 8ae392e

Please sign in to comment.