Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knowledge #241

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions apiclient/types/knowledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ type KnowledgeFile struct {
IngestionStatus IngestionStatus `json:"ingestionStatus,omitempty"`
FileDetails FileDetails `json:"fileDetails,omitempty"`
UploadID string `json:"uploadID,omitempty"`
Approved *bool `json:"approved,omitempty"`
}

type FileDetails struct {
FilePath string `json:"filePath,omitempty"`
URL string `json:"url,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Checksum string `json:"checksum,omitempty"`
Ingested bool `json:"ingested,omitempty"`
}

type IngestionStatus struct {
Expand Down
31 changes: 19 additions & 12 deletions apiclient/types/remoteKnowledgeSource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,24 @@ type RemoteKnowledgeSource struct {

type RemoteKnowledgeSourceManifest struct {
SyncSchedule string `json:"syncSchedule,omitempty"`
AutoApprove *bool `json:"autoApprove,omitempty"`
RemoteKnowledgeSourceInput `json:",inline"`
}

type RemoteKnowledgeSourceList List[RemoteKnowledgeSource]

type RemoteKnowledgeSourceInput struct {
DisableIngestionAfterSync bool `json:"disableIngestionAfterSync,omitempty"`
SourceType RemoteKnowledgeSourceType `json:"sourceType,omitempty"`
Exclude []string `json:"exclude,omitempty"`
OneDriveConfig *OneDriveConfig `json:"onedriveConfig,omitempty"`
NotionConfig *NotionConfig `json:"notionConfig,omitempty"`
WebsiteCrawlingConfig *WebsiteCrawlingConfig `json:"websiteCrawlingConfig,omitempty"`
SourceType RemoteKnowledgeSourceType `json:"sourceType,omitempty"`
OneDriveConfig *OneDriveConfig `json:"onedriveConfig,omitempty"`
NotionConfig *NotionConfig `json:"notionConfig,omitempty"`
WebsiteCrawlingConfig *WebsiteCrawlingConfig `json:"websiteCrawlingConfig,omitempty"`
}

type OneDriveConfig struct {
SharedLinks []string `json:"sharedLinks,omitempty"`
}

type NotionConfig struct {
Pages []string `json:"pages,omitempty"`
}
type NotionConfig struct{}

type WebsiteCrawlingConfig struct {
URLs []string `json:"urls,omitempty"`
Expand All @@ -56,6 +53,12 @@ type RemoteKnowledgeSourceState struct {
type OneDriveLinksConnectorState struct {
Folders FolderSet `json:"folders,omitempty"`
Files map[string]FileState `json:"files,omitempty"`
Links map[string]LinkState `json:"links,omitempty"`
}

type LinkState struct {
IsFolder bool `json:"isFolder,omitempty"`
Name string `json:"name,omitempty"`
}

type FileState struct {
Expand All @@ -75,7 +78,11 @@ type NotionPage struct {
}

type WebsiteCrawlingConnectorState struct {
ScrapeJobIds map[string]string `json:"scrapeJobIds"`
Folders FolderSet `json:"folders"`
Pages map[string]Item `json:"pages"`
ScrapeJobIds map[string]string `json:"scrapeJobIds"`
Folders FolderSet `json:"folders"`
Pages map[string]PageDetails `json:"pages"`
}

type PageDetails struct {
ParentURL string `json:"parentUrl"`
}
61 changes: 49 additions & 12 deletions apiclient/types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ func (a *AgentHandler) UploadKnowledge(req api.Context) error {
return uploadKnowledge(req, a.gptscript, agent.Status.KnowledgeSetNames...)
}

func (a *AgentHandler) ApproveKnowledgeFile(req api.Context) error {
var body struct {
Approve bool `json:"approve"`
}

if err := req.Read(&body); err != nil {
return err
}
var file v1.KnowledgeFile
if err := req.Storage.Get(req.Context(), kclient.ObjectKey{
Namespace: req.Namespace(),
Name: req.PathValue("file_id"),
}, &file); err != nil {
return err
}

if file.Spec.Approved == nil || *file.Spec.Approved != body.Approve {
file.Spec.Approved = &body.Approve
return req.Storage.Update(req.Context(), &file)
}
return nil
}

func (a *AgentHandler) DeleteKnowledge(req api.Context) error {
var agent v1.Agent
if err := req.Get(&agent, req.PathValue("id")); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/handlers/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func uploadKnowledgeToWorkspace(req api.Context, gClient *gptscript.GPTScript, w
Spec: v1.KnowledgeFileSpec{
FileName: filename,
WorkspaceName: ws.Name,
Approved: &[]bool{true}[0],
},
}

Expand All @@ -134,6 +135,7 @@ func convertKnowledgeFile(file v1.KnowledgeFile, ws v1.Workspace) types.Knowledg
RemoteKnowledgeSourceID: file.Spec.RemoteKnowledgeSourceName,
RemoteKnowledgeSourceType: file.Spec.RemoteKnowledgeSourceType,
UploadID: file.Status.UploadID,
Approved: file.Spec.Approved,
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/api/handlers/remoteknowledgesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ func checkConfigChanged(input types.RemoteKnowledgeSourceInput, remoteKnowledgeS
return !equality.Semantic.DeepEqual(*input.OneDriveConfig, *remoteKnowledgeSource.Spec.Manifest.OneDriveConfig)
}

if input.NotionConfig != nil && remoteKnowledgeSource.Spec.Manifest.NotionConfig != nil {
return !equality.Semantic.DeepEqual(*input.NotionConfig, *remoteKnowledgeSource.Spec.Manifest.NotionConfig)
if remoteKnowledgeSource.Spec.Manifest.SourceType == types.RemoteKnowledgeSourceTypeNotion {
// we never resync notion on update, this is because by default we sync every page that it has access to
return false
}

if input.WebsiteCrawlingConfig != nil && remoteKnowledgeSource.Spec.Manifest.WebsiteCrawlingConfig != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Router(services *services.Services) (http.Handler, error) {
// Agent knowledge files
mux.HandleFunc("GET /api/agents/{id}/knowledge", agents.Knowledge)
mux.HandleFunc("POST /api/agents/{id}/knowledge/{file}", agents.UploadKnowledge)
mux.HandleFunc("PUT /api/agents/{id}/knowledge/{file_id}/approve", agents.ApproveKnowledgeFile)
mux.HandleFunc("DELETE /api/agents/{id}/knowledge/{file...}", agents.DeleteKnowledge)

mux.HandleFunc("POST /api/agents/{agent_id}/remote-knowledge-sources", agents.CreateRemoteKnowledgeSource)
Expand Down
Loading