0

Continue a conversation with your data

by
Published Apr 8, 2025

Ask a follow-up question. If the `Accept` header is set to `text/event-stream`, Xata will stream the results back as SSE's.

Script xata Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Xata = {
3
	apiKey: string
4
	workspaceUrl: string
5
}
6
/**
7
 * Continue a conversation with your data
8
 * Ask a follow-up question. If the `Accept` header is set to `text/event-stream`, Xata will stream the results back as SSE's.
9
 */
10
export async function main(
11
	auth: Xata,
12
	db_branch_name: string,
13
	table_name: string,
14
	session_id: string,
15
	body: { message?: string }
16
) {
17
	const url = new URL(
18
		`${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/ask/${session_id}`
19
	)
20

21
	const response = await fetch(url, {
22
		method: 'POST',
23
		headers: {
24
			'Content-Type': 'application/json',
25
			Authorization: 'Bearer ' + auth.apiKey
26
		},
27
		body: JSON.stringify(body)
28
	})
29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33
	return await response.json()
34
}
35