mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
other providers
This commit is contained in:
parent
22696fa75b
commit
339dfe5e02
@ -199,6 +199,7 @@ export const useUpdateModelList = () => {
|
|||||||
return updateModelList
|
return updateModelList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deprecated ???
|
||||||
export const useAnthropicBuyQuota = () => {
|
export const useAnthropicBuyQuota = () => {
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ const CredentialPanel: FC<CredentialPanelProps> = ({
|
|||||||
|
|
||||||
const handleChangePriority = async (key: PreferredProviderTypeEnum) => {
|
const handleChangePriority = async (key: PreferredProviderTypeEnum) => {
|
||||||
const res = await changeModelProviderPriority({
|
const res = await changeModelProviderPriority({
|
||||||
url: `/workspaces/current/model-providers/${provider.provider}/preferred-provider-type`,
|
url: `/workspaces/current/model-providers/${provider.plugin_id}/${provider.provider}/preferred-provider-type`,
|
||||||
body: {
|
body: {
|
||||||
preferred_provider_type: key,
|
preferred_provider_type: key,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,11 +4,8 @@ import { useCallback, useEffect, useState } from 'react'
|
|||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
import { useRouter, useSearchParams } from 'next/navigation'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { useContext } from 'use-context-selector'
|
|
||||||
import I18n from '@/context/i18n'
|
|
||||||
import {
|
import {
|
||||||
fetchDataSourceNotionBinding,
|
fetchDataSourceNotionBinding,
|
||||||
fetchFreeQuotaVerify,
|
|
||||||
} from '@/service/common'
|
} from '@/service/common'
|
||||||
import type { IConfirm } from '@/app/components/base/confirm'
|
import type { IConfirm } from '@/app/components/base/confirm'
|
||||||
import Confirm from '@/app/components/base/confirm'
|
import Confirm from '@/app/components/base/confirm'
|
||||||
@ -53,66 +50,6 @@ export const useBillingPay = () => {
|
|||||||
return confirm
|
return confirm
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUOTA_RECEIVE_STATUS: Record<string, any> = {
|
|
||||||
spark: {
|
|
||||||
success: {
|
|
||||||
'en': 'Successful collection, the quota will be automatically increased after 5 minutes.',
|
|
||||||
'zh-Hans': '领取成功,将在 5 分钟后自动增加配额',
|
|
||||||
},
|
|
||||||
fail: {
|
|
||||||
'en': 'Failure to collect',
|
|
||||||
'zh-Hans': '领取失败',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
zhipuai: {
|
|
||||||
success: {
|
|
||||||
'en': 'Successful collection',
|
|
||||||
'zh-Hans': '领取成功',
|
|
||||||
},
|
|
||||||
fail: {
|
|
||||||
'en': 'Failure to collect',
|
|
||||||
'zh-Hans': '领取失败',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const FREE_CHECK_PROVIDER = ['spark', 'zhipuai']
|
|
||||||
export const useCheckFreeQuota = () => {
|
|
||||||
const { locale } = useContext(I18n)
|
|
||||||
const router = useRouter()
|
|
||||||
const [shouldVerify, setShouldVerify] = useState(false)
|
|
||||||
const searchParams = useSearchParams()
|
|
||||||
const type = searchParams.get('type')
|
|
||||||
const provider = searchParams.get('provider')
|
|
||||||
const result = searchParams.get('result')
|
|
||||||
const token = searchParams.get('token')
|
|
||||||
|
|
||||||
const { data, error } = useSWR(
|
|
||||||
shouldVerify
|
|
||||||
? `/workspaces/current/model-providers/${provider}/free-quota-qualification-verify?token=${token}`
|
|
||||||
: null,
|
|
||||||
fetchFreeQuotaVerify,
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (error)
|
|
||||||
router.replace('/')
|
|
||||||
}, [error, router])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (type === 'provider_apply_callback' && FREE_CHECK_PROVIDER.includes(provider as string) && result === 'success')
|
|
||||||
setShouldVerify(true)
|
|
||||||
}, [type, provider, result])
|
|
||||||
|
|
||||||
return (data && provider)
|
|
||||||
? {
|
|
||||||
type: data.flag ? 'info' : 'warning',
|
|
||||||
title: data.flag ? QUOTA_RECEIVE_STATUS[provider as string].success[locale] : QUOTA_RECEIVE_STATUS[provider].fail[locale],
|
|
||||||
desc: !data.flag ? data.reason : undefined,
|
|
||||||
}
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useCheckNotion = () => {
|
export const useCheckNotion = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [confirm, setConfirm] = useState<ConfirmType | null>(null)
|
const [confirm, setConfirm] = useState<ConfirmType | null>(null)
|
||||||
@ -154,7 +91,6 @@ export const CheckModal = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [showPayStatusModal, setShowPayStatusModal] = useState(true)
|
const [showPayStatusModal, setShowPayStatusModal] = useState(true)
|
||||||
const anthropicConfirmInfo = useAnthropicCheckPay()
|
const anthropicConfirmInfo = useAnthropicCheckPay()
|
||||||
const freeQuotaConfirmInfo = useCheckFreeQuota()
|
|
||||||
const notionConfirmInfo = useCheckNotion()
|
const notionConfirmInfo = useCheckNotion()
|
||||||
const billingConfirmInfo = useBillingPay()
|
const billingConfirmInfo = useBillingPay()
|
||||||
|
|
||||||
@ -163,7 +99,7 @@ export const CheckModal = () => {
|
|||||||
router.replace('/')
|
router.replace('/')
|
||||||
}, [router])
|
}, [router])
|
||||||
|
|
||||||
const confirmInfo = anthropicConfirmInfo || freeQuotaConfirmInfo || notionConfirmInfo || billingConfirmInfo
|
const confirmInfo = anthropicConfirmInfo || notionConfirmInfo || billingConfirmInfo
|
||||||
|
|
||||||
if (!confirmInfo || !showPayStatusModal)
|
if (!confirmInfo || !showPayStatusModal)
|
||||||
return null
|
return null
|
||||||
@ -176,7 +112,7 @@ export const CheckModal = () => {
|
|||||||
showCancel={false}
|
showCancel={false}
|
||||||
type={confirmInfo.type === 'info' ? 'info' : 'warning' }
|
type={confirmInfo.type === 'info' ? 'info' : 'warning' }
|
||||||
title={confirmInfo.title}
|
title={confirmInfo.title}
|
||||||
content={(confirmInfo as { desc: string }).desc || ''}
|
content={(confirmInfo as unknown as { desc: string }).desc || ''}
|
||||||
confirmText={(confirmInfo.type === 'info' && t('common.operation.ok')) || ''}
|
confirmText={(confirmInfo.type === 'info' && t('common.operation.ok')) || ''}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -257,10 +257,6 @@ export const fetchFileUploadConfig: Fetcher<FileUploadConfigResponse, { url: str
|
|||||||
return get<FileUploadConfigResponse>(url)
|
return get<FileUploadConfigResponse>(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => {
|
|
||||||
return get(url) as Promise<{ result: string; flag: boolean; reason: string }>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
|
export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
|
||||||
return get(url) as Promise<{ data: string }>
|
return get(url) as Promise<{ data: string }>
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user