module LLM::Adapter

Overview

A normalized adapter interface for LLM clients.

Implementations should return a String response (JSON text after any provider-specific cleanup).

Direct including types

Defined in:

llm/adapter.cr

Instance Method Summary

Instance Method Detail

def close : Nil #

Optional cleanup hook for adapters that manage external resources.


[View source]
abstract def request(prompt : String, format : String = "json") : String #

Send a single prompt and get a response as a String.


[View source]
abstract def request_messages(messages : Messages, format : String = "json") : String #

Send chat-style messages (system/user) and get a response as a String.


[View source]
def request_messages_with_tools(messages : Messages, _tools : String) : String #

Request next step using provider-native tool definitions. Implementations that do not support this can fallback to regular JSON-mode requests.


[View source]
def request_with_context(system : String | Nil, user : String, format : String = "json", cache_key : String | Nil = nil) : String #

Context-aware request. Adapters that support provider-side context can reuse it using a cache_key. Default implementation falls back to request_messages without context reuse.


[View source]
def supports_context? : Bool #

Whether this adapter supports server-side KV context reuse across calls.


[View source]
def supports_native_tool_calling? : Bool #

Whether this adapter can leverage provider-native tool-calling.


[View source]