Model Adapters
A model adapter allows converting models with different input/output formats into a common schema.
To interact with model adapter using the CLI, use the lf model-adapter command.
Model Adapter Overview
Properties
key Key required
Reference to an existing entity in AI GO!.
Pattern:^[a-zA-Z0-9_\-\$]+$Max Length:
250display_name string required
The model adapter's name displayed to the user.
description string
Short description of the model adapter.
Default:Nonelong_description string
Long description of the model adapter. Supports Markdown formatting.
Default:Noneprovider enum ModelAdapterProviderId
Provider of the model adapter.
Default:userPossible ModelAdapterProviderId values
The provider of the model adapter.
Allowed Values:
latticeflowuser
task enum MLTask
The ML task of the model. Default is: chat_completion.
chat_completionPossible MLTask values
The type of machine learning task to be performed.
Allowed Values:
chat_completionembeddingscustom
process_input ModelAdapterCodeSnippet required
The transform of the model inputs in AI GO! format into the body of the HTTP request.
process_output ModelAdapterCodeSnippet required
The transform of the model's HTTP response body into the AI GO! 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).
task: "chat_completion"
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 %}
]
}Definitions
ModelAdapterCodeSnippet
ModelAdapterCodeSnippetProperties
language enum ModelAdapterCodeLanguage required
The programming language of the code snippet.
Possible ModelAdapterCodeLanguage values
The programming language used in the code snippet.
Allowed Values:
jinja
source_code string required
The source code of the model adapter.
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).
task: "chat_completion"
process_input:
language: "jinja"
source_code: !include "./ragflow_input.jinja"
process_output:
language: "jinja"
source_code: !include "./ragflow_output.jinja"
!includedirective is a convenient way to include the code snippet from a separate file. Alternatively, you can inline the code snippet directly in the YAML file.
