mirror of
https://github.com/langgenius/dify.git
synced 2026-10-28 03:35:04 +08:00
feat: add Responses API tip for GPT-5.6 and later models in multiple languages (#39188)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
autofix-ci[bot]
parent
38045078dc
commit
2f3c785f27
+64
@@ -1,5 +1,6 @@
|
||||
import type * as React from 'react'
|
||||
import type { Credential, CredentialFormSchema, ModelProvider } from '../../declarations'
|
||||
import type { FormSchema } from '@/app/components/base/form/types'
|
||||
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
|
||||
import {
|
||||
ConfigurationMethodEnum,
|
||||
@@ -125,8 +126,10 @@ vi.mock('@/app/components/base/form/form-scenarios/auth', async () => {
|
||||
const AuthForm = React.forwardRef(
|
||||
(
|
||||
{
|
||||
formSchemas,
|
||||
onChange,
|
||||
}: {
|
||||
formSchemas: FormSchema[]
|
||||
onChange?: (field: string, value: string) => void
|
||||
},
|
||||
ref: React.ForwardedRef<{
|
||||
@@ -141,6 +144,12 @@ vi.mock('@/app/components/base/form/form-scenarios/auth', async () => {
|
||||
}))
|
||||
return (
|
||||
<div>
|
||||
{formSchemas.map(
|
||||
(schema) =>
|
||||
typeof schema.description === 'string' && (
|
||||
<div key={schema.name}>{schema.description}</div>
|
||||
),
|
||||
)}
|
||||
<button type="button" onClick={() => onChange?.('__model_name', 'updated-model')}>
|
||||
Model Name Change
|
||||
</button>
|
||||
@@ -281,6 +290,61 @@ describe('ModelModal', () => {
|
||||
expect(screen.getByText('common.modelProvider.auth.modelCredential'))!.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the Responses API tip only for official OpenAI credential forms', () => {
|
||||
const tip = 'common.modelProvider.auth.openAIResponsesAPITip'
|
||||
mockState.formSchemas = [
|
||||
{ variable: 'api_protocol', type: 'select' } as unknown as CredentialFormSchema,
|
||||
]
|
||||
|
||||
const officialOpenAI = renderModal({
|
||||
provider: createProvider({ provider: 'langgenius/openai/openai' }),
|
||||
})
|
||||
expect(screen.getByText(tip))!.toBeInTheDocument()
|
||||
officialOpenAI.unmount()
|
||||
|
||||
const legacyOpenAI = renderModal()
|
||||
expect(screen.getByText(tip))!.toBeInTheDocument()
|
||||
legacyOpenAI.unmount()
|
||||
|
||||
mockState.formSchemas = []
|
||||
const openAIWithoutProtocolField = renderModal()
|
||||
expect(screen.queryByText(tip)).not.toBeInTheDocument()
|
||||
openAIWithoutProtocolField.unmount()
|
||||
|
||||
mockState.formSchemas = [
|
||||
{ variable: 'api_protocol', type: 'select' } as unknown as CredentialFormSchema,
|
||||
]
|
||||
renderModal({
|
||||
provider: createProvider({ provider: 'langgenius/azure_openai/azure_openai' }),
|
||||
})
|
||||
expect(screen.queryByText(tip)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the Responses API tip when adding a new custom model credential', () => {
|
||||
const tip = 'common.modelProvider.auth.openAIResponsesAPITip'
|
||||
mockState.formSchemas = [
|
||||
{ variable: 'api_protocol', type: 'select' } as unknown as CredentialFormSchema,
|
||||
]
|
||||
const customModel = renderModal({ mode: ModelModalModeEnum.configCustomModel })
|
||||
expect(screen.getByText(tip))!.toBeInTheDocument()
|
||||
customModel.unmount()
|
||||
|
||||
const modelCredential = renderModal({
|
||||
mode: ModelModalModeEnum.configModelCredential,
|
||||
model: { model: 'gpt-5.6', model_type: ModelTypeEnum.textGeneration },
|
||||
})
|
||||
expect(screen.getByText(tip))!.toBeInTheDocument()
|
||||
modelCredential.unmount()
|
||||
|
||||
renderModal({ mode: ModelModalModeEnum.addCustomModelToModelList })
|
||||
|
||||
expect(screen.queryByText(tip)).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByText('Add New'))
|
||||
|
||||
expect(screen.getByText(tip))!.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should call onCancel when the cancel button is clicked', () => {
|
||||
const { onCancel } = renderModal()
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
import ModelIcon from '@/app/components/header/account-setting/model-provider-page/model-icon'
|
||||
import { useCredentialPermissions } from '@/hooks/use-credential-permissions'
|
||||
import { useRenderI18nObject } from '@/hooks/use-i18n'
|
||||
import { ModelProviderQuotaGetPaid } from '@/types/model-provider'
|
||||
import { ConfigurationMethodEnum, FormTypeEnum, ModelModalModeEnum } from '../declarations'
|
||||
import { useLanguage } from '../hooks'
|
||||
import { CredentialSelector } from '../model-auth'
|
||||
@@ -285,6 +286,8 @@ const ModelModal: FC<ModelModalProps> = ({
|
||||
if (getForm()) getForm()?.setFieldValue(field, value)
|
||||
}, [])
|
||||
const notAllowCustomCredential = provider.allow_custom_token === false
|
||||
const isOfficialOpenAIProvider =
|
||||
provider.provider === ModelProviderQuotaGetPaid.OPENAI || provider.provider === 'openai'
|
||||
|
||||
const handleOpenChange = useCallback(
|
||||
(open: boolean) => {
|
||||
@@ -357,6 +360,13 @@ const ModelModal: FC<ModelModalProps> = ({
|
||||
...formSchema,
|
||||
name: formSchema.variable,
|
||||
showRadioUI: formSchema.type === FormTypeEnum.radio,
|
||||
...(isOfficialOpenAIProvider && formSchema.variable === 'api_protocol'
|
||||
? {
|
||||
description: t(($) => $['modelProvider.auth.openAIResponsesAPITip'], {
|
||||
ns: 'common',
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
}) as FormSchema[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user