Skip to content

Commit

Permalink
[feature] Update structured data response
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Seabock (Centific Technologies Inc) committed Jul 2, 2024
1 parent 38b7862 commit 80bc2ed
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 3,648 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Plotly from 'react-plotly.js'
export type AskResponse = {
answer: string
citations: Citation[]
plotly_data: AzureSqlServerCodeExecResult | null
generated_chart: string | null
error?: string
message_id?: string
feedback?: Feedback
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Answer/Answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ export const Answer = ({ answer, onCitationClicked, onExectResultClicked }: Prop
</Stack.Item>
</Stack>
</Stack.Item>
{parsedAnswer.plotly_data !== null && (
{parsedAnswer.generated_chart !== null && (
<Stack className={styles.answerContainer}>
<Stack.Item grow>
<Plot data={parsedAnswer.plotly_data.data} layout={parsedAnswer.plotly_data.layout} />
<img src={`data:image/png;base64, ${parsedAnswer.generated_chart}`} />
</Stack.Item>
</Stack>
)}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Answer/AnswerParser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AskResponse, Citation, AzureSqlServerCodeExecResult } from '../../api'
export type ParsedAnswer = {
citations: Citation[]
markdownFormatText: string,
plotly_data: AzureSqlServerCodeExecResult | null
generated_chart: string | null
}

export const enumerateCitations = (citations: Citation[]) => {
Expand Down Expand Up @@ -47,6 +47,6 @@ export function parseAnswer(answer: AskResponse): ParsedAnswer {
return {
citations: filteredCitations,
markdownFormatText: answerText,
plotly_data: answer.plotly_data
generated_chart: answer.generated_chart
}
}
9 changes: 6 additions & 3 deletions frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,13 @@ const Chat = () => {
try {
const execResults = JSON.parse(message.content) as AzureSqlServerExecResults;
const codeExecResult = execResults.all_exec_results.at(-1)?.code_exec_result;
console.log('execResults :', execResults);
console.log("codeExecResult: ", codeExecResult && atob(codeExecResult.toString()))
// codeExecResult && setChart(atob(codeExecResult.toString()))
if (codeExecResult === undefined) {
return null;
}
return codeExecResult;
return codeExecResult.toString();
}
catch {
return null;
Expand Down Expand Up @@ -784,7 +787,7 @@ const Chat = () => {
answer={{
answer: answer.content,
citations: parseCitationFromMessage(messages[index - 1]),
plotly_data: parsePlotFromMessage(messages[index - 1]),
generated_chart: parsePlotFromMessage(messages[index - 1]),
message_id: answer.id,
feedback: answer.feedback,
exec_results: execResults
Expand All @@ -811,7 +814,7 @@ const Chat = () => {
answer={{
answer: "Generating answer...",
citations: [],
plotly_data: null
generated_chart: null
}}
onCitationClicked={() => null}
onExectResultClicked={() => null}
Expand Down
3,638 changes: 0 additions & 3,638 deletions static/assets/index-2e11eaf6.js

This file was deleted.

1 change: 0 additions & 1 deletion static/assets/index-2e11eaf6.js.map

This file was deleted.

155 changes: 155 additions & 0 deletions static/assets/index-90158a7d.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/assets/index-90158a7d.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/x-icon" href="{{ favicon }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ title }}</title>
<script type="module" crossorigin src="/assets/index-2e11eaf6.js"></script>
<script type="module" crossorigin src="/assets/index-90158a7d.js"></script>
<link rel="stylesheet" href="/assets/index-61492790.css">
</head>
<body>
Expand Down

0 comments on commit 80bc2ed

Please sign in to comment.