Laddro DocsLaddro Docs

SSE-striimaus

SSE-striimaus

Career API tukee Server-Sent Events (SSE) -striimausta tekoalypaatepisteille. Taman avulla voit vastaanottaa tuloksia reaaliajassa sita mukaa kun ne generoidaan.

Striimauspaatepisteet

PaatepisteKuvaus
POST /v1/tailorAnsioluettelon raatalointiehdotukset
POST /v1/cover-letters/generateSaatekirjeen generointi

Kayttoonotto

Lisaa Accept: text/event-stream pyynton otsikkoihin:

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": "..."
  }'

Tapahtumamuoto

Tapahtumat noudattavat SSE-maaritelmaa:

data: {"type":"section","section":"summary","content":"Experienced engineer..."}

data: {"type":"section","section":"experience","content":"..."}

data: {"type":"done"}

Jokainen tapahtuma on JSON-objekti, jossa:

KenttaTyyppiKuvaus
typestringsection tai done
sectionstringAnsioluettelon osion nimi (kun type on section)
contentstringGeneroitu sisalto

Toteutusesimerkit

JavaScript (selain)

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)
    }
  }
}

TypeScript SDK

for await (const event of client.tailor(
  { resumeId, jobDescription }, { stream: true }
)) {
  console.log(event.section, event.content)
}

Python SDK

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))
}

Virheiden kasittely

Jos virhe tapahtuu striimauksen aikana, striimi lahettaa virhetapahtuman:

data: {"type":"error","message":"Rate limit exceeded","statusCode":429}

Kasittele aina virhetapahtumatyyppi striimin kuluttajassasi.

On this page