Documentation
¶
Overview ¶
Package naiprovider provides the AI Provider node implementation for flow execution.
Package naiprovider provides the AI Provider node implementation for flow execution. AI Provider nodes are active LLM executors that make LLM calls and track metrics. They are orchestrated by NodeAI nodes via HandleAiProvider edges.
Index ¶
- func ExtractFinishReason(resp *llms.ContentResponse) string
- func ExtractTextContent(resp *llms.ContentResponse) string
- func ExtractTokensFromResponse(resp *llms.ContentResponse) (prompt, completion int32)
- func ExtractToolCalls(resp *llms.ContentResponse) []llms.ToolCall
- type NodeAiProvider
- func (n *NodeAiProvider) Execute(ctx context.Context, req *node.FlowNodeRequest, input nai.AIProviderInput) (*mflow.AIProviderOutput, error)
- func (n *NodeAiProvider) GetID() idwrap.IDWrap
- func (n *NodeAiProvider) GetModelString() string
- func (n *NodeAiProvider) GetName() string
- func (n *NodeAiProvider) GetOutputVariables() []string
- func (n *NodeAiProvider) GetProviderString() string
- func (n *NodeAiProvider) GetRequiredVariables() []string
- func (n *NodeAiProvider) RunAsync(ctx context.Context, req *node.FlowNodeRequest, ...)
- func (n *NodeAiProvider) RunSync(ctx context.Context, req *node.FlowNodeRequest) node.FlowNodeResult
- func (n *NodeAiProvider) SetLLM(llm any)
- func (n *NodeAiProvider) SetProviderFactory(factory *scredential.LLMProviderFactory)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFinishReason ¶
func ExtractFinishReason(resp *llms.ContentResponse) string
ExtractFinishReason extracts the stop/finish reason from an LLM response. Common values: "stop" (OpenAI), "end_turn" (Anthropic), "tool_calls"/"tool_use"
func ExtractTextContent ¶
func ExtractTextContent(resp *llms.ContentResponse) string
ExtractTextContent extracts the text content from an LLM response. Handles multiple choices by aggregating text from all choices with content.
func ExtractTokensFromResponse ¶
func ExtractTokensFromResponse(resp *llms.ContentResponse) (prompt, completion int32)
ExtractTokensFromResponse extracts token usage from a LangChainGo response. Different providers return usage information in GenerationInfo map: - OpenAI: Uses PromptTokens, CompletionTokens - Anthropic: Uses InputTokens, OutputTokens Returns (promptTokens, completionTokens).
func ExtractToolCalls ¶
func ExtractToolCalls(resp *llms.ContentResponse) []llms.ToolCall
ExtractToolCalls extracts tool calls from an LLM response. Aggregates tool calls from all choices since some providers split them.
Types ¶
type NodeAiProvider ¶
type NodeAiProvider struct {
FlowNodeID idwrap.IDWrap
Name string
CredentialID *idwrap.IDWrap // Optional: nil means no credential set yet
Model mflow.AiModel
Temperature *float32 // Optional: nil means use provider default
MaxTokens *int32 // Optional: nil means use provider default
// Runtime dependencies
ProviderFactory *scredential.LLMProviderFactory
// LLM allows injecting a mock model for testing
LLM llms.Model
}
NodeAiProvider represents an AI Provider node that executes LLM calls. It is an active node that makes LLM API calls and returns results with metrics. The orchestrator (NodeAI) calls Execute() with typed input and receives typed output.
func New ¶
func New( id idwrap.IDWrap, name string, credentialID *idwrap.IDWrap, model mflow.AiModel, temperature *float32, maxTokens *int32, ) *NodeAiProvider
New creates a new NodeAiProvider with the given configuration.
func (*NodeAiProvider) Execute ¶
func (n *NodeAiProvider) Execute(ctx context.Context, req *node.FlowNodeRequest, input nai.AIProviderInput) (*mflow.AIProviderOutput, error)
Execute runs the LLM with typed input and returns typed output. This is the primary method for orchestrator-to-provider communication, maintaining type safety for messages and tool calls.
func (*NodeAiProvider) GetID ¶
func (n *NodeAiProvider) GetID() idwrap.IDWrap
GetID returns the node's unique identifier.
func (*NodeAiProvider) GetModelString ¶
func (n *NodeAiProvider) GetModelString() string
GetModelString returns the model identifier string (e.g., "gpt-5.2"). Implements the AIProvider interface from nai package.
func (*NodeAiProvider) GetName ¶
func (n *NodeAiProvider) GetName() string
GetName returns the node's display name.
func (*NodeAiProvider) GetOutputVariables ¶
func (n *NodeAiProvider) GetOutputVariables() []string
GetOutputVariables implements node.VariableIntrospector. Returns the output paths this AI Provider node produces.
func (*NodeAiProvider) GetProviderString ¶
func (n *NodeAiProvider) GetProviderString() string
GetProviderString returns the provider name (e.g., "openai", "anthropic"). Implements the AIProvider interface from nai package.
func (*NodeAiProvider) GetRequiredVariables ¶
func (n *NodeAiProvider) GetRequiredVariables() []string
GetRequiredVariables implements node.VariableIntrospector. Returns variables referenced in node configuration (none for AI Provider).
func (*NodeAiProvider) RunAsync ¶
func (n *NodeAiProvider) RunAsync(ctx context.Context, req *node.FlowNodeRequest, resultChan chan node.FlowNodeResult)
RunAsync runs the node asynchronously by calling RunSync and sending the result.
func (*NodeAiProvider) RunSync ¶
func (n *NodeAiProvider) RunSync(ctx context.Context, req *node.FlowNodeRequest) node.FlowNodeResult
RunSync is part of the FlowNode interface but should not be used for AI Provider nodes. The orchestrator (NodeAI) should call Execute() directly with typed input. This method exists only for interface compliance and will error if called.
func (*NodeAiProvider) SetLLM ¶
func (n *NodeAiProvider) SetLLM(llm any)
SetLLM sets a mock LLM model for testing purposes. Implements the AIProvider interface.
func (*NodeAiProvider) SetProviderFactory ¶
func (n *NodeAiProvider) SetProviderFactory(factory *scredential.LLMProviderFactory)
SetProviderFactory sets the LLM provider factory on this node. Implements the AIProvider interface.