From 9e637f92bd99492d233a8f227a430d735938e09f Mon Sep 17 00:00:00 2001 From: narawat Date: Fri, 7 Aug 2026 14:07:40 +0700 Subject: [PATCH] update --- src/type.jl | 61 +++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/type.jl b/src/type.jl index 0da023f..e659ca1 100644 --- a/src/type.jl +++ b/src/type.jl @@ -8,11 +8,36 @@ using GeneralUtils const Timestamp = DateTime -struct Usage +# ------------------------------------------------------------------------------------------------ # +# LLM model info # +# ------------------------------------------------------------------------------------------------ # + +struct modelCost # Model pricing per 1M tokens + input::Float64 # Price per 1M input tokens + output::Float64 # Price per 1M output tokens + cache_read::Float64 # Price per 1M cached read tokens + cache_write::Float64 # Price per 1M cache write tokens +end + +struct llmModel # LLM model configuration + id::String # Unique model identifier + name::String # Human-readable model name + api::Api # API type (parametric type) + provider::String # Provider name (e.g., "anthropic", "openai") + baseUrl::String # API endpoint base URL + reasoning::Bool # Whether the model supports chain-of-thought + input::Vector{String} # Supported input modalities (e.g., "text", "image") + cost::modelCost # Pricing information + contextWindow::Int64 # Maximum context length in tokens + maxTokens::Int64 # Maximum output tokens per completion +end + +struct llmUsage inputTokens::Int64 outputTokens::Int64 end + # ------------------------------------------------------------------------------------------------ # # Message content types # # ------------------------------------------------------------------------------------------------ # @@ -67,7 +92,7 @@ struct assistantMessage <: agentMessage # Message from the AI assistant api::String # API name used (e.g., "openai") provider::String # Provider name (e.g., "anthropic") model::String # Model identifier - usage::Usage # Token usage for this message + usage::llmUsage # Token usage for this message stopReason::String # Why generation stopped (e.g., "end_turn") errorMessage::Union{String, Nothing} # Error if generation failed timestamp::Timestamp # When the message was received @@ -82,7 +107,7 @@ Create a new assistant message. - `api::String`: API name used (e.g., "openai") - `provider::String`: Provider name (e.g., "anthropic") - `model::String`: Model identifier -- `usage::Usage`: Token usage for this message +- `usage::llmUsage`: Token usage for this message - `stopReason::String`: Why generation stopped (e.g., "end_turn") - `errorMessage::Union{String, Nothing}`: Error if generation failed - `timestamp::Timestamp`: When the message was received @@ -97,7 +122,7 @@ assistantMessage("assistant", [textContent("Hello!")], "", "", "gpt-4", ..., "en ``` """ function assistantMessage(; role="assistant", content=Vector{messageContent}(), - api="", provider="", model="", usage=Usage(0, 0), stopReason="end_turn", + api="", provider="", model="", usage=llmUsage(0, 0), stopReason="end_turn", errorMessage=nothing, timestamp=now()) return assistantMessage(role, content, api, provider, model, usage, stopReason, errorMessage, timestamp) end @@ -108,7 +133,7 @@ struct toolResultMessage <: agentMessage # Result returned from a tool execut toolName::String # Name of the executed tool content::Vector{messageContent} # Tool output content details::Any # Additional tool-specific details - usage::Union{Usage, Nothing} # Token usage if applicable + usage::Union{llmUsage, Nothing} # Token usage if applicable addedToolNames::Union{Vector{String}, Nothing} # Tools added during execution isError::Bool # Whether the tool call resulted in an error timestamp::Timestamp # When the result was recorded @@ -123,7 +148,7 @@ Create a new tool result message. - `toolName::String`: Name of the executed tool - `content::Vector{messageContent}`: Tool output content - `details::Any`: Additional tool-specific details -- `usage::Union{Usage, Nothing}`: Token usage if applicable +- `usage::Union{llmUsage, Nothing}`: Token usage if applicable - `addedToolNames::Union{Vector{String}, Nothing}`: Tools added during execution - `isError::Bool`: Whether the tool call resulted in an error - `timestamp::Timestamp`: When the result was recorded @@ -279,26 +304,6 @@ struct prepareNextTurnContext # Context for preparing the end -struct modelCost # Model pricing per 1M tokens - input::Float64 # Price per 1M input tokens - output::Float64 # Price per 1M output tokens - cache_read::Float64 # Price per 1M cached read tokens - cache_write::Float64 # Price per 1M cache write tokens -end - -struct llmModel{Api} # LLM model configuration - id::String # Unique model identifier - name::String # Human-readable model name - api::Api # API type (parametric type) - provider::String # Provider name (e.g., "anthropic", "openai") - baseUrl::String # API endpoint base URL - reasoning::Bool # Whether the model supports chain-of-thought - input::Vector{String} # Supported input modalities (e.g., "text", "image") - cost::modelCost # Pricing information - contextWindow::Int64 # Maximum context length in tokens - maxTokens::Int64 # Maximum output tokens per completion -end - # ------------------------------------------------------------------------------------------------ # # Agent loop configuration & tool execution types # # ------------------------------------------------------------------------------------------------ # @@ -335,13 +340,13 @@ Result returned by tool execution before the `afterToolCall` hook. # Arguments - `content::Vector{messageContent}`: Tool output content - `details::Dict{Any,Any}`: Tool-specific details -- `usage::Union{Usage, Nothing}`: Token usage if applicable +- `usage::Union{llmUsage, Nothing}`: Token usage if applicable - `terminate::Bool`: Whether tool requests termination of the agent loop """ struct agentToolResult content::Vector{messageContent} details::Dict{Any,Any} - usage::Union{Usage, Nothing} + usage::Union{llmUsage, Nothing} terminate::Bool end