Skip to content

Commit

Permalink
ai/worker: Update package with what was in go.mod (c19289d)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Jan 9, 2025
1 parent aa2ac5c commit 0189345
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 122 deletions.
1 change: 0 additions & 1 deletion ai/worker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var pipelineToImage = map[string]string{
"segment-anything-2": "livepeer/ai-runner:segment-anything-2",
"text-to-speech": "livepeer/ai-runner:text-to-speech",
"audio-to-text": "livepeer/ai-runner:audio-to-text",
"llm": "livepeer/ai-runner:llm",
}

var livePipelineToImage = map[string]string{
Expand Down
50 changes: 50 additions & 0 deletions ai/worker/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,56 @@ func NewAudioToTextMultipartWriter(w io.Writer, req GenAudioToTextMultipartReque
return mw, nil
}

func NewLLMMultipartWriter(w io.Writer, req BodyGenLLM) (*multipart.Writer, error) {
mw := multipart.NewWriter(w)

if err := mw.WriteField("prompt", req.Prompt); err != nil {
return nil, fmt.Errorf("failed to write prompt field: %w", err)
}

if req.History != nil {
if err := mw.WriteField("history", *req.History); err != nil {
return nil, fmt.Errorf("failed to write history field: %w", err)
}
}

if req.ModelId != nil {
if err := mw.WriteField("model_id", *req.ModelId); err != nil {
return nil, fmt.Errorf("failed to write model_id field: %w", err)
}
}

if req.SystemMsg != nil {
if err := mw.WriteField("system_msg", *req.SystemMsg); err != nil {
return nil, fmt.Errorf("failed to write system_msg field: %w", err)
}
}

if req.Temperature != nil {
if err := mw.WriteField("temperature", fmt.Sprintf("%f", *req.Temperature)); err != nil {
return nil, fmt.Errorf("failed to write temperature field: %w", err)
}
}

if req.MaxTokens != nil {
if err := mw.WriteField("max_tokens", strconv.Itoa(*req.MaxTokens)); err != nil {
return nil, fmt.Errorf("failed to write max_tokens field: %w", err)
}
}

if req.Stream != nil {
if err := mw.WriteField("stream", fmt.Sprintf("%v", *req.Stream)); err != nil {
return nil, fmt.Errorf("failed to write stream field: %w", err)
}
}

if err := mw.Close(); err != nil {
return nil, fmt.Errorf("failed to close multipart writer: %w", err)
}

return mw, nil
}

func NewSegmentAnything2MultipartWriter(w io.Writer, req GenSegmentAnything2MultipartRequestBody) (*multipart.Writer, error) {
mw := multipart.NewWriter(w)
writer, err := mw.CreateFormFile("image", req.Image.Filename())
Expand Down
Loading

0 comments on commit 0189345

Please sign in to comment.