General-purpose string-to-string AI transformation — apply any natural-language instruction to a string input.
| Field | Type | Description |
|---|---|---|
Input |
*string |
Input string to transform |
| Field | Type | Description |
|---|---|---|
Result |
string |
Transformed string output |
Reasoning is captured by WithReasoningLog — no graph output needed.
| Key | Type | Default | Description |
|---|---|---|---|
operation |
string |
required | Full natural-language instruction for the transformation |
max_retries |
string |
"3" | Number of retries on error |
Most flexible AI op. When the output type is a known structured value, prefer a more specific op: AIBoolOp for yes/no, AIScoreOp for 0–1 scores, AIExtractStringSliceOp for lists. Use this op when the output is free-form text.
Translates an English business sentence to Spanish using a plain-language operation instruction.
package main
import (
"context"
"encoding/json"
"log"
"os"
"time"
"github.com/akennis/sparsi-go/library"
_ "github.com/akennis/dagor/operator/builtin"
"github.com/panjf2000/ants/v2"
"github.com/akennis/dagor"
"github.com/akennis/dagor/graph"
)
func main() {
input := "The quarterly revenue exceeded expectations by a significant margin."
library.RegisterConst("input_val", input)
g, err := graph.NewBuilder("translate_demo").
Vertex("src").Op("input_val").
Output("Result", "input_wire").
Vertex("translate").Op("AIComputeStringToStringOp").
Params(map[string]string{
"operation": "translate this text to Spanish, preserving a professional tone",
}).
Input("Input", "input_wire").
Output("Result", "translated").
Build()
if err != nil {
log.Fatalf("build: %v", err)
}
pool, err := ants.NewPool(4)
if err != nil {
log.Fatalf("pool: %v", err)
}
defer pool.Release()
eng, err := dagor.NewEngine(g, pool)
if err != nil {
log.Fatalf("engine: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := eng.Run(ctx); err != nil {
log.Fatalf("run: %v", err)
}
out := map[string]any{}
if raw, ok := eng.GetOutput("translated"); ok {
out["result"] = *raw.(*string)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(out)
}