Spaces:
Sleeping
Sleeping
File size: 4,049 Bytes
f866820 2eda359 aa663e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
// Use environment variable for API URL, fallback to localhost for development
const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8000/api';
/**
* Run a query with zero-storage privacy
* Requires Dropbox access token to re-fetch documents at query time
*/
export async function runQuery(query, accessToken, topK = 3) {
const res = await fetch(`${API_BASE}/query-secure`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query,
access_token: accessToken,
top_k: topK
})
});
return res.json();
}
export async function reindex(docsDir, outputPath = 'data/chunks.jsonl') {
const res = await fetch(`${API_BASE}/ingest`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ docs_dir: docsDir, output_path: outputPath })
});
return res.json();
}
export async function syncPinecone(chunksPath = 'data/chunks.jsonl') {
const res = await fetch(`${API_BASE}/sync-pinecone`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chunks_path: chunksPath })
});
return res.json();
}
export async function getStatus(chunksPath = 'data/chunks.jsonl') {
const res = await fetch(`${API_BASE}/status?chunks_path=${encodeURIComponent(chunksPath)}`);
return res.json();
}
export async function healthCheck() {
const res = await fetch(`${API_BASE}/health`);
return res.json();
}
/**
* Clear all vectors from Pinecone index
*/
export async function clearIndex() {
const res = await fetch(`${API_BASE}/clear-index`, {
method: 'DELETE'
});
return res.json();
}
/**
* Send pre-chunked text to server for embedding
* Text is discarded immediately after embedding
*/
export async function embedChunks(chunks) {
const res = await fetch(`${API_BASE}/embed-chunks`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chunks })
});
return res.json();
}
/**
* Exchange Dropbox authorization code for access token
*/
export async function exchangeDropboxCode(code, redirectUri) {
const res = await fetch(`${API_BASE}/dropbox/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code, redirect_uri: redirectUri })
});
return res.json();
}
/**
* Get Dropbox folder contents via backend proxy
*/
export async function getDropboxFolder(path, accessToken) {
const res = await fetch(`${API_BASE}/dropbox/folder`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path, access_token: accessToken })
});
return res.json();
}
/**
* Get Dropbox file content via backend proxy
*/
export async function getDropboxFile(filePath, accessToken) {
const res = await fetch(`${API_BASE}/dropbox/file`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: filePath, access_token: accessToken })
});
return res.json();
}
/**
* Evaluate Docling parsing on a Dropbox file
* Returns element breakdown and parsing metrics
*/
export async function evalParsing(filePath, accessToken) {
const res = await fetch(`${API_BASE}/eval/parsing`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: filePath, access_token: accessToken })
});
return res.json();
}
/**
* Get supported document formats for Docling parsing
*/
export async function getSupportedFormats() {
const res = await fetch(`${API_BASE}/eval/formats`);
return res.json();
}
/**
* Parse files with Docling and return COMPLETE output
* Returns all elements (not just samples) for full document preview
*/
export async function parseWithDocling(files, accessToken) {
const res = await fetch(`${API_BASE}/parse-docling`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ files, access_token: accessToken })
});
return res.json();
}
|