- Updated the Vision function and associated handlers to accept a forceUses parameter, allowing explicit control over the use of external tools regardless of model capabilities. - Modified the Assistant's BuildContent method to set the AssistantID in the context for better file tracking. - Enhanced the applyCreateResponseOptions method to merge and prioritize Uses and ForceUses configurations from the createResponse. - Added comprehensive tests to validate the adjustment of Uses and ForceUses configurations through hooks, ensuring correct application in content processing.
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package content
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/yaoapp/gou/connector/openai"
|
|
agentContext "github.com/yaoapp/yao/agent/context"
|
|
)
|
|
|
|
// PDFHandler handles PDF documents
|
|
type PDFHandler struct{}
|
|
|
|
// CanHandle checks if this handler can handle the content type
|
|
func (h *PDFHandler) CanHandle(contentType string, fileType FileType) bool {
|
|
return fileType == FileTypePDF ||
|
|
contentType == "application/pdf" ||
|
|
strings.Contains(contentType, "pdf")
|
|
}
|
|
|
|
// Handle processes PDF content
|
|
// Logic:
|
|
// 1. Check if uses.Vision is specified and supports PDF
|
|
// 2. If yes, use vision tool to handle PDF (images + text)
|
|
// 3. If no, extract text directly from PDF
|
|
func (h *PDFHandler) Handle(ctx *agentContext.Context, info *Info, capabilities *openai.Capabilities, uses *agentContext.Uses, forceUses bool) (*Result, error) {
|
|
// TODO: Implement PDF handling
|
|
// 1. Check if vision tool supports PDF
|
|
// 2. If yes:
|
|
// - Call vision tool to handle PDF (handles both text and images)
|
|
// 3. If no:
|
|
// - Extract text from PDF using default library
|
|
// 4. Return Result with extracted text
|
|
return nil, fmt.Errorf("not implemented")
|
|
}
|
|
|
|
// extractPDFText extracts text content from PDF
|
|
func extractPDFText(data []byte) (string, error) {
|
|
// TODO: Implement PDF text extraction
|
|
// Use a PDF library to extract text
|
|
// Consider preserving layout/structure
|
|
return "", fmt.Errorf("not implemented")
|
|
}
|
|
|
|
// handleWithVisionTool processes PDF using vision tool (for PDFs with images)
|
|
func handleWithVisionTool(ctx *agentContext.Context, data []byte, visionTool string) (string, error) {
|
|
// TODO: Implement vision tool PDF processing
|
|
// Some vision tools can handle PDF directly and extract both text and images
|
|
return "", fmt.Errorf("not implemented")
|
|
}
|