Skip to content
Open
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
12 changes: 11 additions & 1 deletion go/ai/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ai

import (
"context"
"encoding/json"
"errors"
"fmt"
"log/slog"
Expand Down Expand Up @@ -244,7 +245,16 @@ func buildVariables(variables any) (map[string]any, error) {

v := reflect.Indirect(reflect.ValueOf(variables))
if v.Kind() == reflect.Map {
return variables.(map[string]any), nil
// ensure JSON tags are taken in consideration (allowing snake case fields)
jsonData, err := json.Marshal(variables)
if err != nil {
return nil, fmt.Errorf("unable to marshal prompt field values: %w", err)
}
var resultVariables map[string]any
if err := json.Unmarshal(jsonData, &resultVariables); err != nil {
return nil, fmt.Errorf("unable to unmarshal prompt field values: %w", err)
}
return resultVariables, nil
}
if v.Kind() != reflect.Struct {
return nil, errors.New("prompt.buildVariables: fields not a struct or pointer to a struct or a map")
Expand Down
Loading