Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/ai/background_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ type ModelOperation = core.Operation[*ModelResponse]
// StartModelOpFunc starts a background model operation.
type StartModelOpFunc = func(ctx context.Context, req *ModelRequest) (*ModelOperation, error)

// CheckOperationFunc checks the status of a background model operation.
// CheckModelOpFunc checks the status of a background model operation.
type CheckModelOpFunc = func(ctx context.Context, op *ModelOperation) (*ModelOperation, error)

// CancelOperationFunc cancels a background model operation.
// CancelModelOpFunc cancels a background model operation.
type CancelModelOpFunc = func(ctx context.Context, op *ModelOperation) (*ModelOperation, error)

// BackgroundModelOptions holds configuration for defining a background model
Expand Down
6 changes: 3 additions & 3 deletions go/ai/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ type MultipartToolResponse struct {
// Operation represents a long-running background task.
type Operation struct {
// Action is the name of the action being performed by this operation.
Action string `json:"action,omitempty"`
Action string `json:"action"`
// Done indicates whether the operation has completed.
Done bool `json:"done,omitempty"`
Done bool `json:"done"`
// Error contains error information if the operation failed.
Error *OperationError `json:"error,omitempty"`
// Id is the unique identifier for this operation.
Id string `json:"id,omitempty"`
Id string `json:"id"`
// Metadata contains additional information about the operation.
Metadata map[string]any `json:"metadata,omitempty"`
// Output contains the result of the operation if it has completed successfully.
Expand Down
6 changes: 4 additions & 2 deletions go/ai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func GenerateWithRequest(ctx context.Context, r api.Registry, opts *GenerateActi
// Native constrained output is enabled only when the user has
// requested it, the model supports it, and there's a JSON schema.
outputCfg.Constrained = opts.Output.JsonSchema != nil &&
opts.Output.Constrained && outputCfg.Constrained && m.(*model).supportsConstrained(len(toolDefs) > 0)
opts.Output.Constrained && outputCfg.Constrained && m != nil && m.(*model).supportsConstrained(len(toolDefs) > 0)

// Add schema instructions to prompt when not using native constraints.
// This is a no-op for unstructured output requests.
Expand Down Expand Up @@ -313,12 +313,14 @@ func GenerateWithRequest(ctx context.Context, r api.Registry, opts *GenerateActi
Output: &outputCfg,
}

fn := m.Generate
var fn ModelFunc
if bm != nil {
if cb != nil {
logger.FromContext(ctx).Warn("background model does not support streaming", "model", bm.Name())
}
fn = backgroundModelToModelFn(bm.Start)
} else {
fn = m.Generate
}
fn = core.ChainMiddleware(mw...)(fn)

Expand Down
12 changes: 6 additions & 6 deletions go/core/background_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ type CancelOpFunc[Out any] = func(ctx context.Context, op *Operation[Out]) (*Ope

// Operation represents a long-running operation started by a background action.
type Operation[Out any] struct {
Action string // Key of the action that created this operation.
ID string // ID of the operation.
Done bool // Whether the operation is complete.
Output Out // Result when done.
Error error // Error if the operation failed.
Metadata map[string]any // Additional metadata.
Action string `json:"action"` // Key of the action that created this operation.
ID string `json:"id"` // ID of the operation.
Done bool `json:"done"` // Whether the operation is complete.
Output Out `json:"output,omitempty"` // Result when done.
Error error `json:"error,omitempty"` // Error if the operation failed.
Metadata map[string]any `json:"metadata,omitempty"` // Additional metadata.
}

// BackgroundActionDef is a background action that can be used to start, check, and cancel background operations.
Expand Down
5 changes: 5 additions & 0 deletions go/internal/cmd/jsonschemagen/jsonschemagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ var (
"ModelResponseChunk": {
"index": {}, // fields should be as defined in core/schemas.config
},
"Operation": {
"action": {},
"done": {},
"id": {},
},
}
)

Expand Down
2 changes: 1 addition & 1 deletion go/internal/cmd/jsonschemagen/testdata/golden
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ type Message struct {
type Operation struct {
BlockedOnStep *OperationBlockedOnStep `json:"blockedOnStep,omitempty"`
// If the value is false, it means the operation is still in progress. If true, the operation is completed, and either error or response is available.
Done bool `json:"done,omitempty"`
Done bool `json:"done"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Operation type is no longer used in the codebase and it was colliding with ai.Operation Done field.

// Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time.
Metadata any `json:"metadata,omitempty"`
// server-assigned name, which is only unique within the same service that originally returns it.
Expand Down
Loading
Loading