MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / streamCompletion

Method streamCompletion

chat/api.js:456–1195  ·  view source on GitHub ↗
(messages, modelId, apiKey, onChunk, onTokenUpdate, files = [], searchEnabled = false, abortController = null, onStreamOpen = null, onReasoningChunk = null, reasoningEnabled = true, reasoningEffort = DEFAULT_REASONING_EFFORT)

Source from the content-addressed store, hash-verified

454 {
455 context,
456 maxAttempts,
457 timeoutMs,
458 signal
459 }
460 );
461
462 if (window.networkLogger) {
463 window.networkLogger.logRequest({
464 type: 'openrouter',
465 method: 'POST',
466 url: url,
467 status: response.status,
468 request: {
469 headers: window.networkLogger.sanitizeHeaders(headers),
470 body: body
471 },
472 response: data
473 });
474 }
475
476 if (!response.ok) {
477 const error = new Error(`HTTP error! status: ${response.status}`);
478 error.status = response.status;
479 error.responseText = text || '';
480 error.data = data;
481 error.responseData = data;
482 throw error;
483 }
484
485 const content = data?.choices?.[0]?.message?.content;
486 if (typeof content !== 'string') {
487 const error = new Error('Invalid completion response');
488 error.responseData = data;
489 throw error;
490 }
491
492 return {
493 content,
494 data,
495 response
496 };
497 } catch (error) {
498 console.error('Error sending completion:', {
499 name: typeof error?.name === 'string'
500 ? error.name.replace(/[^A-Za-z0-9_.-]/g, '').slice(0, 80)
501 : 'Error',
502 code: typeof error?.code === 'string'
503 ? error.code.replace(/[^A-Za-z0-9_.-]/g, '').slice(0, 80)
504 : null,
505 status: Number.isFinite(Number(error?.status)) ? Number(error.status) : null
506 });
507
508 if (window.networkLogger) {
509 window.networkLogger.logRequest({
510 type: 'openrouter',
511 method: 'POST',
512 url: url,
513 status: Number.isFinite(error?.status) ? error.status : 0,

Callers 5

regenerateResponseMethod · 0.80
sendMessageMethod · 0.80
inlineQuickAskMethod · 0.80
streamCompletionFunction · 0.80

Calls 10

getApiKeyMethod · 0.95
normalizeReasoningEffortFunction · 0.90
filesToMultimodalContentFunction · 0.85
logRequestMethod · 0.80
sanitizeHeadersMethod · 0.80
getSystemPromptFunction · 0.70
fetchWithRetryMethod · 0.45

Tested by

no test coverage detected