utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLastMessage

func ExtractLastMessage(messages []openai.ChatCompletionMessageParamUnion) (string, error)

ExtractLastMessage extracts content from the last message for cache key generation. This supports all message roles (user, assistant, system, developer, tool).

func ExtractPromptFromAnthropicMessages

func ExtractPromptFromAnthropicMessages(messages []anthropic.MessageParam) (string, error)

ExtractPromptFromAnthropicMessages extracts the prompt text from Anthropic MessageParam array for routing decisions Gets the last user message with text content

func ExtractPromptFromGeminiContents

func ExtractPromptFromGeminiContents(contents []*genai.Content) (string, error)

ExtractPromptFromGeminiContents extracts the prompt text from Gemini Content array for routing decisions Intelligently processes different part types and combines them into a coherent prompt

func ExtractToolCallsFromAnthropicMessages

func ExtractToolCallsFromAnthropicMessages(messages []anthropic.MessageParam) any

ExtractToolCallsFromAnthropicMessages extracts tool calls from the last message if it's an assistant message.

func ExtractToolCallsFromGeminiContents

func ExtractToolCallsFromGeminiContents(contents []*genai.Content) *genai.Part

ExtractToolCallsFromGeminiContents extracts tool calls from the last content if it's a model content

func ExtractToolCallsFromLastMessage

func ExtractToolCallsFromLastMessage(messages []openai.ChatCompletionMessageParamUnion) any

ExtractToolCallsFromLastMessage extracts tool calls from the last message if it's an assistant message.

func FindLastUserMessage

func FindLastUserMessage(messages []openai.ChatCompletionMessageParamUnion) (string, error)

FindLastUserMessage safely finds the last user message in a conversation.

func Get

Get is a convenience function that uses the global pool

func ParseProviderModel

func ParseProviderModel(modelSpec string) (provider, model string, err error)

ParseProviderModel parses a model specification in "provider:model" format. This function is strict - it requires exact format and will error if not correct. Examples:

  • "openai:gpt-4" -> ("openai", "gpt-4", nil)
  • "anthropic:claude-3-5-sonnet-20241022" -> ("anthropic", "claude-3-5-sonnet-20241022", nil)
  • "gpt-4" -> error (no provider specified)
  • "openai:" -> error (empty model)
  • ":gpt-4" -> error (empty provider)
  • "openai:gpt-4:extra" -> error (too many parts)

func ParseProviderModelWithDefault

func ParseProviderModelWithDefault(modelSpec, defaultProvider string) (provider, model string, err error)

ParseProviderModelWithDefault parses a model specification, using defaultProvider if no provider is specified. This is less strict than ParseProviderModel - it allows model-only specifications. Examples:

  • "openai:gpt-4" -> ("openai", "gpt-4", nil)
  • "gpt-4" with defaultProvider="openai" -> ("openai", "gpt-4", nil)
  • "anthropic:" -> error (empty model)
  • ":gpt-4" -> error (empty provider)

func Put

func Put(buf *bytebufferpool.ByteBuffer)

Put is a convenience function that uses the global pool

Types

type BufferPool

type BufferPool struct {
	// contains filtered or unexported fields
}

BufferPool provides efficient buffer pooling for streaming operations Uses bytebufferpool for automatic size-class management and anti-fragmentation

func Global

func Global() *BufferPool

Global returns the global buffer pool instance

func NewBufferPool

func NewBufferPool() *BufferPool

NewBufferPool creates a new buffer pool

func (*BufferPool) Get

Get retrieves a buffer from the pool

func (*BufferPool) Put

func (bp *BufferPool) Put(buf *bytebufferpool.ByteBuffer)

Put returns a buffer to the pool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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