Skip to content

Commit

Permalink
Allow to index note with images in RAG
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Oct 7, 2024
1 parent 20bbf36 commit 5eb75dc
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions model/rag/index.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package rag

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strings"

"github.com/cozy/cozy-stack/model/instance"
"github.com/cozy/cozy-stack/model/job"
"github.com/cozy/cozy-stack/model/note"
"github.com/cozy/cozy-stack/model/vfs"
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/consts"
Expand Down Expand Up @@ -139,20 +142,40 @@ func callRAGIndexer(inst *instance.Instance, doctype string, change couchdb.Chan
"name": []string{name},
"md5sum": []string{md5sum},
}.Encode()
fs := inst.VFS()
fileDoc := &vfs.FileDoc{
Type: consts.FileType,
DocID: change.DocID,
DirID: dirID,
DocName: name,
InternalID: internalID,
}
// TODO notes with images
content, err := fs.OpenFile(fileDoc)
if err != nil {
return err
var content io.Reader
fmt.Printf("mime = %s\n", mime)

Check failure on line 146 in model/rag/index.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Printf` forbidden by pattern `fmt.Printf` (forbidigo)
if mime == consts.NoteMimeType {
fmt.Printf("NOTE !!")

Check failure on line 148 in model/rag/index.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Printf` forbidden by pattern `fmt.Printf` (forbidigo)
metadata, _ := change.Doc.Get("metadata").(map[string]interface{})
schema, _ := metadata["schema"].(map[string]interface{})
raw, _ := metadata["content"].(map[string]interface{})
noteDoc := &note.Document{
DocID: change.DocID,
SchemaSpec: schema,
RawContent: raw,
}
md, err := noteDoc.Markdown(nil)
fmt.Printf("markdown: %s\n", md)

Check failure on line 158 in model/rag/index.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Printf` forbidden by pattern `fmt.Printf` (forbidigo)
if err != nil {
return err
}
content = bytes.NewReader(md)
} else {
fs := inst.VFS()
fileDoc := &vfs.FileDoc{
Type: consts.FileType,
DocID: change.DocID,
DirID: dirID,
DocName: name,
InternalID: internalID,
}
f, err := fs.OpenFile(fileDoc)
if err != nil {
return err
}
defer f.Close()
content = f
}
defer content.Close()
req, err = http.NewRequest(http.MethodPut, u.String(), content)
if err != nil {
return err
Expand Down

0 comments on commit 5eb75dc

Please sign in to comment.