# llm_baidu_qianfan

A RocketRide LLM node that calls Baidu Qianfan ERNIE chat models through Qianfan's OpenAI-compatible chat-completions API.

## What it does

Connects a pipeline to Baidu Qianfan ERNIE large language models for chat-based text
generation, question answering, summarization, and Chinese-language enterprise AI
workflows. Questions arriving on the `questions` lane are answered by the configured
ERNIE model and emitted on the `answers` lane.

Uses **langchain-openai** (`ChatOpenAI`) over the **openai** Python SDK, pointed at
Qianfan's OpenAI-compatible endpoint. Temperature is fixed at `0` for deterministic
output, and generation is capped at the profile's output-token limit.

When you save the node configuration, the node validates it live: it sends a tiny test
completion (`"Hi"`, max 8 tokens) to the configured endpoint and surfaces a specific
warning for an invalid API key, an empty model name, a non-positive token limit, a rate
limit, an unreachable base URL, or any other API error.

At runtime, rate-limit and connection errors are treated as retryable; authentication
and other API errors fail immediately with a user-facing message.

---

## Configuration

### Lanes

| Lane        | Direction | Description                              |
|-------------|-----------|------------------------------------------|
| `questions` | input     | Prompts / questions to send to the model |
| `answers`   | output    | Model completions                        |

### Fields

The node is configured through a single **Model** profile selector plus the fields that
profile exposes.

| Field | Type | Description |
|---|---|---|
| `model` | string | Baidu Qianfan model name |
| `modelTotalTokens` | number | Maximum context length in tokens |
| `modelOutputTokens` | number | Maximum generated tokens |
| `serverbase` | string | Default "https://qianfan.baidubce.com/v2". Qianfan OpenAI-compatible API endpoint. |
| `profile` | string | Default "ernie-4-5-turbo-128k". Baidu Qianfan model selection |

---

## Model profiles

| Profile                          | Model                        | Context tokens    | Output tokens     |
|----------------------------------|------------------------------|-------------------|-------------------|
| ERNIE 4.5 Turbo 128K (default)   | `ernie-4.5-turbo-128k`       | 128,000           | 4,096             |
| ERNIE 4.5 Turbo 32K              | `ernie-4.5-turbo-32k`        | 32,768            | 4,096             |
| ERNIE 5.0 Thinking Preview       | `ernie-5.0-thinking-preview` | 128,000           | 8,192             |
| Custom                           | user-supplied                | 32,768 (editable) | 4,096 (editable)  |

The named profiles pin the model name and token limits; only the API key, base URL, and
model source are editable. The **Custom** profile additionally exposes `model`,
`modelTotalTokens`, and `modelOutputTokens` so you can target any model available on
your Qianfan account.

---

## Authentication

Provide a Qianfan API key in `apikey`: it is required, and the node refuses to start
without one. The key must have access to the selected model.

Pick the base URL matching where your key was issued:

- **China (default)**: `https://qianfan.baidubce.com/v2`
- **International**: `https://api.baiduqianfan.ai/v1`

An invalid or unauthorized key is reported as "Baidu Qianfan API key is invalid or
unauthorized" both at save-time validation and at runtime.

---

<!-- ROCKETRIDE:GENERATED:PARAMS START -->
<!-- Generated by nodes:docs-generate. Do not edit by hand. -->

## Schema

| Field | Type | Description | Default |
|---|---|---|---|
| `baidu_qianfan.profile` | `string` | **Model**<br/>Baidu Qianfan model selection | `"ernie-4-5-turbo-128k"` |
| `baidu_qianfan.serverbase` | `string` | **Base URL**<br/>Qianfan OpenAI-compatible API endpoint. | `"https://qianfan.baidubce.com/v2"` |
| `model` | `string` | **Model**<br/>Baidu Qianfan model name |  |
| `modelOutputTokens` | `number` | **Output Tokens**<br/>Maximum generated tokens |  |
| `modelTotalTokens` | `number` | **Tokens**<br/>Maximum context length in tokens |  |

## Dependencies

- `openai`
- `langchain`
- `langchain-core`
- `langchain-openai`

## Source

[<svg viewBox="0 0 16 16" width="15" height="15" fill="currentColor" aria-hidden="true" style="vertical-align:-0.15em;margin-right:0.35em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg> View source](https://github.com/rocketride-org/rocketride-server/tree/develop/nodes/src/nodes/llm_baidu_qianfan)
<!-- ROCKETRIDE:GENERATED:PARAMS END -->
