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

Chore/update completion payload to use map instead of string #14

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all 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
26 changes: 22 additions & 4 deletions pkg/task/task_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func ValidateTaskData(taskData TaskData) error {
for _, taskresponse := range taskData.Responses {
switch task {
case db.TaskTypeTextToImage:
if _, ok := taskresponse.Completion.(string); !ok {
if _, ok := taskresponse.Completion.(map[string]interface{}); !ok {
return fmt.Errorf("invalid completion format: %v", taskresponse.Completion)
}
case db.TaskTypeCodeGeneration:
Expand Down Expand Up @@ -448,7 +448,12 @@ func ValidateTaskData(taskData TaskData) error {
return errors.New("message is required for each message")
}
}
case db.TaskTypeTextToThreeDeez:
if _, ok := taskresponse.Completion.(map[string]interface{}); !ok {
return fmt.Errorf("invalid completion format: %v", taskresponse.Completion)
}
}

}

if len(taskData.Criteria) == 0 {
Expand Down Expand Up @@ -658,17 +663,29 @@ func ProcessFileUpload(requestBody CreateTaskRequest, files []*multipart.FileHea
for i, t := range requestBody.TaskData {
if t.Task == db.TaskTypeTextToImage || t.Task == db.TaskTypeTextToThreeDeez {
for j, response := range t.Responses {
completionMap, ok := response.Completion.(map[string]interface{})
if !ok {
return CreateTaskRequest{}, fmt.Errorf("unexpected type for response.Completion: %T", response.Completion)
}

filename, ok := completionMap["filename"].(string)
if !ok {
log.Error().Msg("Filename not found in completion map or not a string")
return CreateTaskRequest{}, errors.New("filename not found in completion map or not a string")
}

log.Info().Str("filename", filename).Interface("files", files).Msg("Debugging file matching")
var fileHeader *multipart.FileHeader
// Find the file with the matching completion filename
for _, file := range files {
if file.Filename == response.Completion {
if file.Filename == filename {
fileHeader = file
break
}
}

if fileHeader == nil {
log.Error().Interface("response", response.Completion).Msg("Failed to find file header for response")
log.Error().Str("filename", filename).Msg("Failed to find file header for response")
return CreateTaskRequest{}, errors.New("failed to find file header for response")
}

Expand All @@ -684,7 +701,8 @@ func ProcessFileUpload(requestBody CreateTaskRequest, files []*multipart.FileHea
log.Info().Str("fileURL", fileURL).Msg("File URL")

// Update the response completion with the S3 URL
requestBody.TaskData[i].Responses[j].Completion = fileURL
completionMap["url"] = fileURL
requestBody.TaskData[i].Responses[j].Completion = completionMap
}
}
}
Expand Down