Streaming SSE
Streaming SSE
Career API obsluguje Server-Sent Events (SSE) streaming dla endpointow opartych na AI. Pozwala to na otrzymywanie wynikow w czasie rzeczywistym w miare ich generowania.
Endpointy ze Streamingiem
| Endpoint | Opis |
|---|---|
POST /v1/tailor | Sugestie optymalizacji CV |
POST /v1/cover-letters/generate | Generowanie listow motywacyjnych |
Jak Wlaczyc
Dodaj Accept: text/event-stream do naglowkow zapytania:
curl https://api.laddro.com/v1/tailor \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"resumeId": "res_abc123",
"jobDescription": "..."
}'Format Zdarzen
Zdarzenia podazaja za specyfikacja SSE:
data: {"type":"section","section":"summary","content":"Experienced engineer..."}
data: {"type":"section","section":"experience","content":"..."}
data: {"type":"done"}Kazde zdarzenie to obiekt JSON z:
| Pole | Typ | Opis |
|---|---|---|
type | string | section lub done |
section | string | Nazwa sekcji CV (gdy type to section) |
content | string | Wygenerowana tresc |
Przyklady Implementacji
JavaScript (Przegladarka)
const response = await fetch('https://api.laddro.com/v1/tailor', {
method: 'POST',
headers: {
'x-api-key': apiKey,
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({ resumeId, jobDescription })
})
const reader = response.body.getReader()
const decoder = new TextDecoder()
while (true) {
const { done, value } = await reader.read()
if (done) break
const text = decoder.decode(value)
const lines = text.split('\n')
for (const line of lines) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6))
if (event.type === 'done') return
console.log(event.section, event.content)
}
}
}SDK TypeScript
for await (const event of client.tailor(
{ resumeId, jobDescription },
{ stream: true }
)) {
console.log(event.section, event.content)
}SDK Python
for event in client.tailor(
resume_id=resume_id,
job_description=jd,
stream=True
):
print(event.section, event.content)Node.js (Raw)
import { createParser } from 'eventsource-parser'
const response = await fetch('https://api.laddro.com/v1/tailor', {
method: 'POST',
headers: {
'x-api-key': process.env.LADDRO_API_KEY,
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({ resumeId, jobDescription })
})
const parser = createParser(event => {
if (event.type === 'event') {
const data = JSON.parse(event.data)
if (data.type === 'done') return
process.stdout.write(data.content)
}
})
for await (const chunk of response.body) {
parser.feed(new TextDecoder().decode(chunk))
}Obsluga Bledow
Jesli wystapi blad podczas streamingu, strumien wyemituje zdarzenie bledu:
data: {"type":"error","message":"Rate limit exceeded","statusCode":429}Zawsze obsluguj typ zdarzenia bledu w swoim odbiorniku strumienia.