mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-15 13:14:35 +00:00
feat: better preidctiosn
This commit is contained in:
@@ -136,30 +136,41 @@ export function createToothFairyAI(options: ToothFairyAIProviderSettings = {}):
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("data: ")) {
|
||||
const json = line.slice(6).trim()
|
||||
if (json && !json.startsWith('{"status":')) {
|
||||
filtered.push(line)
|
||||
// Log tool calls and finish_reason
|
||||
// Filter out connection status messages like {"status":"initialising"}, {"status":"connected"}
|
||||
// These are internal progress indicators, not OpenAI-format chunks
|
||||
if (json) {
|
||||
try {
|
||||
const parsed = JSON.parse(json)
|
||||
if (parsed.choices?.[0]?.delta?.tool_calls) {
|
||||
log.debug("stream tool_calls", {
|
||||
tool_calls: parsed.choices[0].delta.tool_calls,
|
||||
})
|
||||
if (parsed.status === "initialising" || parsed.status === "connected") {
|
||||
log.debug("filtered connection status", { status: parsed.status })
|
||||
continue
|
||||
}
|
||||
if (parsed.choices?.[0]?.finish_reason) {
|
||||
log.info("stream finish_reason", {
|
||||
finish_reason: parsed.choices[0].finish_reason,
|
||||
})
|
||||
}
|
||||
if (parsed.usage) {
|
||||
log.info("stream usage", {
|
||||
prompt_tokens: parsed.usage.prompt_tokens,
|
||||
completion_tokens: parsed.usage.completion_tokens,
|
||||
total_tokens: parsed.usage.total_tokens,
|
||||
})
|
||||
}
|
||||
} catch {}
|
||||
} catch {
|
||||
// Not valid JSON, keep the line
|
||||
}
|
||||
}
|
||||
filtered.push(line)
|
||||
// Log tool calls and finish_reason
|
||||
try {
|
||||
const parsed = JSON.parse(json)
|
||||
if (parsed.choices?.[0]?.delta?.tool_calls) {
|
||||
log.debug("stream tool_calls", {
|
||||
tool_calls: parsed.choices[0].delta.tool_calls,
|
||||
})
|
||||
}
|
||||
if (parsed.choices?.[0]?.finish_reason) {
|
||||
log.info("stream finish_reason", {
|
||||
finish_reason: parsed.choices[0].finish_reason,
|
||||
})
|
||||
}
|
||||
if (parsed.usage) {
|
||||
log.info("stream usage", {
|
||||
prompt_tokens: parsed.usage.prompt_tokens,
|
||||
completion_tokens: parsed.usage.completion_tokens,
|
||||
total_tokens: parsed.usage.total_tokens,
|
||||
})
|
||||
}
|
||||
} catch {}
|
||||
} else {
|
||||
filtered.push(line)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user