@discomedia/utils 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7374,21 +7374,66 @@ const makeResponsesAPICall = async (input, options = {}) => {
7374
7374
  * Makes a call to the OpenAI Responses API for advanced use cases with built-in tools.
7375
7375
  *
7376
7376
  * @param input The text prompt to send to the model (e.g., "What's in this image?")
7377
- * @param options The options for the Responses API call, including optional image data.
7377
+ * @param options The options for the Responses API call, including optional image data and context.
7378
7378
  * @return A promise that resolves to the response from the Responses API.
7379
+ *
7380
+ * @example
7381
+ * // With conversation context
7382
+ * const response = await makeLLMCall("What did I ask about earlier?", {
7383
+ * context: [
7384
+ * { role: 'user', content: 'What is the capital of France?' },
7385
+ * { role: 'assistant', content: 'The capital of France is Paris.' }
7386
+ * ]
7387
+ * });
7379
7388
  */
7380
7389
  async function makeLLMCall(input, options = {}) {
7381
- const { apiKey, model = DEFAULT_MODEL$1, responseFormat = 'text', tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high' } = options;
7390
+ const { apiKey, model = DEFAULT_MODEL$1, responseFormat = 'text', tools, useCodeInterpreter = false, useWebSearch = false, imageBase64, imageDetail = 'high', context } = options;
7382
7391
  // Validate model
7383
7392
  const normalizedModel = normalizeModelName(model);
7384
7393
  if (!isSupportedModel(normalizedModel)) {
7385
7394
  throw new Error(`Unsupported model: ${normalizedModel}. Please use one of the supported models.`);
7386
7395
  }
7387
- // Process input for image analysis
7396
+ // Process input for conversation context and image analysis
7388
7397
  let processedInput;
7389
- if (imageBase64) {
7390
- // Combine text prompt with image for multi-modal input
7391
- // Based on OpenAI's sample code structure
7398
+ if (context && context.length > 0) {
7399
+ // Build conversation array with context
7400
+ const conversationMessages = [];
7401
+ // Add context messages
7402
+ for (const contextMsg of context) {
7403
+ conversationMessages.push({
7404
+ role: contextMsg.role,
7405
+ content: contextMsg.content,
7406
+ type: 'message'
7407
+ });
7408
+ }
7409
+ // Add current input message
7410
+ if (imageBase64) {
7411
+ // Current message includes both text and image
7412
+ conversationMessages.push({
7413
+ role: 'user',
7414
+ content: [
7415
+ { type: 'input_text', text: input },
7416
+ {
7417
+ type: 'input_image',
7418
+ detail: imageDetail,
7419
+ image_url: imageBase64.startsWith('data:') ? imageBase64 : `data:image/webp;base64,${imageBase64}`,
7420
+ }
7421
+ ],
7422
+ type: 'message'
7423
+ });
7424
+ }
7425
+ else {
7426
+ // Current message is just text
7427
+ conversationMessages.push({
7428
+ role: 'user',
7429
+ content: input,
7430
+ type: 'message'
7431
+ });
7432
+ }
7433
+ processedInput = conversationMessages;
7434
+ }
7435
+ else if (imageBase64) {
7436
+ // No context, but has image - use the original image logic
7392
7437
  processedInput = [
7393
7438
  {
7394
7439
  role: 'user',
@@ -7399,11 +7444,13 @@ async function makeLLMCall(input, options = {}) {
7399
7444
  detail: imageDetail,
7400
7445
  image_url: imageBase64.startsWith('data:') ? imageBase64 : `data:image/webp;base64,${imageBase64}`,
7401
7446
  }
7402
- ]
7447
+ ],
7448
+ type: 'message'
7403
7449
  }
7404
7450
  ];
7405
7451
  }
7406
7452
  else {
7453
+ // No context, no image - simple string input
7407
7454
  processedInput = input;
7408
7455
  }
7409
7456
  // Build the options object for makeResponsesAPICall