LLMProxy.Protocol behaviour (llm_proxy v0.1.0)

Copy Markdown View Source

Protocol detection and conversion between LLM API formats.

Each protocol module knows how to:

  • Render normalized requests to wire format
  • Convert responses back to its format
  • Handle streaming event conversion

Summary

Callbacks

Convert a non-streaming response from source protocol to this protocol's format

Extract usage from a response in this protocol's native format

Which protocol this module handles

Types

protocol()

@type protocol() :: :openai | :anthropic

Callbacks

convert_response(response, from, model)

@callback convert_response(response :: map(), from :: protocol(), model :: String.t()) ::
  map()

Convert a non-streaming response from source protocol to this protocol's format

extract_usage(response)

@callback extract_usage(response :: map()) :: LLMProxy.Providers.Behaviour.usage()

Extract usage from a response in this protocol's native format

protocol()

@callback protocol() :: protocol()

Which protocol this module handles

Functions

get_module(atom)

provider_request_body(request, provider, model)

@spec provider_request_body(LLMProxy.Protocol.Request.t(), module(), String.t()) ::
  map()