You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: result-formatter/main.go
+64-25
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,9 @@ import (
4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+
"log/slog"
8
+
neturl "net/url"
7
9
"os"
8
-
"strconv"
9
10
"strings"
10
11
"sync"
11
12
@@ -22,14 +23,27 @@ type subqueryResults struct {
22
23
}
23
24
24
25
typedocumentstruct {
25
-
IDstring`json:"id"`
26
-
Contentstring`json:"content,omitempty"`
27
-
Metadatamap[string]any`json:"metadata,omitempty"`
26
+
IDstring`json:"id"`
27
+
Contentstring`json:"content,omitempty"`
28
+
Metadatametadata`json:"metadata,omitempty"`
29
+
}
30
+
31
+
typemetadatastruct {
32
+
Sourcestring`json:"source,omitempty"`
33
+
WorkspaceIDstring`json:"workspaceID,omitempty"`
34
+
URLstring`json:"url,omitempty"`
35
+
Pagesstring`json:"pages,omitempty"`
36
+
Pageint`json:"page,omitempty"`
37
+
TotalPagesint`json:"totalPages,omitempty"`
38
+
FileSizeint`json:"fileSize,omitempty"`
39
+
WorkspaceFileNamestring`json:"workspaceFileName,omitempty"`// workspaceFileName is the location of the converted file, not the original file - e.g. <path>/foo.pdf.json
40
+
DatasetIDstring`json:"datasetID,omitempty"`
28
41
}
29
42
30
43
typehitstruct {
31
-
URLstring`json:"url,omitempty"`
32
-
Contentstring`json:"content,omitempty"`
44
+
URLstring`json:"url,omitempty"`// URL should be the original source of the document (Web URL, OneDrive Link, etc.)
45
+
Locationstring`json:"location,omitempty"`// Location should be the location of the result in the original source (page numbers, etc.)
46
+
Contentstring`json:"content,omitempty"`// Content should be the text content of the document
33
47
}
34
48
35
49
typeinputContentstruct {
@@ -44,22 +58,22 @@ func main() {
44
58
ctx=context.Background()
45
59
)
46
60
47
-
// This is ugly code, I know. Beauty comes later.
61
+
// This is ugly code, I know. Beauty comes later. Cleaned up a little. Still room for improvement.
48
62
49
63
ifclientErr!=nil {
50
-
_, _=fmt.Fprintf(os.Stderr, "failed to create gptscript client: %v\n", clientErr)
64
+
slog.Error("failed to create gptscript client", "error", clientErr)
location=fmt.Sprintf("%s of %d", location, doc.Metadata.TotalPages)
98
+
slog.Debug("result doc in file", "filename", filename, "location", location)
99
+
}
100
+
101
+
ifffi, ok:=fullyFetched[filename]; ok {
102
+
iflocation!="" {
103
+
outDocs[ffi].Location+=" and "+location
104
+
}
73
105
continue
74
106
}
75
107
76
-
url, _:=doc.Metadata["url"].(string)
108
+
varurlstring
109
+
ifdoc.Metadata.URL!="" {
110
+
url=doc.Metadata.URL
111
+
} elseifdoc.Metadata.Source!="" {
112
+
url="knowledge://"+neturl.PathEscape(doc.Metadata.DatasetID+"::"+strings.TrimPrefix(doc.Metadata.Source, "ws://")) // <datasetID>::<workspaceFileName>, where datasetID is <namespace>/<knowledgeset>
0 commit comments