diff --git a/packages/webapp/src/api/api.ts b/packages/webapp/src/api/api.ts deleted file mode 100644 index c0886f5a..00000000 --- a/packages/webapp/src/api/api.ts +++ /dev/null @@ -1,112 +0,0 @@ -import { type AskRequest, type ChatResponse, type ChatRequest } from './models.js'; - -export const apiBaseUrl = import.meta.env.VITE_SEARCH_API_URI ?? ''; - -export async function askApi(options: AskRequest): Promise { - const response = await fetch(`${apiBaseUrl}/ask`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - question: options.question, - context: { - approach: options.context?.approach, - retrieval_mode: options.context?.retrievalMode, - semantic_ranker: options.context?.semanticRanker, - semantic_captions: options.context?.semanticCaptions, - top: options.context?.top, - temperature: options.context?.temperature, - prompt_template: options.context?.promptTemplate, - prompt_template_prefix: options.context?.promptTemplatePrefix, - prompt_template_suffix: options.context?.promptTemplateSuffix, - exclude_category: options.context?.excludeCategory, - }, - }), - }); - - const parsedResponse: ChatResponse = await response.json(); - if (response.status > 299 || !response.ok) { - throw new Error(parsedResponse.error || 'Unknown error'); - } - - return parsedResponse; -} - -export async function chatApi(options: ChatRequest): Promise { - const response = await fetch(`${apiBaseUrl}/chat`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - messages: options.messages, - stream: options.stream, - context: { - approach: options.context?.approach, - retrieval_mode: options.context?.retrievalMode, - semantic_ranker: options.context?.semanticRanker, - semantic_captions: options.context?.semanticCaptions, - top: options.context?.top, - temperature: options.context?.temperature, - prompt_template: options.context?.promptTemplate, - prompt_template_prefix: options.context?.promptTemplatePrefix, - prompt_template_suffix: options.context?.promptTemplateSuffix, - exclude_category: options.context?.excludeCategory, - suggest_followup_questions: options.context?.suggestFollowupQuestions, - }, - }), - }); - - if (options.stream) { - return response; - } - - const parsedResponse: ChatResponse = await response.json(); - if (response.status > 299 || !response.ok) { - throw new Error(parsedResponse.error || 'Unknown error'); - } - - return parsedResponse; -} - -export function getCitationFilePath(citation: string): string { - return `${apiBaseUrl}/content/${citation}`; -} - -export class NdJsonParserStream extends TransformStream { - private buffer: string = ''; - constructor() { - let controller: TransformStreamDefaultController; - super({ - start: (_controller) => { - controller = _controller; - }, - transform: (chunk) => { - const jsonChunks = chunk.split('\n').filter(Boolean); - for (const jsonChunk of jsonChunks) { - try { - this.buffer += jsonChunk; - controller.enqueue(JSON.parse(this.buffer)); - this.buffer = ''; - } catch { - // Invalid JSON, wait for next chunk - } - } - }, - }); - } -} - -export async function* getChunksFromResponse(response: Response): AsyncGenerator { - const reader = response.body?.pipeThrough(new TextDecoderStream()).pipeThrough(new NdJsonParserStream()).getReader(); - if (!reader) { - throw new Error('No response body or body is not readable'); - } - - let value: JSON | undefined; - let done: boolean; - while ((({ value, done } = await reader.read()), !done)) { - yield value as T; - } -} diff --git a/packages/webapp/src/api/index.ts b/packages/webapp/src/api/index.ts index 20d70e13..31fbf94f 100644 --- a/packages/webapp/src/api/index.ts +++ b/packages/webapp/src/api/index.ts @@ -1,2 +1,2 @@ -export * from './api.js'; export * from './models.js'; +export const apiBaseUrl = import.meta.env.VITE_SEARCH_API_URI ?? ''; diff --git a/packages/webapp/src/api/models.ts b/packages/webapp/src/api/models.ts index 27283510..5acc757a 100644 --- a/packages/webapp/src/api/models.ts +++ b/packages/webapp/src/api/models.ts @@ -9,61 +9,3 @@ export const enum RetrievalMode { Vectors = 'vectors', Text = 'text', } - -export type AskRequestOverrides = { - retrievalMode?: RetrievalMode; - semanticRanker?: boolean; - semanticCaptions?: boolean; - excludeCategory?: string; - top?: number; - temperature?: number; - promptTemplate?: string; - promptTemplatePrefix?: string; - promptTemplateSuffix?: string; -}; - -export type AskRequest = { - question: string; - context?: AskRequestOverrides & { - approach?: Approaches; - }; -}; - -export type Message = { - content: string; - role: string; - context?: Record & { - data_points?: string[]; - thoughts?: string; - }; -}; - -export type ChatResponse = { - choices: Array<{ - index: number; - message: Message; - }>; - error?: string; -}; - -export type ChatResponseChunk = { - choices: Array<{ - index: number; - delta: Partial; - }>; - error?: string; -}; - -export type ChatTurn = { - user: string; - bot?: string; -}; - -export type ChatRequest = { - messages: ChatTurn[]; - stream?: boolean; - context?: AskRequestOverrides & { - approach?: Approaches; - suggestFollowupQuestions?: boolean; - }; -}; diff --git a/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.module.css b/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.module.css deleted file mode 100644 index ce6c134e..00000000 --- a/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.module.css +++ /dev/null @@ -1,6 +0,0 @@ -.thoughtProcess { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; - word-wrap: break-word; - padding-top: 12px; - padding-bottom: 12px; -} diff --git a/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.tsx b/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.tsx deleted file mode 100644 index fffc0164..00000000 --- a/packages/webapp/src/components/AnalysisPanel/AnalysisPanel.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { Pivot, PivotItem } from '@fluentui/react'; -import DOMPurify from 'dompurify'; - -import styles from './AnalysisPanel.module.css'; - -import { SupportingContent } from '../SupportingContent/index.js'; -import { type Message } from '../../api/index.js'; -import { AnalysisPanelTabs } from './AnalysisPanelTabs.jsx'; - -interface Props { - className: string; - activeTab: AnalysisPanelTabs; - onActiveTabChanged: (tab: AnalysisPanelTabs) => void; - activeCitation: string | undefined; - citationHeight: string; - answer: Message; -} - -const pivotItemDisabledStyle = { disabled: true, style: { color: 'grey' } }; - -export const AnalysisPanel = ({ - answer, - activeTab, - activeCitation, - citationHeight, - className, - onActiveTabChanged, -}: Props) => { - const isDisabledThoughtProcessTab: boolean = !answer.context?.thoughts; - const isDisabledSupportingContentTab: boolean = answer.context?.data_points?.length === 0; - const isDisabledCitationTab: boolean = !activeCitation; - const sanitizedThoughts = DOMPurify.sanitize(answer.context?.thoughts ?? ''); - - return ( - pivotItem && onActiveTabChanged(pivotItem.props.itemKey! as AnalysisPanelTabs)} - > - -
-
- {answer.context?.data_points && ( - - - - )} - -