Skip to content

Commit ecad4c3

Browse files
Merge pull request #48 from microsoft/jamesqa1
Citation styling and code cleanup
2 parents be4459d + 80a6481 commit ecad4c3

File tree

6 files changed

+74
-161
lines changed

6 files changed

+74
-161
lines changed

frontend/src/api/models.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import Plotly from 'react-plotly.js'
33
export type AskResponse = {
44
answer: string
55
citations: Citation[]
6-
plotly_data: AzureSqlServerCodeExecResult | null
76
error?: string
87
message_id?: string
98
feedback?: Feedback
10-
exec_results?: ExecResults[]
119
}
1210

1311
export type Citation = {
@@ -27,23 +25,6 @@ export type ToolMessageContent = {
2725
intent: string
2826
}
2927

30-
export type AzureSqlServerCodeExecResult = {
31-
data: Plotly.Data[]
32-
layout: Partial<Plotly.Layout>
33-
}
34-
35-
export type AzureSqlServerExecResult = {
36-
intent: string
37-
search_query: string | null
38-
search_result: string | null
39-
code_generated: string | null
40-
code_exec_result?: AzureSqlServerCodeExecResult | undefined
41-
}
42-
43-
export type AzureSqlServerExecResults = {
44-
all_exec_results: AzureSqlServerExecResult[]
45-
}
46-
4728
export type ChatMessage = {
4829
id: string
4930
role: string
@@ -54,13 +35,6 @@ export type ChatMessage = {
5435
context?: string
5536
}
5637

57-
export type ExecResults = {
58-
intent: string
59-
search_query: string | null
60-
search_result: string | null
61-
code_generated: string | null
62-
}
63-
6438
export type Conversation = {
6539
id: string
6640
title: string
@@ -107,7 +81,7 @@ export type DraftedDocument = {
10781
}
10882

10983
export type SectionGenerateRequest = {
110-
sectionTitle: string,
84+
sectionTitle: string
11185
sectionDescription: string
11286
}
11387

@@ -181,4 +155,4 @@ export enum Feedback {
181155
export enum ChatType {
182156
Browse = 'browse',
183157
Template = 'template'
184-
}
158+
}

frontend/src/components/Answer/Answer.tsx

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ThumbDislike20Filled, ThumbLike20Filled } from '@fluentui/react-icons'
88
import DOMPurify from 'dompurify'
99
import remarkGfm from 'remark-gfm'
1010
import supersub from 'remark-supersub'
11-
import Plot from 'react-plotly.js'
1211
import { AskResponse, Citation, Feedback, historyMessageFeedback } from '../../api'
1312
import { XSSAllowTags } from '../../constants/xssAllowTags'
1413
import { AppStateContext } from '../../state/AppProvider'
@@ -20,10 +19,9 @@ import styles from './Answer.module.css'
2019
interface Props {
2120
answer: AskResponse
2221
onCitationClicked: (citedDocument: Citation) => void
23-
onExectResultClicked: () => void
2422
}
2523

26-
export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Props) => {
24+
export const Answer = ({ answer, onCitationClicked }: Props) => {
2725
const initializeAnswerFeedback = (answer: AskResponse) => {
2826
if (answer.message_id == undefined) return undefined
2927
if (answer.feedback == undefined) return undefined
@@ -228,7 +226,7 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
228226
}
229227

230228
const components = {
231-
code({ node, ...props }: { node: any;[key: string]: any }) {
229+
code({ node, ...props }: { node: any; [key: string]: any }) {
232230
let language
233231
if (props.className) {
234232
const match = props.className.match(/language-(\w+)/)
@@ -269,7 +267,7 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
269267
onClick={() => onLikeResponseClicked()}
270268
style={
271269
feedbackState === Feedback.Positive ||
272-
appStateContext?.state.feedbackState[answer.message_id] === Feedback.Positive
270+
appStateContext?.state.feedbackState[answer.message_id] === Feedback.Positive
273271
? { color: 'darkgreen', cursor: 'pointer' }
274272
: { color: 'slategray', cursor: 'pointer' }
275273
}
@@ -280,8 +278,8 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
280278
onClick={() => onDislikeResponseClicked()}
281279
style={
282280
feedbackState !== Feedback.Positive &&
283-
feedbackState !== Feedback.Neutral &&
284-
feedbackState !== undefined
281+
feedbackState !== Feedback.Neutral &&
282+
feedbackState !== undefined
285283
? { color: 'darkred', cursor: 'pointer' }
286284
: { color: 'slategray', cursor: 'pointer' }
287285
}
@@ -291,13 +289,6 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
291289
</Stack.Item>
292290
</Stack>
293291
</Stack.Item>
294-
{parsedAnswer.plotly_data !== null && (
295-
<Stack className={styles.answerContainer}>
296-
<Stack.Item grow>
297-
<Plot data={parsedAnswer.plotly_data.data} layout={parsedAnswer.plotly_data.layout} />
298-
</Stack.Item>
299-
</Stack>
300-
)}
301292
<Stack horizontal className={styles.answerFooter}>
302293
{!!parsedAnswer.citations.length && (
303294
<Stack.Item onKeyDown={e => (e.key === 'Enter' || e.key === ' ' ? toggleIsRefAccordionOpen() : null)}>
@@ -327,29 +318,6 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
327318
<Stack.Item className={styles.answerDisclaimerContainer}>
328319
<span className={styles.answerDisclaimer}>AI-generated content may be incorrect</span>
329320
</Stack.Item>
330-
{!!answer.exec_results?.length && (
331-
<Stack.Item onKeyDown={e => (e.key === 'Enter' || e.key === ' ' ? toggleIsRefAccordionOpen() : null)}>
332-
<Stack style={{ width: '100%' }}>
333-
<Stack horizontal horizontalAlign="start" verticalAlign="center">
334-
<Text
335-
className={styles.accordionTitle}
336-
onClick={() => onExectResultClicked()}
337-
aria-label="Open Intents"
338-
tabIndex={0}
339-
role="button">
340-
<span>
341-
Show Intents
342-
</span>
343-
</Text>
344-
<FontIcon
345-
className={styles.accordionIcon}
346-
onClick={handleChevronClick}
347-
iconName={'ChevronRight'}
348-
/>
349-
</Stack>
350-
</Stack>
351-
</Stack.Item>
352-
)}
353321
</Stack>
354322
{chevronIsExpanded && (
355323
<div className={styles.citationWrapper}>

frontend/src/components/Answer/AnswerParser.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ const sampleCitations: Citation[] = [
4242

4343
const sampleAnswer: AskResponse = {
4444
answer: 'This is an example answer with citations [doc1] and [doc2].',
45-
citations: cloneDeep(sampleCitations),
46-
plotly_data: null
45+
citations: cloneDeep(sampleCitations)
4746
}
4847

4948
describe('enumerateCitations', () => {

frontend/src/components/Answer/AnswerParser.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { cloneDeep } from 'lodash'
22

3-
import { AskResponse, Citation, AzureSqlServerCodeExecResult } from '../../api'
3+
import { AskResponse, Citation } from '../../api'
44

55
export type ParsedAnswer = {
66
citations: Citation[]
7-
markdownFormatText: string,
8-
plotly_data: AzureSqlServerCodeExecResult | null
7+
markdownFormatText: string
98
}
109

1110
export const enumerateCitations = (citations: Citation[]) => {
@@ -46,7 +45,6 @@ export function parseAnswer(answer: AskResponse): ParsedAnswer {
4645

4746
return {
4847
citations: filteredCitations,
49-
markdownFormatText: answerText,
50-
plotly_data: answer.plotly_data
48+
markdownFormatText: answerText
5149
}
5250
}

0 commit comments

Comments
 (0)