Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions models/openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This plugin connects Dify to OpenAI language, embedding, moderation, speech-to-t
- The LLM integration was rewritten around the official OpenAI Python SDK.
- The Responses API is now the default for supported language models.
- Chat Completions remains available for compatible endpoints and audio-capable chat models.
- Stateless reasoning replay preserves every OpenAI output item, including encrypted reasoning items and assistant phase metadata.
- The plugin retains every OpenAI output item, including encrypted reasoning items and assistant phase metadata, for stateless replay when Dify passes the opaque payload back.
- Reasoning summaries, refusals, parallel function calls, terminal states, usage, and stream cancellation now have explicit handling.
- The model catalog was checked against OpenAI's model and deprecation documentation.
- Deprecated and unavailable model entries were removed, while missing current entries were added.
Expand Down Expand Up @@ -47,6 +47,13 @@ The API only accepts metadata when storage is enabled, so enabling it also sends

<img src="./_assets/openai-01.png" width="400" alt="OpenAI provider configuration" />

## GPT-6 models

GPT-6 Astra, Sol, and Luna support text, vision, structured outputs, and streaming, with reasoning effort set to `medium` by default.
GPT-6 Astra requires Responses for function calling and does not support reasoning effort `none`.
GPT-6 Sol and Luna support function calling through Chat Completions only with reasoning effort `none`; use Responses to combine reasoning and tools.
Sampling and log-probability parameters are omitted when reasoning is enabled.

## Question classification with Decisions

