MCPcopy
hub / github.com/CodebuffAI/codebuff / promptAiSdkStream

Function promptAiSdkStream

sdk/src/impl/llm.ts:286–718  ·  view source on GitHub ↗
(
  params: ParamsOf<PromptAiSdkStreamFn> & {
    skipChatGptOAuth?: boolean
    chatGptOAuthRetried?: boolean
  },
)

Source from the content-addressed store, hash-verified

284}
285
286export async function* promptAiSdkStream(
287 params: ParamsOf<PromptAiSdkStreamFn> & {
288 skipChatGptOAuth?: boolean
289 chatGptOAuthRetried?: boolean
290 },
291): ReturnType<PromptAiSdkStreamFn> {
292 const { providerOptions: originalProviderOptions, ...streamParams } = params
293
294 const {
295 logger,
296 trackEvent,
297 userId,
298 userInputId,
299 model: requestedModel,
300 } = params
301 const agentChunkMetadata =
302 params.agentId != null ? { agentId: params.agentId } : undefined
303
304 if (params.signal.aborted) {
305 logger.info(
306 {
307 userId: params.userId,
308 userInputId: params.userInputId,
309 },
310 'Skipping stream due to canceled user input',
311 )
312 return promptAborted('User cancelled input')
313 }
314
315 const modelParams: ModelRequestParams = {
316 apiKey: params.apiKey,
317 model: params.model,
318 skipChatGptOAuth: params.skipChatGptOAuth,
319 costMode: params.costMode,
320 }
321 const { model: aiSDKModel, isChatGptOAuth } =
322 await getModelForRequest(modelParams)
323
324 if (isChatGptOAuth) {
325 trackEvent({
326 event: AnalyticsEvent.CHATGPT_OAUTH_REQUEST,
327 userId: userId ?? '',
328 properties: {
329 model: requestedModel,
330 userInputId,
331 },
332 logger,
333 })
334 }
335
336 const response = streamText({
337 ...streamParams,
338 prompt: undefined,
339 model: aiSDKModel,
340 messages: convertCbToModelMessages(params),
341 ...(isChatGptOAuth && { maxRetries: 0 }),
342 // For ChatGPT OAuth direct, don't send codebuff metadata/provider options to OpenAI
343 ...(isChatGptOAuth

Callers 1

Calls 15

flushMethod · 0.95
processMethod · 0.95
promptAbortedFunction · 0.90
getModelForRequestFunction · 0.90
convertCbToModelMessagesFunction · 0.90
buildArrayFunction · 0.90
getErrorObjectFunction · 0.90
isFreeModeFunction · 0.90
refreshChatGptOAuthTokenFunction · 0.90
promptSuccessFunction · 0.90
getProviderOptionsFunction · 0.85

Tested by

no test coverage detected