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

fix: Add image-to-text pipeline to remote worker #3229

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion server/ai_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func parseMultiPartResult(body io.Reader, boundary string, pipeline string) core
break
}
results = parsedResp
case "audio-to-text", "segment-anything-2", "llm":
case "audio-to-text", "segment-anything-2", "llm", "image-to-text":
err := json.Unmarshal(body, &results)
if err != nil {
glog.Error("Error getting results json:", err)
Expand Down
17 changes: 17 additions & 0 deletions server/ai_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@
return n.LLM(ctx, req)
}
reqOk = true
case "image-to-text":
var req worker.GenImageToTextMultipartRequestBody
err = json.Unmarshal(reqData.Request, &req)
if err != nil || req.ModelId == nil {
break

Check warning on line 292 in server/ai_worker.go

View check run for this annotation

Codecov / codecov/patch

server/ai_worker.go#L292

Added line #L292 was not covered by tests
}
input, err = core.DownloadData(ctx, reqData.InputUrl)
if err != nil {
break

Check warning on line 296 in server/ai_worker.go

View check run for this annotation

Codecov / codecov/patch

server/ai_worker.go#L296

Added line #L296 was not covered by tests
}
modelID = *req.ModelId
resultType = "application/json"
req.Image.InitFromBytes(input, "image")
processFn = func(ctx context.Context) (interface{}, error) {
return n.ImageToText(ctx, req)
}
reqOk = true
case "text-to-speech":
var req worker.GenTextToSpeechJSONRequestBody
err = json.Unmarshal(reqData.Request, &req)
Expand Down
19 changes: 19 additions & 0 deletions server/ai_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ func TestRunAIJob(t *testing.T) {
expectedErr: "",
expectedOutputs: 1,
},
{
name: "ImageToText_Success",
notify: createAIJob(8, "image-to-text", modelId, parsedURL.String()+"/image.png"),
pipeline: "image-to-text",
expectedErr: "",
expectedOutputs: 1,
},
{
name: "TextToSpeech_Success",
notify: createAIJob(9, "text-to-speech", modelId, ""),
Expand Down Expand Up @@ -319,6 +326,15 @@ func TestRunAIJob(t *testing.T) {
assert.Equal(len(results.Files), 0)
expectedResp, _ := wkr.LLM(context.Background(), worker.GenLLMFormdataRequestBody{})
assert.Equal(expectedResp, &jsonRes)
case "image-to-text":
res, _ := json.Marshal(results.Results)
var jsonRes worker.ImageToTextResponse
json.Unmarshal(res, &jsonRes)

assert.Equal("8", headers.Get("TaskId"))
assert.Equal(len(results.Files), 0)
expectedResp, _ := wkr.ImageToText(context.Background(), worker.GenImageToTextMultipartRequestBody{})
assert.Equal(expectedResp, &jsonRes)
case "text-to-speech":
audResp, ok := results.Results.(worker.AudioResponse)
assert.True(ok)
Expand Down Expand Up @@ -357,6 +373,9 @@ func createAIJob(taskId int64, pipeline, modelId, inputUrl string) *net.NotifyAI
req = worker.GenSegmentAnything2MultipartRequestBody{ModelId: &modelId, Image: inputFile}
case "llm":
req = worker.GenLLMFormdataRequestBody{Prompt: "tell me a story", ModelId: &modelId}
case "image-to-text":
inputFile.InitFromBytes(nil, inputUrl)
req = worker.GenImageToImageMultipartRequestBody{Prompt: "test prompt", ModelId: &modelId, Image: inputFile}
case "text-to-speech":
desc := "a young adult"
text := "let me tell you a story"
Expand Down
Loading