chore: initialize git repo, add matplotlib dep, extend config
- Add .gitignore for Python/data/models - Add matplotlib>=3.8.0 for eval plots - Add PretrainConfig, FinetuneConfig, BalabitAdapterConfig, EvalConfig dataclasses
This commit is contained in:
39
static/js/api.js
Normal file
39
static/js/api.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* API utilities: axios instance and SSE helper.
|
||||
*/
|
||||
|
||||
export const API_BASE = ''
|
||||
|
||||
export const api = axios.create({ baseURL: '/api' })
|
||||
|
||||
/**
|
||||
* Consume a Server-Sent Events stream from a POST endpoint.
|
||||
* @param {string} url - The URL to POST to (e.g. '/api/train')
|
||||
* @param {object} body - JSON body to send
|
||||
* @param {function} onMessage - Callback invoked with each parsed SSE message object
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function fetchSSE(url, body, onMessage) {
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
const reader = resp.body.getReader()
|
||||
const dec = new TextDecoder()
|
||||
let buf = ''
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
buf += dec.decode(value, { stream: true })
|
||||
const parts = buf.split('\n\n')
|
||||
buf = parts.pop()
|
||||
for (const part of parts) {
|
||||
const line = part.trim()
|
||||
if (!line.startsWith('data:')) continue
|
||||
const msg = JSON.parse(line.slice(5).trim())
|
||||
onMessage(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user