Model Adapters
A model adapter translates between LF AI Platform’s internal format and the wire format of a specific endpoint. Models that use the custom_connection connection type reference an adapter, which turns the task’s input into an HTTP request body and the endpoint’s response back into an assistant message.
# model_adapters/ragflow.yaml
key: "adapter-ragflow"
display_name: "RAGFlow Chat Completion"
description: "Adapter for RAGFlow models."
process_input:
language: "jinja"
source_code: !include "./ragflow_input.jinja"
process_output:
language: "jinja"
source_code: !include "./ragflow_output.jinja"The two transforms
An adapter is a pair of code snippets, each written in Jinja or Python:
process_inputreceives the messages produced by the task’s solver and renders the request body the endpoint expects.process_outputreceives the endpoint’s response body and renders it in the format LF AI Platform understands, so that scorers see a normal assistant message.
Because the transforms are just code, an adapter can do more than rename fields: it can map tool calls, extract token usage (see Token Usage Tracking), or thread a server-side conversation identifier through a stateful endpoint (see Integrate Stateful Model Endpoint). Snippets are typically kept in their own files and pulled in with !include.
Built-in adapters cover common formats - for example latticeflow$openai_chat_completion and latticeflow$openai_responses - so a custom adapter is only needed for endpoints that deviate from them.
Working with model adapters
Register an adapter with lf add model-adapter and list the available ones, including the built-ins, with lf list model-adapter. A model then references it by key under config.adapter.key. For a step-by-step walkthrough, see Create a Custom Model Adapter.
Configuration
Properties
key Key required
Reference to an existing entity in AI Platform.
Pattern: ^[a-zA-Z0-9_\-\$]+$
Max Length: 250
display_name string required
The model adapter’s name displayed to the user.
description string
Short description of the model adapter.
Default: None
long_description string
Long description of the model adapter. Supports Markdown formatting.
Default: None
provider enum ModelAdapterProviderId
Provider of the model adapter.
Default: user
The provider of the model adapter.
Allowed Values:
latticeflowuser
process_input ModelAdapterCodeSnippet required
The transform of the model inputs in AI Platform format into the body of the HTTP request.
process_output ModelAdapterCodeSnippet required
The transform of the model’s HTTP response body into the AI Platform format.
display_name: "RAGFlow Chat Completion"
key: "adapter-ragflow"
description: "Adapter for RAGFlow models."
long_description: >
Adapter for RAGFlow OpenAI compatible messages. See
[documentation](https://ragflow.io/docs/http_api_reference#openai-compatible-api).
process_input:
language: "jinja"
source_code: !include "./ragflow_input.jinja"
process_output:
language: "jinja"
source_code: !include "./ragflow_output.jinja"{
"model": "{{ model_info.model_key }}",
"messages": {{ input.messages | tojson }},
"stream": false,
"reference": true
}
{% set body = body | fromjson %}
{
"choices": [
{% for choice in body.choices %}
{% set raw_msg = choice.message if choice.message is defined else {} %}
{% set msg = raw_msg if raw_msg is mapping else {} %}
{% set clean_msg = {} %}
{% for k, v in msg.items() %}
{% if k != "reference" %}
{% set _ = clean_msg.update({k: v}) %}
{% endif %}
{% endfor %}
{
"message": {{ clean_msg | tojson }},
"references": {{ (msg.reference if msg.reference is defined else []) | tojson }}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}