84 lines
3.3 KiB
Go
84 lines
3.3 KiB
Go
package structuredoutput
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/responseschema"
|
|
)
|
|
|
|
// DiagnosticContext identifies the logical call without examining rendered text.
|
|
type DiagnosticContext struct {
|
|
Role string `json:"role"`
|
|
ModuleKey string `json:"module_key,omitempty"`
|
|
ModuleInstance string `json:"module_instance,omitempty"`
|
|
SectionIndex *int `json:"section_index,omitempty"`
|
|
BatchIndex *int `json:"batch_index,omitempty"`
|
|
ValidatorName string `json:"validator_name,omitempty"`
|
|
}
|
|
|
|
// Request names an embedded prompt and response schema. Profile selection and
|
|
// credentials are supplied by the role-bound runtime client.
|
|
type Request struct {
|
|
PromptID string `json:"prompt_id"`
|
|
PromptVersion string `json:"prompt_version"`
|
|
Variables map[string]string `json:"variables"`
|
|
Schema responseschema.Key `json:"schema"`
|
|
Context DiagnosticContext `json:"context"`
|
|
}
|
|
|
|
// PromptMetadata is the execution snapshot returned by the runtime when available.
|
|
type PromptMetadata struct {
|
|
PromptID string `json:"prompt_id,omitempty"`
|
|
PromptVersion string `json:"prompt_version,omitempty"`
|
|
DefinitionHash string `json:"definition_hash,omitempty"`
|
|
RenderedHash string `json:"rendered_hash,omitempty"`
|
|
ProfileID string `json:"profile_id,omitempty"`
|
|
BackendID string `json:"backend_id,omitempty"`
|
|
Model string `json:"model,omitempty"`
|
|
}
|
|
|
|
type Response struct {
|
|
Execution outcomes.ExecutionCounts `json:"execution"`
|
|
Content json.RawMessage `json:"content,omitempty"`
|
|
Provider string `json:"provider,omitempty"`
|
|
Model string `json:"model,omitempty"`
|
|
PromptTokens int `json:"prompt_tokens,omitempty"`
|
|
CompletionTokens int `json:"completion_tokens,omitempty"`
|
|
TotalTokens int `json:"total_tokens,omitempty"`
|
|
Prompt PromptMetadata `json:"prompt"`
|
|
Prepared *PreparedSnapshot `json:"prepared,omitempty"`
|
|
FinalContent string `json:"final_content,omitempty"`
|
|
}
|
|
|
|
// PreparedSnapshot is the exact rendered request snapshot. Its messages may
|
|
// contain transcript and glossary content and belong only in protected diagnostics.
|
|
type PreparedSnapshot struct {
|
|
Messages []Message `json:"messages"`
|
|
Prompt PromptMetadata `json:"prompt"`
|
|
}
|
|
|
|
type Message struct {
|
|
Role string `json:"role"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
// CallRecord brackets one logical operation, including preparation. Content
|
|
// is present only when a model returned it; consumers must protect it.
|
|
type CallRecord struct {
|
|
CallID uint64 `json:"call_id"`
|
|
Context DiagnosticContext `json:"context"`
|
|
Prompt PromptMetadata `json:"prompt"`
|
|
Started time.Time `json:"started"`
|
|
Finished time.Time `json:"finished,omitempty"`
|
|
Prepared *PreparedSnapshot `json:"prepared,omitempty"`
|
|
FinalContent string `json:"final_content,omitempty"`
|
|
Failure FailureKind `json:"failure,omitempty"`
|
|
}
|
|
|
|
type Client interface {
|
|
CompleteStructured(ctx context.Context, req Request, out any) (Response, error)
|
|
}
|