naiprovider

package
v0.0.0-...-36d6306 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL