Model Runtime (#1858)

Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
Co-authored-by: Garfield Dai <dai.hai@foxmail.com>
Co-authored-by: chenhe <guchenhe@gmail.com>
Co-authored-by: jyong <jyong@dify.ai>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Yeuoly <admin@srmxy.cn>
This commit is contained in:
takatost
2024-01-02 23:42:00 +08:00
committed by GitHub
parent e91dd28a76
commit d069c668f8
807 changed files with 171310 additions and 23806 deletions

View File

@ -25,7 +25,13 @@ import type {
UpdateOpenAIKeyResponse,
ValidateOpenAIKeyResponse,
} from '@/models/app'
import type { BackendModel, ProviderMap } from '@/app/components/header/account-setting/model-page/declarations'
import type {
DefaultModelResponse,
Model,
ModelItem,
ModelParameterRule,
ModelProvider,
} from '@/app/components/header/account-setting/model-provider-page/declarations'
import type { RETRIEVE_METHOD } from '@/types/app'
export const login: Fetcher<CommonResponse & { data: string }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
@ -146,12 +152,20 @@ export const activateMember: Fetcher<CommonResponse, { url: string; body: any }>
return post<CommonResponse>(url, { body })
}
export const fetchModelProviders: Fetcher<ProviderMap, string> = (url) => {
return get<ProviderMap>(url)
export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => {
return get<{ data: ModelProvider[] }>(url)
}
export const fetchModelList: Fetcher<BackendModel[], string> = (url) => {
return get<BackendModel[]>(url)
export const fetchModelProviderCredentials: Fetcher<{ credentials?: Record<string, string | undefined | boolean> }, string> = (url) => {
return get<{ credentials?: Record<string, string | undefined | boolean> }>(url)
}
export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => {
return get<{ data: ModelItem[] }>(url)
}
export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => {
return get<{ data: Model[] }>(url)
}
export const validateModelProvider: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
@ -162,8 +176,8 @@ export const setModelProvider: Fetcher<CommonResponse, { url: string; body: any
return post<CommonResponse>(url, { body })
}
export const deleteModelProvider: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
return del<CommonResponse>(url)
export const deleteModelProvider: Fetcher<CommonResponse, { url: string; body?: any }> = ({ url, body }) => {
return del<CommonResponse>(url, { body })
}
export const changeModelProviderPriority: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
@ -182,14 +196,18 @@ export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
return get<{ url: string }>(url)
}
export const fetchDefaultModal: Fetcher<BackendModel, string> = (url) => {
return get<BackendModel>(url)
export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => {
return get<{ data: DefaultModelResponse }>(url)
}
export const updateDefaultModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
return post<CommonResponse>(url, { body })
}
export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => {
return get<{ data: ModelParameterRule[] }>(url)
}
export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => {
return post<{ type: string; redirect_url?: string; result?: string }>(url)
}

View File

@ -2,6 +2,7 @@ import type { IOnAnnotationReply, IOnCompleted, IOnData, IOnError, IOnMessageEnd
import { get, post, ssePost } from './base'
import type { ChatPromptConfig, CompletionPromptConfig } from '@/models/debug'
import type { ModelModeType } from '@/types/app'
import type { ModelParameterRule } from '@/app/components/header/account-setting/model-provider-page/declarations'
export type AutomaticRes = {
prompt: string
@ -65,9 +66,9 @@ export const generateRule = (body: Record<string, any>) => {
export const fetchModelParams = (providerName: string, modelId: string) => {
return get(`workspaces/current/model-providers/${providerName}/models/parameter-rules`, {
params: {
model_name: modelId,
model: modelId,
},
})
}) as Promise<{ data: ModelParameterRule[] }>
}
export const fetchPromptTemplate = ({