Fix Ask AI dialog to proxy requests via Next API (#518)
This commit is contained in:
parent
13e7a5937b
commit
d48846e5b5
21
ui/homepage/app/api/rag/query/route.ts
Normal file
21
ui/homepage/app/api/rag/query/route.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { getServerServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const { question, history } = await req.json()
|
||||
const apiBase = getServerServiceBaseUrl()
|
||||
const response = await fetch(`${apiBase}/api/rag/query`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ question, history })
|
||||
})
|
||||
|
||||
const data = await response.json().catch(() => null)
|
||||
return Response.json(data ?? { error: 'Invalid response from server' }, {
|
||||
status: response.status
|
||||
})
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Unknown error'
|
||||
return Response.json({ error: message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@ -4,12 +4,10 @@ import { useState } from 'react'
|
||||
import { Bot } from 'lucide-react'
|
||||
import { AskAIDialog } from './AskAIDialog'
|
||||
import { useAccess } from '@lib/accessControl'
|
||||
import { getServerServiceBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
export function AskAIButton() {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [minimized, setMinimized] = useState(false)
|
||||
const apiBase = getServerServiceBaseUrl()
|
||||
const { allowed, isLoading } = useAccess({ allowGuests: true })
|
||||
|
||||
if (!allowed && !isLoading) {
|
||||
@ -32,7 +30,6 @@ export function AskAIButton() {
|
||||
|
||||
<AskAIDialog
|
||||
open={open}
|
||||
apiBase={apiBase}
|
||||
onMinimize={() => {
|
||||
setOpen(false)
|
||||
setMinimized(true)
|
||||
|
||||
@ -11,12 +11,10 @@ const MAX_CACHE_SIZE = 50
|
||||
|
||||
export function AskAIDialog({
|
||||
open,
|
||||
apiBase,
|
||||
onMinimize,
|
||||
onEnd
|
||||
}: {
|
||||
open: boolean
|
||||
apiBase: string
|
||||
onMinimize: () => void
|
||||
onEnd: () => void
|
||||
}) {
|
||||
@ -171,7 +169,7 @@ export function AskAIDialog({
|
||||
|
||||
try {
|
||||
let { answer, retrieved } = await streamChat(
|
||||
`${apiBase}/api/rag/query`,
|
||||
'/api/rag/query',
|
||||
{ question: normalized, history },
|
||||
updateAI
|
||||
)
|
||||
@ -184,7 +182,7 @@ export function AskAIDialog({
|
||||
)
|
||||
try {
|
||||
const result = await streamChat(
|
||||
`${apiBase}/api/askai`,
|
||||
'/api/askai',
|
||||
{ question: normalized, history },
|
||||
updateAI
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user