Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reference order #737

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
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()}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get showText vs showtext might have been a problem,, but what's with the .toString() part?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showtext expects a string, so false was causing errors that "false" fixes...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:suspect:

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.
Loading