Skip to content

Commit

Permalink
Merge pull request #45 from navikt/context-citation-navno-format
Browse files Browse the repository at this point in the history
update citation and context to match new format for navno support
  • Loading branch information
sigbjorn-myhre authored Dec 4, 2024
2 parents 7e2fe3a + e6932c7 commit 82048ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
24 changes: 6 additions & 18 deletions src/components/content/chat/chatbubbles/BobAnswerCitations.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { ExternalLinkIcon } from "@navikt/aksel-icons"
import { BodyLong, BodyShort, Heading, Link } from "@navikt/ds-react"
import Markdown from "react-markdown"
import { Context } from "../../../../types/Message.ts"
import { Citation, Context } from "../../../../types/Message.ts"

interface BobAnswerCitationProps {
citation: {
title: string
text: string
section: string
article: string
}
citation: Citation
context: Context[]
}

// Matching citation.text against context metadata, to find correct URL //
function BobAnswerCitations({ citation, context }: BobAnswerCitationProps) {
const matchingContextCitationData = context
.flatMap((context) => context.metadata)
.find(
(contextMetadata) =>
contextMetadata.Title === citation.title &&
contextMetadata.Section === citation.section &&
contextMetadata.KnowledgeArticleId === citation.article,
)
const matchingContextCitationData = context.at(citation.sourceId)

// Splitting words, making it functional for textStart & textEnd //
const citeWords = citation.text
Expand Down Expand Up @@ -50,12 +38,12 @@ function BobAnswerCitations({ citation, context }: BobAnswerCitationProps) {
<Link
href={
numWords < 1
? `${matchingContextCitationData.KnowledgeArticle_QuartoUrl}`
: `${matchingContextCitationData.KnowledgeArticle_QuartoUrl}#:~:text=${encodeFragment(textStart)},${encodeFragment(textEnd)}`
? `${matchingContextCitationData.url}`
: `${matchingContextCitationData.url}#:~:text=${encodeFragment(textStart)},${encodeFragment(textEnd)}`
}
target='_blank'
>
{citation.title}
{matchingContextCitationData.title}
<ExternalLinkIcon title='Åpne artikkelen i ny fane' />
</Link>
) : (
Expand Down
29 changes: 10 additions & 19 deletions src/types/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,20 @@ export type Message = {

export type Citation = {
text: string
article: string
title: string
section: string
sourceId: number
}

export type Context = {
content: string
metadata: Metadata[]
}

export type Metadata = {
Tab: string
Score: number
Title: string
Headers: null
Section: string
Fragment: string
ArticleType: string
ContentColumn: string
DataCategories: [string]
KnowledgeArticleId: string
SemanticSimilarity: number
KnowledgeArticle_QuartoUrl: string
title: string
ingress: string
source: string
url: string
anchor: string | null
articleId: string
articleColumn: string | null
lastModified: string | null
semanticSimilarity: number
}

export type NewConversation = {
Expand Down

0 comments on commit 82048ca

Please sign in to comment.