Select `gpt-6-luna-only-for-question-classifier` in a Dify Question Classifier
Expand Down Expand Up @@ -77,7 +84,8 @@ See the [official Decisions guide](https://developers.openai.com/api/docs/guides

The plugin sends `store=false` by default and requests encrypted reasoning content when it uses the Responses API. Enabling `Enable request metadata` switches `store` to `true`, but encrypted reasoning content is still requested, so reasoning replay behaves the same either way.

Complete response output items are stored in the assistant message's opaque payload and replayed in original order on the next turn.
Complete response output items are stored in the assistant message's opaque payload and replayed in original order when that payload returns on the next turn.
Existing SDK, daemon, Dify, and Agent paths can lose or reject this payload during tool continuations; adding GPT-6 model support does not resolve those limitations.

Reasoning summaries are user-visible only when `reasoning_summary` is enabled for a supported model.

Expand Down
2 changes: 1 addition & 1 deletion models/openai/manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.0.6
version: 1.0.7
type: plugin
author: "langgenius"
name: "openai"
Expand Down
20 changes: 19 additions & 1 deletion models/openai/models/common_openai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Generator, Iterable, Mapping
import hashlib
import re
from collections.abc import Generator, Iterable, Mapping
from typing import TypeVar

import openai
Expand All @@ -20,6 +20,24 @@ def _user_digest(user: str) -> str:
return hashlib.sha256(user.encode()).hexdigest()


def _normalize_gpt6_parameters(model: str, params: dict, effort: str | None) -> None:
if not model.startswith("gpt-6-"):
return
if model == "gpt-6-astra" and effort == "none":
raise InvokeBadRequestError(
"GPT-6 Astra does not support reasoning effort none"
)
if effort != "none":
for name in ("temperature", "top_p", "top_logprobs", "logprobs"):
params.pop(name, None)
if "include" in params:
params["include"] = [
item
for item in params["include"] or []
if item != "message.output_text.logprobs"
]


def _chat_completions_tools_reasoning_guidance(error: Exception) -> str | None:
if not isinstance(error, openai.BadRequestError):
return None
Expand Down
3 changes: 3 additions & 0 deletions models/openai/models/llm/_position.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- gpt-6-astra
- gpt-6-sol
- gpt-6-luna
- gpt-5.6
- gpt-5.6-sol
- gpt-5.6-terra
Expand Down
32 changes: 23 additions & 9 deletions models/openai/models/llm/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from collections.abc import Generator, Iterable
from typing import TYPE_CHECKING, Any, cast

from openai import OpenAI
from openai.types.chat import ChatCompletion

from dify_plugin.entities.model.llm import (
LLMResult,
LLMResultChunk,
Expand All @@ -27,15 +24,17 @@
UserPromptMessage,
)
from dify_plugin.errors.model import InvokeBadRequestError, InvokeConnectionError
from openai import OpenAI
from openai.types.chat import ChatCompletion

from ..common_openai import _user_digest
from ..common_openai import _normalize_gpt6_parameters, _user_digest
from . import tokens
from ._metadata import apply_dify_metadata_if_enabled

if TYPE_CHECKING:
from .llm import OpenAILargeLanguageModel

THINKING_PREFIXES = ("o", "gpt-5")
THINKING_PREFIXES = ("o", "gpt-5", "gpt-6")


def generate_chat(
Expand All @@ -50,7 +49,17 @@ def generate_chat(
stream: bool,
user: str | None,
) -> LLMResult | Generator[LLMResultChunk, None, None]:
params = _chat_params(model_parameters)
params = _chat_params(model, model_parameters)
effort = params.get("reasoning_effort")
_normalize_gpt6_parameters(model, params, effort)
if (
model.startswith("gpt-6-")
and (tools or params.get("tools"))
and (model == "gpt-6-astra" or effort != "none")
):
raise InvokeBadRequestError(
f"{model} function tools require the Responses API with this reasoning effort"
)
if uses_max_completion_tokens(model) and "max_tokens" in params:
params["max_completion_tokens"] = params.pop("max_tokens")
if tools:
Expand Down Expand Up @@ -131,12 +140,17 @@ def message(prompt: PromptMessage) -> dict[str, Any]:
return result


def _chat_params(model_parameters: dict) -> dict:
def _chat_params(model: str, model_parameters: dict) -> dict:
params = model_parameters.copy()
unsupported = [
name
for name in ("reasoning_summary", "reasoning_mode", "reasoning_context")
if params.pop(name, None) not in (None, "")
for name, default in (
("reasoning_summary", None),
("reasoning_mode", "standard"),
("reasoning_context", "auto"),
)
if params.pop(name, None)
not in (None, "", default if model.startswith("gpt-6-") else None)
]
if unsupported:
raise InvokeBadRequestError(
Expand Down
135 changes: 135 additions & 0 deletions models/openai/models/llm/gpt-6-astra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# https://developers.openai.com/api/docs/models/gpt-6-astra
model: gpt-6-astra
label:
zh_Hans: gpt-6-astra
en_US: gpt-6-astra
model_type: llm
features:
- multi-tool-call
- agent-thought
- stream-tool-call
- vision
- structured-output
model_properties:
mode: chat
context_size: 1050000
parameter_rules:
- name: max_tokens
use_template: max_tokens
default: 8192
min: 1
max: 128000
- name: response_format
label:
zh_Hans: 回复格式
en_US: Response Format
type: string
help:
zh_Hans: 指定模型必须输出的格式
en_US: specifying the format that the model must output
required: false
options:
- text
- json_schema
- name: json_schema
use_template: json_schema
- name: reasoning_effort
label:
zh_Hans: 推理努力程度
en_US: Reasoning Effort
type: string
help:
zh_Hans: GPT-6 Astra 支持 low、medium、high、xhigh 和 max,此插件默认值为 medium。工具调用需要 Responses API。
en_US: GPT-6 Astra supports low, medium, high, xhigh, and max. This plugin defaults to medium. Tool calling requires the Responses API.
required: false
default: medium
options:
- low
- medium
- high
- xhigh
- max
- name: reasoning_mode
label:
zh_Hans: 推理模式
en_US: Reasoning Mode
type: string
help:
zh_Hans: 标准模式平衡质量与延迟;Pro 模式会投入更多模型计算,仅适用于 Responses API。
en_US: Standard mode balances quality and latency; Pro mode applies more model work and is available only with the Responses API.
required: false
default: standard
options:
- standard
- pro
- name: reasoning_context
label:
zh_Hans: 推理上下文
en_US: Reasoning Context
type: string
help:
zh_Hans: 控制当前请求可使用哪些已有推理项;all_turns 需要通过 previous_response_id、Conversation 或完整历史提供先前响应。
en_US: Controls which available reasoning items the request can use; all_turns requires prior responses through previous_response_id, a Conversation, or complete replayed history.
required: false
default: auto
options:
- auto
- current_turn
- all_turns
- name: reasoning_summary
label:
zh_Hans: 推理摘要
en_US: Reasoning Summary
type: string
help:
zh_Hans: 显式请求模型返回最详细的可用推理摘要;仅适用于 Responses API。
en_US: Explicitly requests the most detailed available reasoning summary; available only with the Responses API.
required: false
options:
- auto
- name: verbosity
label:
zh_Hans: 详细程度
en_US: Verbosity
type: string
help:
zh_Hans: 约束模型响应的详细程度。较低的值将产生更简洁的响应,而较高的值将产生更详细的响应。支持的值包括 low、medium 和 high
en_US: Constrains the verbosity of the model's response. Lower values will result in more concise responses, while higher values will result in more verbose responses. Currently supported values are low, medium, and high
required: false
default: medium
options:
- low
- medium
- high
- name: enable_stream
label:
zh_Hans: 流式响应
en_US: Streaming
type: boolean
help:
zh_Hans: 是否启用流式响应。GPT-6 Astra 支持流式输出。
en_US: Whether to enable streaming responses. GPT-6 Astra supports streaming.
required: true
default: true
- name: service_tier
label:
zh_Hans: 服务层级
en_US: Service tier
type: string
help:
zh_Hans: Auto 跟随项目设置;Default、Flex 和 Priority 分别使用标准、低成本和低延迟处理。
en_US: Auto follows the project setting; Default, Flex, and Priority select standard, lower-cost, and lower-latency processing respectively.
required: false
default: auto
options:
- auto
- default
- flex
- priority
# Base Standard pricing for direct API requests with up to 272K input tokens.
# Cached, cache-write, regional, and long-context rates are not representable by PriceConfig.
pricing:
input: '10.00'
output: '50.00'
unit: '0.000001'
currency: USD
Loading
Loading