82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit"
|
|
)
|
|
|
|
type deterministicClient struct{}
|
|
|
|
func (deterministicClient) Generate(
|
|
ctx context.Context,
|
|
_ promptkit.GenerateRequest,
|
|
) (*promptkit.GenerateResponse, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &promptkit.GenerateResponse{
|
|
Content: "Ada finished the migration review.",
|
|
Usage: promptkit.TokenUsage{
|
|
PromptTokens: 12,
|
|
CompletionTokens: 6,
|
|
TotalTokens: 18,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
type summary struct {
|
|
Output string `json:"output"`
|
|
ValidationStatus promptkit.ValidationStatus `json:"validation_status"`
|
|
IsValid bool `json:"is_valid"`
|
|
Model string `json:"model"`
|
|
TotalTokens int `json:"total_tokens"`
|
|
}
|
|
|
|
func main() {
|
|
engine, err := promptkit.NewEngine(
|
|
promptkit.Config{},
|
|
promptkit.WithPromptFile("examples/go-library/run/prompt.yaml"),
|
|
promptkit.WithProfiles(promptkit.Profile{
|
|
ID: "offline-example",
|
|
Endpoint: "https://example.invalid/v1",
|
|
Model: "offline-model",
|
|
}),
|
|
promptkit.WithLLMClient(deterministicClient{}),
|
|
)
|
|
if err != nil {
|
|
exit(err)
|
|
}
|
|
|
|
result, err := engine.Run(context.Background(), promptkit.RunRequest{
|
|
PromptID: "example.run",
|
|
Inputs: map[string]promptkit.ArtifactRef{
|
|
"note": promptkit.Inline("Ada finished the migration review."),
|
|
},
|
|
})
|
|
if err != nil {
|
|
exit(err)
|
|
}
|
|
|
|
encoder := json.NewEncoder(os.Stdout)
|
|
encoder.SetIndent("", " ")
|
|
if err := encoder.Encode(summary{
|
|
Output: result.RawOutput,
|
|
ValidationStatus: result.Validation.Status,
|
|
IsValid: result.Validation.IsValid,
|
|
Model: result.ModelName,
|
|
TotalTokens: result.Usage.TotalTokens,
|
|
}); err != nil {
|
|
exit(err)
|
|
}
|
|
}
|
|
|
|
func exit(err error) {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|