Skip to content

Commit 2a09e10

Browse files
committed
Updated page number citations and fixed PDF Viewer
1 parent 48c12ee commit 2a09e10

File tree

5 files changed

+87
-31
lines changed

5 files changed

+87
-31
lines changed

src/components/ChatInterface.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ export function ChatInterface({ onCitationClick }: ChatInterfaceProps) {
7272
: msg
7373
));
7474
},
75-
onDone: () => {
75+
onDone: (sources) => {
76+
// Convert sources to citations format and add to message
77+
if (sources && sources.length > 0) {
78+
const citations = sources.map(source => ({
79+
page: source.page,
80+
text: source.text
81+
}));
82+
83+
setMessages(prev => prev.map(msg =>
84+
msg.id === assistantMessageId
85+
? { ...msg, citations }
86+
: msg
87+
));
88+
}
7689
setIsLoading(false);
7790
},
7891
onError: (error) => {
@@ -175,7 +188,7 @@ export function ChatInterface({ onCitationClick }: ChatInterfaceProps) {
175188
: 'bg-muted'
176189
}`}
177190
>
178-
<p className="whitespace-pre-wrap">
191+
<p className="whitespace-pre-wrap text-left">
179192
{message.content}
180193
{message.role === 'assistant' && isLoading && chatConfig.enableStreaming && message === messages[messages.length - 1] && (
181194
<span className="inline-block w-2 h-4 ml-0.5 bg-current animate-pulse" />

src/components/PdfViewer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { Button } from '@/components/ui/button';
55
import { Input } from '@/components/ui/input';
66
import { ScrollArea } from '@/components/ui/scroll-area';
77

8-
// Configure PDF.js worker
9-
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
8+
// Configure PDF.js worker for Vite
9+
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
10+
pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
1011

1112
interface PdfViewerProps {
1213
pdfUrl: string;

src/components/SettingsPanel.tsx

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,26 @@ export function SettingsPanel({ isOpen, onClose }: SettingsPanelProps) {
122122
type="number"
123123
min="1"
124124
max="20"
125-
value={chatConfig.maxChunks || 5}
126-
onChange={(e) =>
127-
updateChatConfig({
128-
maxChunks: Math.max(1, Math.min(20, parseInt(e.target.value) || 5)),
129-
})
130-
}
125+
value={chatConfig.maxChunks ?? ''}
126+
onChange={(e) => {
127+
const value = e.target.value;
128+
if (value === '') {
129+
updateChatConfig({ maxChunks: undefined });
130+
} else {
131+
const num = parseInt(value);
132+
if (!isNaN(num)) {
133+
updateChatConfig({
134+
maxChunks: Math.max(1, Math.min(20, num)),
135+
});
136+
}
137+
}
138+
}}
139+
onBlur={(e) => {
140+
const value = e.target.value;
141+
if (value === '' || isNaN(parseInt(value))) {
142+
updateChatConfig({ maxChunks: 5 });
143+
}
144+
}}
131145
/>
132146
</div>
133147

@@ -147,12 +161,26 @@ export function SettingsPanel({ isOpen, onClose }: SettingsPanelProps) {
147161
min="0"
148162
max="2"
149163
step="0.1"
150-
value={chatConfig.temperature || 0.7}
151-
onChange={(e) =>
152-
updateChatConfig({
153-
temperature: Math.max(0, Math.min(2, parseFloat(e.target.value) || 0.7)),
154-
})
155-
}
164+
value={chatConfig.temperature ?? ''}
165+
onChange={(e) => {
166+
const value = e.target.value;
167+
if (value === '') {
168+
updateChatConfig({ temperature: undefined });
169+
} else {
170+
const num = parseFloat(value);
171+
if (!isNaN(num)) {
172+
updateChatConfig({
173+
temperature: Math.max(0, Math.min(2, num)),
174+
});
175+
}
176+
}
177+
}}
178+
onBlur={(e) => {
179+
const value = e.target.value;
180+
if (value === '' || isNaN(parseFloat(value))) {
181+
updateChatConfig({ temperature: 0.7 });
182+
}
183+
}}
156184
/>
157185
</div>
158186

@@ -171,12 +199,26 @@ export function SettingsPanel({ isOpen, onClose }: SettingsPanelProps) {
171199
type="number"
172200
min="1"
173201
max="50"
174-
value={chatConfig.topK || 10}
175-
onChange={(e) =>
176-
updateChatConfig({
177-
topK: Math.max(1, Math.min(50, parseInt(e.target.value) || 10)),
178-
})
179-
}
202+
value={chatConfig.topK ?? ''}
203+
onChange={(e) => {
204+
const value = e.target.value;
205+
if (value === '') {
206+
updateChatConfig({ topK: undefined });
207+
} else {
208+
const num = parseInt(value);
209+
if (!isNaN(num)) {
210+
updateChatConfig({
211+
topK: Math.max(1, Math.min(50, num)),
212+
});
213+
}
214+
}
215+
}}
216+
onBlur={(e) => {
217+
const value = e.target.value;
218+
if (value === '' || isNaN(parseInt(value))) {
219+
updateChatConfig({ topK: 10 });
220+
}
221+
}}
180222
/>
181223
</div>
182224
</div>

src/services/api.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChatRequest, ChatResponse, Citation } from '@/types/chat';
1+
import { ChatRequest, ChatResponse, Citation, SourceItem } from '@/types/chat';
22
import { ChatConfig } from '@/types/config';
33

44
const API_BASE_URL = 'http://localhost:8000';
@@ -49,7 +49,7 @@ export async function sendChatMessage(
4949

5050
export interface StreamCallbacks {
5151
onToken: (token: string) => void;
52-
onDone: () => void;
52+
onDone: (sources?: SourceItem[]) => void;
5353
onError: (error: string) => void;
5454
}
5555

@@ -112,7 +112,9 @@ export async function sendChatMessageStream(
112112
if (data.type === 'token' && data.content) {
113113
callbacks.onToken(data.content);
114114
} else if (data.type === 'done') {
115-
callbacks.onDone();
115+
// Extract sources from the done message if present
116+
const sources = data.sources || [];
117+
callbacks.onDone(sources);
116118
} else if (data.type === 'error') {
117119
callbacks.onError(data.content || 'Unknown error');
118120
}

src/types/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ export interface ChatConfig {
1010
export const DEFAULT_CHAT_CONFIG: ChatConfig = {
1111
enableChunks: true,
1212
enableStreaming: true,
13-
promptType: 'default',
13+
promptType: 'tutor',
1414
maxChunks: 5,
1515
temperature: 0.7,
1616
topK: 10,
1717
};
1818

1919
export const PROMPT_TYPES = [
20-
{ value: 'default', label: 'Default Prompt' },
21-
{ value: 'concise', label: 'Concise Prompt' },
22-
{ value: 'detailed', label: 'Detailed Prompt' },
23-
{ value: 'educational', label: 'Educational Prompt' },
24-
{ value: 'qa', label: 'Q&A Prompt' },
20+
{ value: 'tutor', label: 'Tutor' },
21+
{ value: 'detailed', label: 'Detailed' },
22+
{ value: 'concise', label: 'Concise' },
2523
];
2624

0 commit comments

Comments
 (0)