package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/option"
"go.opentelemetry.io/otel"
openaiotel "github.com/Arize-ai/openinference/go/openinference-instrumentation-openai-go"
)
func main() {
ctx := context.Background()
tp, _ := initTracer(ctx)
defer tp.Shutdown(ctx)
client := openai.NewClient(
option.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
option.WithMiddleware(openaiotel.Middleware(otel.Tracer("openai-go-app"))),
)
decision, err := client.Decisions.New(ctx, openai.DecisionNewParams{
Model: "gpt-6-luna",
Input: openai.DecisionNewParamsInputUnion{
OfString: openai.String("I was charged twice for my order."),
},
Questions: []openai.DecisionNewParamsQuestionUnion{
{OfPredicate: &openai.DecisionNewParamsQuestionPredicate{
Name: openai.String("is_refund"),
Instructions: "Is this a refund request?",
}},
{OfChoice: &openai.DecisionNewParamsQuestionChoice{
Name: openai.String("department"),
Instructions: "Which department should handle this complaint?",
Choices: []openai.DecisionNewParamsQuestionChoiceChoice{
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("billing")},
Description: openai.String("Payments, invoices, and refunds."),
},
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("technical")},
Description: openai.String("Problems using the product."),
},
{
Value: openai.DecisionNewParamsQuestionChoiceChoiceValueUnion{OfString: openai.String("shipping")},
Description: openai.String("Delivery and tracking."),
},
},
}},
{OfScore: &openai.DecisionNewParamsQuestionScore{
Name: openai.String("urgency"),
Instructions: "How urgent is this message?",
Levels: []openai.DecisionNewParamsQuestionScoreLevel{
{Label: "low", Description: openai.String("Can wait a week.")},
{Label: "medium"},
{Label: "high", Description: openai.String("Needs a reply today.")},
},
}},
},
})
if err != nil {
fmt.Println("openai:", err)
return
}
for _, answer := range decision.Answers {
fmt.Println(answer.RawJSON())
}
}