feature: local and production level connection
This commit is contained in:
parent
fbf5ad5561
commit
10eae505ef
|
|
@ -1,7 +1,8 @@
|
||||||
import type { ChatMode } from '@/types/chat'
|
import type { ChatMode } from '@/types/chat'
|
||||||
|
|
||||||
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:5000'
|
const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000'
|
||||||
const USE_MOCK_DATA = true // Set to false when backend is ready
|
const API_ENDPOINT = import.meta.env.VITE_API_ENDPOINT || '/chat/stream'
|
||||||
|
const USE_MOCK_DATA = false // Set to true to use mock data for testing
|
||||||
|
|
||||||
// Session management
|
// Session management
|
||||||
export const getChatSessionId = (): string | null => {
|
export const getChatSessionId = (): string | null => {
|
||||||
|
|
@ -102,15 +103,14 @@ class ApiClient {
|
||||||
yield { type: 'session_id', data: actualSessionId }
|
yield { type: 'session_id', data: actualSessionId }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/api/chat/stream`, {
|
const response = await fetch(`${API_BASE_URL}${API_ENDPOINT}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
question,
|
message: question,
|
||||||
mode,
|
conversation_id: actualSessionId,
|
||||||
sessionId: actualSessionId,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -141,24 +141,19 @@ class ApiClient {
|
||||||
if (line.startsWith('data: ')) {
|
if (line.startsWith('data: ')) {
|
||||||
const data = line.slice(6)
|
const data = line.slice(6)
|
||||||
|
|
||||||
if (data === '[DONE]') {
|
|
||||||
yield { type: 'done', data: null }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(data)
|
const parsed = JSON.parse(data)
|
||||||
if (parsed.type === 'error') {
|
if (parsed.type === 'chunk' && parsed.content) {
|
||||||
yield { type: 'error', data: parsed.message }
|
|
||||||
} else if (parsed.content) {
|
|
||||||
yield { type: 'chunk', data: parsed.content }
|
yield { type: 'chunk', data: parsed.content }
|
||||||
} else {
|
} else if (parsed.type === 'done') {
|
||||||
// Raw string chunk
|
yield { type: 'done', data: null }
|
||||||
yield { type: 'chunk', data: data }
|
return
|
||||||
|
} else if (parsed.type === 'error') {
|
||||||
|
yield { type: 'error', data: parsed.message || 'Unknown error' }
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Raw string chunk (not JSON)
|
// Skip non-JSON lines
|
||||||
yield { type: 'chunk', data: data }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue