Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/component/ai/gemini/v0/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ func extractSystemMessage(in SystemMessageInput) string {
// MaxInlineSize is the 20MB threshold for determining when to use File API based on total request size
const MaxInlineSize = 20 * 1024 * 1024

// FileAPITimeout is the timeout for File API operations (upload and processing)
const FileAPITimeout = 300 * time.Second

// uploadedFile represents a file that was uploaded and needs to be waited for
type uploadedFile struct {
name string
Expand Down Expand Up @@ -672,7 +675,7 @@ func (e *execution) processImagePartsWithTotalSize(ctx context.Context, client *
}

// Process using File API decision based on total request size
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, 60*time.Second, useFileAPI)
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, FileAPITimeout, useFileAPI)
if err != nil {
return nil, nil, fmt.Errorf("failed to process image: %w", err)
}
Expand Down Expand Up @@ -722,7 +725,7 @@ func (e *execution) processAudioPartsWithTotalSize(ctx context.Context, client *
}

// Process using File API decision based on total request size
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, 60*time.Second, useFileAPI)
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, FileAPITimeout, useFileAPI)
if err != nil {
return nil, nil, fmt.Errorf("failed to process audio: %w", err)
}
Expand Down Expand Up @@ -772,7 +775,7 @@ func (e *execution) processVideoPartsWithTotalSize(ctx context.Context, client *
}

// Use File API based on decision (longer timeout for videos)
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, 120*time.Second, useFileAPI)
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), contentType, 0, FileAPITimeout, useFileAPI)
if err != nil {
return nil, nil, fmt.Errorf("failed to process video: %w", err)
}
Expand Down Expand Up @@ -831,7 +834,7 @@ func (e *execution) processDocumentPartsWithTotalSize(ctx context.Context, clien
}

// Process using File API decision based on total request size
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), "application/pdf", 0, 60*time.Second, useFileAPI)
part, fileName, err := e.processMediaFile(ctx, client, binary.ByteArray(), "application/pdf", 0, FileAPITimeout, useFileAPI)
if err != nil {
return nil, nil, fmt.Errorf("failed to process PDF: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/ai/gemini/v0/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ type TaskTextEmbeddingsInput struct {

// TaskTextEmbeddingsOutput is the output for the TASK_TEXT_EMBEDDINGS task.
type TaskTextEmbeddingsOutput struct {
Embedding []float64 `instill:"embedding"`
Embedding *genai.ContentEmbedding `instill:"embedding"`
}
10 changes: 2 additions & 8 deletions pkg/component/ai/gemini/v0/task_text_embeddings.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@ func (e *execution) textEmbeddings(ctx context.Context, job *base.Job) error {
return nil
}

// Convert from []float32 to []float64 for consistency with other components
embeddingFloat64 := make([]float64, len(embedding.Values))
for i, v := range embedding.Values {
embeddingFloat64[i] = float64(v)
}

// Prepare output
// Prepare output using the genai ContentEmbedding directly
output := TaskTextEmbeddingsOutput{
Embedding: embeddingFloat64,
Embedding: embedding,
}

// Write output
Expand Down
Loading