1package typesafe_test23import (4 "context"5 json "encoding/json/v2"6 "fmt"7 "net/http"8 "net/http/httptest"910 "github.com/FelineStateMachine/typesafe-go"11)1213func ExampleClient_SystemOne() {14 server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {15 writer.Header().Set("Content-Type", "application/json")16 if err := json.MarshalWrite(writer, map[string]any{17 "model": "jev-latest",18 "answers": map[string]any{19 "ready": map[string]any{"type": "noul", "noul": 0.9},20 "kind": map[string]any{"type": "choice", "choice": "stable", "confidence": 0.8, "probabilities": map[string]float64{"stable": 0.8, "beta": 0.2}},21 "score": map[string]any{"type": "score", "score": 1.6, "confidence": 0.7, "legend": map[string]any{"0": "not ready", "1": "review", "2": "ready"}, "probabilities": map[string]float64{"0": 0.1, "1": 0.2, "2": 0.7}},22 },23 "usage": map[string]int{"input_tokens": 12, "output_tokens": 3},24 }); err != nil {25 http.Error(writer, err.Error(), http.StatusInternalServerError)26 }27 }))28 defer server.Close()29 client, err := typesafe.NewClient(30 typesafe.WithAPIKey("test-key"),31 typesafe.WithBaseURL(server.URL),32 )33 if err != nil {34 panic(err)35 }36 response, err := client.SystemOne(context.Background(), typesafe.SystemOneRequest{37 State: map[string]any{"text": "ready"},38 Questions: map[string]typesafe.Question{39 "ready": typesafe.NoulQuestion{Instructions: "Is it ready?", Criteria: &typesafe.NoulCriteria{True: "yes", False: "no"}},40 "kind": typesafe.ChoiceQuestion{Instructions: "Which kind?", Criteria: map[string]any{"stable": "stable", "beta": "beta"}},41 "score": typesafe.ScoreQuestion{Instructions: "How ready?", Criteria: []any{"not ready", "review", "ready"}},42 },43 })44 if err != nil {45 panic(err)46 }47 ready, err := response.Noul("ready")48 if err != nil {49 panic(err)50 }51 kind, err := response.Choice("kind")52 if err != nil {53 panic(err)54 }55 score, err := response.Score("score")56 if err != nil {57 panic(err)58 }59 fmt.Printf("%.1f %s %.1f\n", ready.Noul, kind.Choice, score.Score)60 // Output:61 // 0.9 stable 1.662}