@@ -411,27 +411,35 @@ func viewDocumentPageTool(args, user, convID string) providers.ToolOutput {
411411 return providers.ToolOutput {Content : fmt .Sprintf ("error decoding arguments: %v" , err )}
412412 }
413413
414- docs := files .GetAllConversationAttachments (convID )
415- doc := findAttachment (docs , params .FileID )
416- if doc == nil {
417- return providers.ToolOutput {Content : fmt .Sprintf ("Unable to find document with id %s in this conversation" , params .FileID )}
414+ // docs := files.GetAllConversationAttachments(convID)
415+ // doc := findAttachment(docs, params.FileID)
416+ // if doc == nil {
417+ // return providers.ToolOutput{Content: fmt.Sprintf("Unable to find document with id %s in this conversation", params.FileID)}
418+ // }
419+
420+ docs , err := files .GetByIDs ([]string {params .FileID }, user )
421+ if err != nil {
422+ return providers.ToolOutput {Content : fmt .Sprintf ("error finding document: %v" , err )}
423+ }
424+ if len (docs ) == 0 {
425+ return providers.ToolOutput {Content : fmt .Sprintf ("Unable to find document with id %s" , params .FileID )}
418426 }
419427
420- imgData , err := fs .RenderPDFPageAsImage ( doc . File .Path , params .PageNumber , user )
428+ imgData , err := fs .RenderDocPageAsImage ( docs [ 0 ] .Path , params .PageNumber , user )
421429 if err != nil {
422430 return providers.ToolOutput {Content : fmt .Sprintf ("error rendering document page: %v" , err )}
423431 }
424432
425- return providers.ToolOutput {File : imgData .ID , Content : fmt .Sprintf ("Rendered page %d of document %s as image" , params .PageNumber , doc . File .Name )}
433+ return providers.ToolOutput {File : imgData .ID , Content : fmt .Sprintf ("Rendered page %d of document %s as image" , params .PageNumber , docs [ 0 ] .Name )}
426434}
427435
428- func findAttachment (m map [int ][]fs.Attachment , targetID string ) * fs.Attachment {
429- for _ , attachments := range m {
430- for _ , att := range attachments {
431- if att .File .ID == targetID {
432- return & att
433- }
434- }
435- }
436- return nil
437- }
436+ // func findAttachment(m map[int][]fs.Attachment, targetID string) *fs.Attachment {
437+ // for _, attachments := range m {
438+ // for _, att := range attachments {
439+ // if att.File.ID == targetID {
440+ // return &att
441+ // }
442+ // }
443+ // }
444+ // return nil
445+ // }
0 commit comments