From 28da0263dc61113b96884c9864298681e85154fe Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Thu, 7 Mar 2024 01:09:03 +0800 Subject: [PATCH] Migrate new service (#1) --- ...-3f7b468d-823d-4219-b31b-12abca70ebf7.json | 7 + src/components/application/Confirm.vue | 49 +++--- .../ApiStatus.vue => application/Status.vue} | 42 ++---- src/components/chat/InputBox.vue | 5 +- src/components/chat/Introduction.vue | 1 + src/components/chat/Message.vue | 3 +- src/components/chat/ModelSelector.vue | 19 ++- src/components/chat/SidePanel.vue | 26 +++- src/components/chatdoc/Conversations.vue | 7 +- src/components/chatdoc/InputBox.vue | 4 +- src/components/chatdoc/Message.vue | 2 +- src/components/chatdoc/SidePanel.vue | 2 +- src/components/common/Navigator.vue | 1 - src/components/common/Price.vue | 1 + src/components/midjourney/FinalPrompt.vue | 1 + .../{ChannelSelector.vue => ModeSelector.vue} | 20 +-- .../midjourney/preset/StyleSelector.vue | 1 - .../midjourney/tasks/TaskBriefList.vue | 11 +- .../midjourney/tasks/TaskFullList.vue | 21 ++- .../midjourney/tasks/TaskPreview.vue | 113 +++++++------- src/components/order/Create.vue | 11 +- src/components/order/StripePay.vue | 3 +- src/components/order/WechatPay.vue | 3 +- src/constants/chat.ts | 43 ++++++ src/constants/chatdoc.ts | 1 + src/constants/endpoint.ts | 2 +- src/constants/index.ts | 4 +- src/constants/midjourney.ts | 26 ++++ src/constants/role.ts | 3 - src/i18n/zh/common/message.ts | 4 +- src/i18n/zh/midjourney/description.ts | 16 +- src/layouts/Chat.vue | 10 +- src/layouts/Chatdoc.vue | 8 +- src/layouts/Midjourney.vue | 12 ++ .../api/models.ts => models/api.ts} | 30 ++-- .../models.ts => models/application.ts} | 10 +- .../auth/models.ts => models/auth.ts} | 0 .../chat/models.ts => models/chat.ts} | 65 ++++---- .../chatdoc/models.ts => models/chatdoc.ts} | 5 +- src/models/common.ts | 6 + .../models.ts => models/distribution.ts} | 2 +- src/models/index.ts | 12 ++ .../models.ts => models/midjourney.ts} | 42 ++++-- .../order/models.ts => models/order.ts} | 2 +- src/models/service.ts | 28 ++++ .../usage/models.ts => models/usage.ts} | 2 +- .../user/models.ts => models/user.ts} | 0 src/operators/{api/operator.ts => api.ts} | 4 +- src/operators/api/index.ts | 2 - .../operator.ts => application.ts} | 6 +- src/operators/application/index.ts | 2 - src/operators/{auth/operator.ts => auth.ts} | 4 +- src/operators/chat.ts | 129 ++++++++++++++++ src/operators/chat/constants.ts | 57 ------- src/operators/chat/index.ts | 3 - src/operators/chat/operator.ts | 100 ------------- .../{chatdoc/operator.ts => chatdoc.ts} | 18 ++- src/operators/chatdoc/constants.ts | 4 - src/operators/chatdoc/index.ts | 2 - src/operators/{instance.ts => common.ts} | 0 .../operator.ts => distribution.ts} | 4 +- src/operators/distribution/index.ts | 2 - src/operators/index.ts | 4 +- src/operators/midjourney.ts | 87 +++++++++++ src/operators/midjourney/constants.ts | 31 ---- src/operators/midjourney/index.ts | 3 - src/operators/midjourney/operator.ts | 72 --------- src/operators/{order/operator.ts => order.ts} | 4 +- src/operators/order/index.ts | 2 - src/operators/service.ts | 37 +++++ src/operators/{usage/operator.ts => usage.ts} | 4 +- src/operators/usage/contants.ts | 0 src/operators/usage/index.ts | 2 - src/operators/{user/operator.ts => user.ts} | 4 +- src/operators/user/index.ts | 2 - src/pages/auth/Callback.vue | 3 +- src/pages/chat/Conversation.vue | 53 ++++--- src/pages/chatdoc/Conversation.vue | 43 ++---- src/pages/chatdoc/Index.vue | 32 ++-- src/pages/chatdoc/Manage.vue | 28 ++-- src/pages/console/application/Buy.vue | 3 +- src/pages/console/application/List.vue | 9 +- src/pages/console/order/Detail.vue | 4 +- src/pages/console/order/List.vue | 3 +- src/pages/distribution/History.vue | 3 +- src/pages/distribution/Index.vue | 10 +- src/pages/distribution/Invitees.vue | 3 +- src/pages/midjourney/History.vue | 55 +++---- src/pages/midjourney/Index.vue | 62 ++++---- src/store/chat/actions.ts | 141 ++++++++++-------- src/store/chat/models.ts | 13 +- src/store/chat/mutations.ts | 26 ++-- src/store/chat/persist.ts | 2 +- src/store/chat/state.ts | 13 +- src/store/chatdoc/actions.ts | 137 ++++++++--------- src/store/chatdoc/models.ts | 14 +- src/store/chatdoc/mutations.ts | 24 +-- src/store/chatdoc/persist.ts | 2 +- src/store/chatdoc/state.ts | 11 +- src/store/common/actions.ts | 5 +- src/store/common/models.ts | 15 +- src/store/common/mutations.ts | 2 +- src/store/index.ts | 6 +- src/store/midjourney/actions.ts | 139 ++++++++++------- src/store/midjourney/models.ts | 15 +- src/store/midjourney/mutations.ts | 33 ++-- src/store/midjourney/persist.ts | 2 +- src/store/midjourney/state.ts | 15 +- src/utils/baseUrl.ts | 8 +- 109 files changed, 1158 insertions(+), 1051 deletions(-) create mode 100644 change/@acedatacloud-hub-3f7b468d-823d-4219-b31b-12abca70ebf7.json rename src/components/{common/ApiStatus.vue => application/Status.vue} (76%) rename src/components/midjourney/{ChannelSelector.vue => ModeSelector.vue} (80%) create mode 100644 src/constants/chat.ts create mode 100644 src/constants/chatdoc.ts create mode 100644 src/constants/midjourney.ts delete mode 100644 src/constants/role.ts rename src/{operators/api/models.ts => models/api.ts} (80%) rename src/{operators/application/models.ts => models/application.ts} (82%) rename src/{operators/auth/models.ts => models/auth.ts} (100%) rename src/{operators/chat/models.ts => models/chat.ts} (57%) rename src/{operators/chatdoc/models.ts => models/chatdoc.ts} (95%) create mode 100644 src/models/common.ts rename src/{operators/distribution/models.ts => models/distribution.ts} (96%) create mode 100644 src/models/index.ts rename src/{operators/midjourney/models.ts => models/midjourney.ts} (65%) rename src/{operators/order/models.ts => models/order.ts} (92%) create mode 100644 src/models/service.ts rename src/{operators/usage/models.ts => models/usage.ts} (91%) rename src/{operators/user/models.ts => models/user.ts} (100%) rename src/operators/{api/operator.ts => api.ts} (90%) delete mode 100644 src/operators/api/index.ts rename src/operators/{application/operator.ts => application.ts} (90%) delete mode 100644 src/operators/application/index.ts rename src/operators/{auth/operator.ts => auth.ts} (90%) create mode 100644 src/operators/chat.ts delete mode 100644 src/operators/chat/constants.ts delete mode 100644 src/operators/chat/index.ts delete mode 100644 src/operators/chat/operator.ts rename src/operators/{chatdoc/operator.ts => chatdoc.ts} (95%) delete mode 100644 src/operators/chatdoc/constants.ts delete mode 100644 src/operators/chatdoc/index.ts rename src/operators/{instance.ts => common.ts} (100%) rename src/operators/{distribution/operator.ts => distribution.ts} (96%) delete mode 100644 src/operators/distribution/index.ts create mode 100644 src/operators/midjourney.ts delete mode 100644 src/operators/midjourney/constants.ts delete mode 100644 src/operators/midjourney/index.ts delete mode 100644 src/operators/midjourney/operator.ts rename src/operators/{order/operator.ts => order.ts} (96%) delete mode 100644 src/operators/order/index.ts create mode 100644 src/operators/service.ts rename src/operators/{usage/operator.ts => usage.ts} (92%) delete mode 100644 src/operators/usage/contants.ts delete mode 100644 src/operators/usage/index.ts rename src/operators/{user/operator.ts => user.ts} (88%) delete mode 100644 src/operators/user/index.ts diff --git a/change/@acedatacloud-hub-3f7b468d-823d-4219-b31b-12abca70ebf7.json b/change/@acedatacloud-hub-3f7b468d-823d-4219-b31b-12abca70ebf7.json new file mode 100644 index 00000000..52d26c4f --- /dev/null +++ b/change/@acedatacloud-hub-3f7b468d-823d-4219-b31b-12abca70ebf7.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "migrate to new architecture", + "packageName": "@acedatacloud/hub", + "email": "cqc@cuiqingcai.com", + "dependentChangeType": "patch" +} diff --git a/src/components/application/Confirm.vue b/src/components/application/Confirm.vue index 662783a2..0adba480 100644 --- a/src/components/application/Confirm.vue +++ b/src/components/application/Confirm.vue @@ -1,29 +1,30 @@ @@ -31,11 +32,10 @@ diff --git a/src/operators/api/models.ts b/src/models/api.ts similarity index 80% rename from src/operators/api/models.ts rename to src/models/api.ts index 7747ff35..73ccfb79 100644 --- a/src/operators/api/models.ts +++ b/src/models/api.ts @@ -1,3 +1,5 @@ +import { IService } from './service'; + export interface IForm { queries?: { [key: string]: string; @@ -53,28 +55,28 @@ export enum IApiUnit { COUNT = 'Count' } +export interface IApiPrice { + data: any[]; + spans: [number, number, number, number][]; + columns: { + key: string; + label: string; + }[]; +} + export interface IApi { id: string; - path: string; - endpoint: string; - price?: number; - unit?: IApiUnit; + name?: string; title?: string; + definition?: any; introduction?: string; - applied_count?: number; - application_id?: string; - free_amount?: number; - applied?: boolean; + price?: IApiPrice; tags?: string[]; - request: IRequest; - request_id: string; - responses: IResponse[]; - response_ids: string[]; - document_id?: string; - packages?: IPackage[]; + service?: IService; service_id?: string; created_at?: string; updated_at?: string; + stage?: string; } export interface IApiListResponse { diff --git a/src/operators/application/models.ts b/src/models/application.ts similarity index 82% rename from src/operators/application/models.ts rename to src/models/application.ts index ceb50aa6..4e9d82fa 100644 --- a/src/operators/application/models.ts +++ b/src/models/application.ts @@ -1,4 +1,4 @@ -import { IApi } from '../api'; +import { IService } from './service'; export enum IApplicationType { API = 'Api' @@ -21,15 +21,13 @@ export interface ICredential { export interface IApplication { id?: string; - api?: IApi; type?: IApplicationType; - api_id?: string; - proxy_id?: string; - api_key?: string; + service_id?: string; + service?: IService; user_id?: string; remaining_amount?: number; used_amount?: number; - credential?: ICredential; + credentials?: ICredential[]; created_at?: string; updated_at?: string; } diff --git a/src/operators/auth/models.ts b/src/models/auth.ts similarity index 100% rename from src/operators/auth/models.ts rename to src/models/auth.ts diff --git a/src/operators/chat/models.ts b/src/models/chat.ts similarity index 57% rename from src/operators/chat/models.ts rename to src/models/chat.ts index 905ad2f7..ed0616fe 100644 --- a/src/operators/chat/models.ts +++ b/src/models/chat.ts @@ -1,23 +1,20 @@ import { ROLE_ASSISTANT, ROLE_SYSTEM, ROLE_USER } from '@/constants'; import { - CHAT_MODEL_NAME_CHATGPT, - CHAT_MODEL_NAME_CHATGPT4, - CHAT_MODEL_NAME_CHATGPT4_BROWSING, - CHAT_MODEL_NAME_CHATGPT4_VISION, - CHAT_MODEL_NAME_CHATGPT_16K, - CHAT_MODEL_NAME_CHATGPT_BROWSING -} from './constants'; + CHAT_MODEL_NAME_GPT_3_5, + CHAT_MODEL_NAME_GPT_3_5_BROWSING, + CHAT_MODEL_NAME_GPT_4, + CHAT_MODEL_NAME_GPT_4_BROWSING, + CHAT_MODEL_NAME_GPT_4_VISION +} from '@/constants'; export type IChatModelName = - | typeof CHAT_MODEL_NAME_CHATGPT - | typeof CHAT_MODEL_NAME_CHATGPT4 - | typeof CHAT_MODEL_NAME_CHATGPT_16K - | typeof CHAT_MODEL_NAME_CHATGPT_BROWSING - | typeof CHAT_MODEL_NAME_CHATGPT4_BROWSING - | typeof CHAT_MODEL_NAME_CHATGPT4_VISION; + | typeof CHAT_MODEL_NAME_GPT_3_5 + | typeof CHAT_MODEL_NAME_GPT_3_5_BROWSING + | typeof CHAT_MODEL_NAME_GPT_4 + | typeof CHAT_MODEL_NAME_GPT_4_BROWSING + | typeof CHAT_MODEL_NAME_GPT_4_VISION; export interface IChatModel { - apiId: string; name: IChatModelName; displayName: string; description: string; @@ -25,7 +22,7 @@ export interface IChatModel { interface IError { code: string; - detail?: string; + message?: string; } export enum IChatMessageState { @@ -57,42 +54,36 @@ export interface IChatConversation { new?: boolean; } -export interface IChatAskOptions { - stream?: (response: IChatAskResponse) => void; - token: string; - endpoint: string; - path: string; -} - export interface IChatConversationOptions { - endpoint: string; - path: string; + stream?: (response: IChatConversationResponse) => void; + token: string; } -export interface IChatAskRequest { - question: string; +export interface IChatConversationRequest { + id?: string; + question?: string; references?: string[]; stateful?: boolean; - conversation_id?: string; + messages?: IChatMessage[]; + action?: IChatConversationAction; + model: IChatModelName; } -export interface IChatAskResponse { +export interface IChatConversationResponse { answer: string; delta_answer: string; - conversation_id?: string; + id?: string; +} + +export interface IChatConversationsResponse { + items: IChatConversation[]; + count: number; } export enum IChatConversationAction { + CHAT = 'chat', RETRIEVE = 'retrieve', UPDATE = 'update', DELETE = 'delete', RETRIEVE_BATCH = 'retrieve_batch' } - -export interface IChatConversationRequest { - action: IChatConversationAction; - id: string; - messages?: IChatMessage[]; -} - -export type IChatConversationResponse = IChatConversation; diff --git a/src/operators/chatdoc/models.ts b/src/models/chatdoc.ts similarity index 95% rename from src/operators/chatdoc/models.ts rename to src/models/chatdoc.ts index ce07606e..d54e6d98 100644 --- a/src/operators/chatdoc/models.ts +++ b/src/models/chatdoc.ts @@ -65,7 +65,10 @@ export interface IChatdocRepositoryRequest extends IChatdocRepository { } export interface IChatdocRepositoryResponse extends IChatdocRepository {} -export type IChatdocRepositoriesResponse = IChatdocRepository[]; +export type IChatdocRepositoriesResponse = { + items: IChatdocRepository[]; + count: number; +}; export type IChatdocDocumentsResponse = IChatdocDocument[]; export interface IChatdocChatResponse { diff --git a/src/models/common.ts b/src/models/common.ts new file mode 100644 index 00000000..d6e72253 --- /dev/null +++ b/src/models/common.ts @@ -0,0 +1,6 @@ +export enum Status { + Request = 'Request', + Success = 'Success', + Error = 'Error', + None = 'None' +} diff --git a/src/operators/distribution/models.ts b/src/models/distribution.ts similarity index 96% rename from src/operators/distribution/models.ts rename to src/models/distribution.ts index eb16cea5..717d0cb6 100644 --- a/src/operators/distribution/models.ts +++ b/src/models/distribution.ts @@ -1,4 +1,4 @@ -import { IOrder } from '../order'; +import { IOrder } from './order'; export interface IDistributionHistory { id: string; diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 00000000..3b5bd202 --- /dev/null +++ b/src/models/index.ts @@ -0,0 +1,12 @@ +export * from './common'; +export * from './api'; +export * from './application'; +export * from './auth'; +export * from './chat'; +export * from './chatdoc'; +export * from './distribution'; +export * from './midjourney'; +export * from './order'; +export * from './usage'; +export * from './user'; +export * from './service'; diff --git a/src/operators/midjourney/models.ts b/src/models/midjourney.ts similarity index 65% rename from src/operators/midjourney/models.ts rename to src/models/midjourney.ts index 701e77d4..57863b3d 100644 --- a/src/operators/midjourney/models.ts +++ b/src/models/midjourney.ts @@ -1,6 +1,5 @@ -export interface IMidjourneyChannel { +export interface IMidjourneyMode { icon: string; - apiId: string; name: string; displayName: string; } @@ -21,16 +20,18 @@ export interface IMidjourneyPreset { export enum MidjourneyImagineAction { GENERATE = 'generate', - UPSAMPLE1 = 'upsample1', - UPSAMPLE2 = 'upsample2', - UPSAMPLE3 = 'upsample3', - UPSAMPLE4 = 'upsample4', + UPSCALE1 = 'upscale1', + UPSCALE2 = 'upscale2', + UPSCALE3 = 'upscale3', + UPSCALE4 = 'upscale4', VARIATION1 = 'variation1', VARIATION2 = 'variation2', VARIATION3 = 'variation3', VARIATION4 = 'variation4', - HIGH_VARIATION = 'high_variation', - LOW_VARIATION = 'low_variation', + VARIATION_STRONG = 'variation_strong', + VARIATION_SUBTLE = 'variation_subtle', + UPSCALE_SUBTLE = 'upscale_subtle', + UPSCALE_CREATIVE = 'upscale_creative', ZOOM_OUT_2X = 'zoom_out_2x', ZOOM_OUT_1_5X = 'zoom_out_1_5x', SQUARE = 'square', @@ -39,10 +40,12 @@ export enum MidjourneyImagineAction { PAN_DOWN = 'pan_down', PAN_RIGHT = 'pan_right', REROLL = 'reroll', - UPSAMPLE_2X = 'upsample_2x', - UPSAMPLE_4X = 'upsample_4x', - REDO_UPSAMPLE_2X = 'redo_upsample_2x', - REDO_UPSAMPLE_4X = 'redo_upsample_4x' + UPSCALE_2X = 'upscale_2x', + UPSCALE_4X = 'upscale_4x', + REDO_UPSCALE_2X = 'redo_upscale_2x', + REDO_UPSCALE_4X = 'redo_upscale_4x', + REDO_UPSCALE_SUBTLE = 'redo_upscale_subtle', + REDO_UPSCALE_CREATIVE = 'redo_upscale_creative' } export enum MidjourneyImagineState { @@ -52,8 +55,15 @@ export enum MidjourneyImagineState { FAILED = 'failed' } +export enum MidjourneyImagineMode { + FAST = 'fast', + RELAX = 'relax', + TURBO = 'turbo' +} + export interface IMidjourneyImagineRequest { action?: MidjourneyImagineAction; + mode?: MidjourneyImagineMode; prompt?: string; image_id?: string; translation?: boolean; @@ -77,11 +87,19 @@ export interface IMidjourneyImagineResponse { export interface IMidjourneyImagineTask { id: string; created_at?: string; + mode: MidjourneyImagineMode; request?: IMidjourneyImagineRequest; response?: IMidjourneyImagineResponse; state?: MidjourneyImagineState; } +export type IMidjourneyImagineTaskResponse = IMidjourneyImagineTask; + +export interface IMidjourneyImagineTasksResponse { + items: IMidjourneyImagineTask[]; + count: number; +} + export interface IMidjourneyImagineOptions { stream?: (response: IMidjourneyImagineResponse) => void; token?: string; diff --git a/src/operators/order/models.ts b/src/models/order.ts similarity index 92% rename from src/operators/order/models.ts rename to src/models/order.ts index 57128a55..d1a6aa0b 100644 --- a/src/operators/order/models.ts +++ b/src/models/order.ts @@ -1,4 +1,4 @@ -import { IApplication } from '../application'; +import { IApplication } from './application'; export enum OrderState { PENDING = 'Pending', diff --git a/src/models/service.ts b/src/models/service.ts new file mode 100644 index 00000000..05834a94 --- /dev/null +++ b/src/models/service.ts @@ -0,0 +1,28 @@ +import { IApi, IPackage } from './api'; + +export interface IService { + id: string; + title: string; + unit?: string; + price?: number; + description?: string; + free_amount?: number; + applied_count?: number; + applied?: boolean; + tags?: string[]; + thumbnail?: string; + introduction?: string; + apis?: IApi[]; + api_ids?: string[]; + packages?: IPackage[]; + package_ids?: string[]; + created_at?: string; + updated_at?: string; +} + +export interface IServiceListResponse { + count: number; + items: IService[]; +} + +export type IServiceDetailResponse = IService; diff --git a/src/operators/usage/models.ts b/src/models/usage.ts similarity index 91% rename from src/operators/usage/models.ts rename to src/models/usage.ts index 3a8dfbd9..34c57c04 100644 --- a/src/operators/usage/models.ts +++ b/src/models/usage.ts @@ -1,4 +1,4 @@ -import { IApi } from '../api'; +import { IApi } from './api'; export interface IApiUsage { id?: string; diff --git a/src/operators/user/models.ts b/src/models/user.ts similarity index 100% rename from src/operators/user/models.ts rename to src/models/user.ts diff --git a/src/operators/api/operator.ts b/src/operators/api.ts similarity index 90% rename from src/operators/api/operator.ts rename to src/operators/api.ts index 8ebd3b25..60a0ad99 100644 --- a/src/operators/api/operator.ts +++ b/src/operators/api.ts @@ -1,6 +1,6 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { IApi, IApiDetailResponse, IApiListResponse } from '../api/models'; +import { httpClient } from './common'; +import { IApi, IApiDetailResponse, IApiListResponse } from '@/models'; export interface IApiQuery { limit?: number; diff --git a/src/operators/api/index.ts b/src/operators/api/index.ts deleted file mode 100644 index 4a6cbae5..00000000 --- a/src/operators/api/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './models'; -export * from './operator'; diff --git a/src/operators/application/operator.ts b/src/operators/application.ts similarity index 90% rename from src/operators/application/operator.ts rename to src/operators/application.ts index ffa07a8b..1062568c 100644 --- a/src/operators/application/operator.ts +++ b/src/operators/application.ts @@ -1,13 +1,13 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { IApplication, IApplicationDetailResponse, IApplicationListResponse, IApplicationType } from './models'; +import { httpClient } from './common'; +import { IApplication, IApplicationDetailResponse, IApplicationListResponse, IApplicationType } from '@/models'; export interface IApplicationQuery { user_id?: string; offset?: number; limit?: number; type?: IApplicationType; - api_id?: string | string[]; + service_id?: string; ordering?: string; } diff --git a/src/operators/application/index.ts b/src/operators/application/index.ts deleted file mode 100644 index 4a6cbae5..00000000 --- a/src/operators/application/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './models'; -export * from './operator'; diff --git a/src/operators/auth/operator.ts b/src/operators/auth.ts similarity index 90% rename from src/operators/auth/operator.ts rename to src/operators/auth.ts index 288a16b1..8fa249bb 100644 --- a/src/operators/auth/operator.ts +++ b/src/operators/auth.ts @@ -1,6 +1,6 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { ITokenResponse, IToken, IOAuthTokenRequest, IOAuthTokenResponse } from './models'; +import { httpClient } from './common'; +import { ITokenResponse, IToken, IOAuthTokenRequest, IOAuthTokenResponse } from '@/models'; import { getBaseUrlAuth } from '@/utils'; class AuthOperator { diff --git a/src/operators/chat.ts b/src/operators/chat.ts new file mode 100644 index 00000000..aea292b7 --- /dev/null +++ b/src/operators/chat.ts @@ -0,0 +1,129 @@ +import axios, { AxiosProgressEvent, AxiosResponse } from 'axios'; +import { + IChatConversation, + IChatConversationAction, + IChatConversationOptions, + IChatConversationRequest, + IChatConversationResponse, + IChatConversationsResponse +} from '@/models'; +import { BASE_URL_API } from '@/constants'; + +class ChatOperator { + async chatConversation( + data: IChatConversationRequest, + options: IChatConversationOptions + ): Promise> { + return await axios.post('/aichat/conversations', data, { + headers: { + authorization: `Bearer ${options.token}`, + accept: 'application/x-ndjson', + 'content-type': 'application/json' + }, + baseURL: BASE_URL_API, + responseType: 'stream', + onDownloadProgress: ({ event }: AxiosProgressEvent) => { + const response = event.target.response; + const lines = response.split('\r\n').filter((line: string) => !!line); + const lastLine = lines[lines.length - 1]; + if (lastLine) { + const jsonData = JSON.parse(lastLine); + if (options?.stream) { + options?.stream(jsonData as IChatConversationResponse); + } + } + } + }); + } + + async getConversation( + id: string | undefined, + options: IChatConversationOptions + ): Promise> { + return await axios.post( + `/aichat/conversations`, + { + action: IChatConversationAction.RETRIEVE, + id: id + }, + { + headers: { + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } + + async getConversations( + filter: { + ids?: string[]; + applicationId?: string; + }, + options: IChatConversationOptions + ): Promise> { + return await axios.post( + `/aichat/conversations`, + { + action: IChatConversationAction.RETRIEVE_BATCH, + ...(filter.ids + ? { + ids: filter.ids + } + : {}), + ...(filter.applicationId + ? { + application_id: filter.applicationId + } + : {}) + }, + { + headers: { + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } + + async deleteConversation(id: string, options: IChatConversationOptions): Promise> { + return await axios.post( + `/aichat/conversations`, + { + action: IChatConversationAction.DELETE, + id: id + }, + { + headers: { + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } + + async updateConversation( + payload: IChatConversation, + options: IChatConversationOptions + ): Promise> { + return await axios.post( + `/aichat/conversations`, + { + action: IChatConversationAction.UPDATE, + ...payload + }, + { + headers: { + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } +} + +export const chatOperator = new ChatOperator(); diff --git a/src/operators/chat/constants.ts b/src/operators/chat/constants.ts deleted file mode 100644 index c5a25f33..00000000 --- a/src/operators/chat/constants.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { IChatModel } from './models'; - -export const CHAT_MODEL_NAME_CHATGPT = 'chatgpt'; -export const CHAT_MODEL_NAME_CHATGPT4 = 'chatgpt4'; -export const CHAT_MODEL_NAME_CHATGPT_16K = 'chatgpt-16k'; -export const CHAT_MODEL_NAME_CHATGPT_BROWSING = 'chatgpt-browsing'; -export const CHAT_MODEL_NAME_CHATGPT4_BROWSING = 'chatgpt4-browsing'; -export const CHAT_MODEL_NAME_CHATGPT4_VISION = 'chatgpt4-vision'; - -export const API_ID_CHATGPT = '1d58971c-e3cd-4713-a3ce-854a731adb14'; -export const API_ID_CHATGPT_16K = 'bf93bb28-55a7-4428-ad82-156bf410f4e2'; -export const API_ID_CHATGPT_BROWSING = '12271e2e-794f-4079-a714-f68dd0df7808'; -export const API_ID_CHATGPT4 = '1c4e8fa3-362b-4e0a-b0fd-9ff9fc173b77'; -export const API_ID_CHATGPT4_BROWSING = 'a61de51b-d0d0-48a2-9a17-1d4986d5d497'; -export const API_ID_CHATGPT4_VISION = '098c6e4a-14ae-4ff1-8d2f-0968532a4638'; - -export const CHAT_MODEL_CHATGPT: IChatModel = { - apiId: API_ID_CHATGPT, - name: CHAT_MODEL_NAME_CHATGPT, - displayName: '3.5 - 标准', - description: '3.5 标准模型,输入约 2 千汉字' -}; - -export const CHAT_MODEL_CHATGPT_16K: IChatModel = { - apiId: API_ID_CHATGPT_16K, - name: CHAT_MODEL_NAME_CHATGPT_16K, - displayName: '3.5 - 16K', - description: '3.5 16K 模型,输入约 8 千汉字' -}; - -export const CHAT_MODEL_CHATGPT_BROWSING: IChatModel = { - apiId: API_ID_CHATGPT_BROWSING, - name: CHAT_MODEL_NAME_CHATGPT_BROWSING, - displayName: '3.5 - 联网', - description: '3.5 联网模型,额外支持实时联网搜索问答' -}; - -export const CHAT_MODEL_CHATGPT4: IChatModel = { - apiId: API_ID_CHATGPT4, - name: CHAT_MODEL_NAME_CHATGPT4, - displayName: '4.0 - 标准', - description: '4.0 标准模型,输入约 4 千汉字' -}; - -export const CHAT_MODEL_CHATGPT4_BROWSING: IChatModel = { - apiId: API_ID_CHATGPT4_BROWSING, - name: CHAT_MODEL_NAME_CHATGPT4_BROWSING, - displayName: '4.0 - 联网', - description: '4.0 联网模型,支持实时联网搜索问答' -}; - -export const CHAT_MODEL_CHATGPT4_VISION: IChatModel = { - apiId: API_ID_CHATGPT4_VISION, - name: CHAT_MODEL_NAME_CHATGPT4_VISION, - displayName: '4.0 - 视觉', - description: '4.0 视觉模型,支持图片输入和识别' -}; diff --git a/src/operators/chat/index.ts b/src/operators/chat/index.ts deleted file mode 100644 index 81e17a8b..00000000 --- a/src/operators/chat/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './models'; -export * from './operator'; -export * from './constants'; diff --git a/src/operators/chat/operator.ts b/src/operators/chat/operator.ts deleted file mode 100644 index c8e39094..00000000 --- a/src/operators/chat/operator.ts +++ /dev/null @@ -1,100 +0,0 @@ -import axios, { AxiosProgressEvent, AxiosResponse } from 'axios'; -import { - IChatAskOptions, - IChatAskRequest, - IChatAskResponse, - IChatConversation, - IChatConversationAction -} from './models'; -import { BASE_URL_API } from '@/constants'; - -class ChatOperator { - async askQuestion(data: IChatAskRequest, options: IChatAskOptions): Promise> { - return await axios.post(options.path, data, { - headers: { - authorization: `Bearer ${options.token}`, - accept: 'application/x-ndjson', - 'content-type': 'application/json' - }, - baseURL: options.endpoint, - responseType: 'stream', - onDownloadProgress: ({ event }: AxiosProgressEvent) => { - const response = event.target.response; - const lines = response.split('\r\n').filter((line: string) => !!line); - const lastLine = lines[lines.length - 1]; - if (lastLine) { - const jsonData = JSON.parse(lastLine); - if (options?.stream) { - options?.stream(jsonData as IChatAskResponse); - } - } - } - }); - } - - async getConversation(id: string | undefined): Promise> { - return await axios.post( - `/chatgpt/conversations`, - { - action: IChatConversationAction.RETRIEVE, - id: id - }, - { - headers: { - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } - - async getConversations(ids: string[]): Promise> { - return await axios.post( - `/chatgpt/conversations`, - { - action: IChatConversationAction.RETRIEVE_BATCH, - ids: ids - }, - { - headers: { - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } - - async deleteConversation(id: string): Promise> { - return await axios.post( - `/chatgpt/conversations`, - { - action: IChatConversationAction.DELETE, - id: id - }, - { - headers: { - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } - - async updateConversation(payload: IChatConversation): Promise> { - return await axios.post( - `/chatgpt/conversations`, - { - action: IChatConversationAction.UPDATE, - ...payload - }, - { - headers: { - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } -} - -export const chatOperator = new ChatOperator(); diff --git a/src/operators/chatdoc/operator.ts b/src/operators/chatdoc.ts similarity index 95% rename from src/operators/chatdoc/operator.ts rename to src/operators/chatdoc.ts index 3837b3da..f207d687 100644 --- a/src/operators/chatdoc/operator.ts +++ b/src/operators/chatdoc.ts @@ -7,7 +7,7 @@ import { IChatdocDocumentsResponse, IChatdocRepositoriesResponse, IChatdocRepositoryResponse -} from './models'; +} from '@/models'; import { ACTION_RETRIEVE_ALL, ACTION_UPDATE, BASE_URL_API } from '@/constants'; import { ACTION_CREATE, ACTION_DELETE, ACTION_RETRIEVE, ACTION_RETRIEVE_BATCH } from '@/constants'; @@ -128,12 +128,24 @@ class ChatdocOperator { ); } - async getRepositories(ids: string[]): Promise> { + async getRepositories(filter: { + ids?: string[]; + applicationId?: string; + }): Promise> { return await axios.post( `/chatdoc/repositories`, { action: ACTION_RETRIEVE_BATCH, - ids + ...(filter.ids + ? { + ids: filter.ids + } + : {}), + ...(filter.applicationId + ? { + application_id: filter.applicationId + } + : {}) }, { headers: { diff --git a/src/operators/chatdoc/constants.ts b/src/operators/chatdoc/constants.ts deleted file mode 100644 index 60bf2841..00000000 --- a/src/operators/chatdoc/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const API_ID_CHATDOC_REPOSITORIES = 'e22e9e3f-5594-4c48-9284-c1847c22c65f'; -export const API_ID_CHATDOC_DOCUMENTS = 'afc7917f-d89f-4dc9-95c2-863936b02cad'; -export const API_ID_CHATDOC_CONVERSATIONS = 'afc7917f-d89f-4dc9-95c2-863936b02cad'; -export const API_ID_CHATDOC_CHAT = '099eafc8-8167-4557-b8f2-47867ca76e24'; diff --git a/src/operators/chatdoc/index.ts b/src/operators/chatdoc/index.ts deleted file mode 100644 index 4a6cbae5..00000000 --- a/src/operators/chatdoc/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './models'; -export * from './operator'; diff --git a/src/operators/instance.ts b/src/operators/common.ts similarity index 100% rename from src/operators/instance.ts rename to src/operators/common.ts diff --git a/src/operators/distribution/operator.ts b/src/operators/distribution.ts similarity index 96% rename from src/operators/distribution/operator.ts rename to src/operators/distribution.ts index 58f35c66..2c38661f 100644 --- a/src/operators/distribution/operator.ts +++ b/src/operators/distribution.ts @@ -1,11 +1,11 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; +import { httpClient } from './common'; import { IDistributionHistoryListResponse, IDistributionLevelListResponse, IDistributionStatusDetailResponse, IDistributionStatusListResponse -} from './models'; +} from '@/models'; export interface IDistributionHistoryQuery { user_id?: string; diff --git a/src/operators/distribution/index.ts b/src/operators/distribution/index.ts deleted file mode 100644 index 2e04d2d9..00000000 --- a/src/operators/distribution/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './operator'; -export * from './models'; diff --git a/src/operators/index.ts b/src/operators/index.ts index d8e4c031..d5f75ac5 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -1,4 +1,4 @@ -export * from './instance'; +export * from './common'; export * from './application'; export * from './user'; export * from './chat'; @@ -8,3 +8,5 @@ export * from './api'; export * from './order'; export * from './distribution'; export * from './chatdoc'; +export * from './auth'; +export * from './service'; diff --git a/src/operators/midjourney.ts b/src/operators/midjourney.ts new file mode 100644 index 00000000..2dd14582 --- /dev/null +++ b/src/operators/midjourney.ts @@ -0,0 +1,87 @@ +import axios, { AxiosResponse } from 'axios'; +import { + IMidjourneyImagineRequest, + IMidjourneyImagineResponse, + IMidjourneyImagineTask, + IMidjourneyImagineTaskResponse, + IMidjourneyImagineTasksResponse +} from '@/models'; +import { BASE_URL_API } from '@/constants'; + +class MidjourneyOperator { + async task(id: string, options: { token: string }): Promise> { + return await axios.post( + `/midjourney/tasks`, + { + action: 'retrieve', + id: id + }, + { + headers: { + accept: 'application/json', + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } + + async tasks( + filter: { ids?: string[]; applicationId?: string; limit?: number; offset?: number }, + options: { token: string } + ): Promise> { + return await axios.post( + `/midjourney/tasks`, + { + action: 'retrieve_batch', + ...(filter.ids + ? { + ids: filter.ids + } + : {}), + ...(filter.applicationId + ? { + application_id: filter.applicationId + } + : {}), + ...(filter.limit !== undefined + ? { + limit: filter.limit + } + : {}), + ...(filter.offset !== undefined + ? { + offset: filter.offset + } + : {}) + }, + { + headers: { + accept: 'application/json', + 'content-type': 'application/json', + authorization: `Bearer ${options.token}` + }, + baseURL: BASE_URL_API + } + ); + } + + async imagine( + data: IMidjourneyImagineRequest, + options: { + token: string; + } + ): Promise> { + return await axios.post('/midjourney/imagine', data, { + headers: { + authorization: `Bearer ${options.token}`, + 'content-type': 'application/json', + accept: 'application/json' + }, + baseURL: BASE_URL_API + }); + } +} + +export const midjourneyOperator = new MidjourneyOperator(); diff --git a/src/operators/midjourney/constants.ts b/src/operators/midjourney/constants.ts deleted file mode 100644 index d11e29d1..00000000 --- a/src/operators/midjourney/constants.ts +++ /dev/null @@ -1,31 +0,0 @@ -import i18n from '@/i18n'; -import { IMidjourneyChannel } from './models'; - -export const MIDJOURNEY_CHANNEL_NAME_FAST = 'fast'; -export const MIDJOURNEY_CHANNEL_NAME_RELAX = 'relax'; -export const MIDJOURNEY_CHANNEL_NAME_TURBO = 'turbo'; - -export const API_ID_MIDJOURNEY_FAST = '9a628863-8879-462b-bbee-5dc46505b733'; -export const API_ID_MIDJOURNEY_RELAX = 'c58713f3-fef7-4c18-824c-9f76b5a07a7f'; -export const API_ID_MIDJOURNEY_TURBO = '62ec82bd-7de3-427f-b71a-ab3551ac7677'; - -export const MIDJOURNEY_CHANNEL_FAST: IMidjourneyChannel = { - icon: 'fa-solid fa-wind', - apiId: API_ID_MIDJOURNEY_FAST, - name: MIDJOURNEY_CHANNEL_NAME_FAST, - displayName: i18n.global.t('midjourney.button.fast') -}; - -export const MIDJOURNEY_CHANNEL_RELAX: IMidjourneyChannel = { - icon: 'fa-solid fa-mug-saucer', - apiId: API_ID_MIDJOURNEY_RELAX, - name: MIDJOURNEY_CHANNEL_NAME_RELAX, - displayName: i18n.global.t('midjourney.button.relax') -}; - -export const MIDJOURNEY_CHANNEL_TURBO: IMidjourneyChannel = { - icon: 'fa-solid fa-bolt', - apiId: API_ID_MIDJOURNEY_TURBO, - name: MIDJOURNEY_CHANNEL_NAME_TURBO, - displayName: i18n.global.t('midjourney.button.turbo') -}; diff --git a/src/operators/midjourney/index.ts b/src/operators/midjourney/index.ts deleted file mode 100644 index 47497e4d..00000000 --- a/src/operators/midjourney/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './constants'; -export * from './models'; -export * from './operator'; diff --git a/src/operators/midjourney/operator.ts b/src/operators/midjourney/operator.ts deleted file mode 100644 index 334df2c2..00000000 --- a/src/operators/midjourney/operator.ts +++ /dev/null @@ -1,72 +0,0 @@ -import axios, { AxiosProgressEvent, AxiosResponse } from 'axios'; -import { IMidjourneyImagineRequest, IMidjourneyImagineResponse, IMidjourneyImagineTask } from './models'; -import { BASE_URL_API } from '@/constants'; - -class MidjourneyOperator { - async task(id: string): Promise> { - return await axios.post( - `/midjourney/tasks`, - { - action: 'retrieve', - id: id - }, - { - headers: { - accept: 'application/json', - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } - - async tasks(ids: string[]): Promise> { - return await axios.post( - `/midjourney/tasks`, - { - action: 'retrieve_batch', - ids: ids - }, - { - headers: { - accept: 'application/json', - 'content-type': 'application/json' - }, - baseURL: BASE_URL_API - } - ); - } - - async imagine( - data: IMidjourneyImagineRequest, - options: { - stream?: (response: IMidjourneyImagineResponse) => void; - token: string; - endpoint: string; - path: string; - } - ): Promise> { - return await axios.post(options.path, data, { - headers: { - authorization: `Bearer ${options.token}`, - accept: 'application/x-ndjson', - 'content-type': 'application/json' - }, - baseURL: options.endpoint, - responseType: 'stream', - onDownloadProgress: ({ event }: AxiosProgressEvent) => { - const response = event.target.response; - const lines = response.split('\r\n').filter((line: string) => !!line); - const lastLine = lines[lines.length - 1]; - if (lastLine) { - const jsonData = JSON.parse(lastLine); - if (options?.stream) { - options?.stream(jsonData as IMidjourneyImagineResponse); - } - } - } - }); - } -} - -export const midjourneyOperator = new MidjourneyOperator(); diff --git a/src/operators/order/operator.ts b/src/operators/order.ts similarity index 96% rename from src/operators/order/operator.ts rename to src/operators/order.ts index b141e11d..0bb4f056 100644 --- a/src/operators/order/operator.ts +++ b/src/operators/order.ts @@ -1,6 +1,6 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { IOrder, IOrderDetailResponse, IOrderListResponse } from './models'; +import { httpClient } from './common'; +import { IOrder, IOrderDetailResponse, IOrderListResponse } from '@/models'; export interface IOrderQuery { user_id?: string; diff --git a/src/operators/order/index.ts b/src/operators/order/index.ts deleted file mode 100644 index 4a6cbae5..00000000 --- a/src/operators/order/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './models'; -export * from './operator'; diff --git a/src/operators/service.ts b/src/operators/service.ts new file mode 100644 index 00000000..674d45b9 --- /dev/null +++ b/src/operators/service.ts @@ -0,0 +1,37 @@ +import { AxiosResponse } from 'axios'; +import { httpClient } from './common'; +import { IService, IServiceDetailResponse, IServiceListResponse } from '@/models'; + +export interface IServiceQuery { + limit?: number; + offset?: number; + ordering?: string; +} + +class ServiceOperator { + key = 'services'; + + async getAll(query: IServiceQuery): Promise> { + return await httpClient.get(`/${this.key}/`, { + params: query + }); + } + + async get(id: string): Promise> { + return await httpClient.get(`/${this.key}/${id}`); + } + + async create(data: IService): Promise> { + return await httpClient.post(`/${this.key}/`, data); + } + + async update(id: string, data: IService): Promise> { + return await httpClient.put(`/${this.key}/${id}`, data); + } + + async delete(id: string): Promise> { + return await httpClient.delete(`/${this.key}/${id}`); + } +} + +export const serviceOperator = new ServiceOperator(); diff --git a/src/operators/usage/operator.ts b/src/operators/usage.ts similarity index 92% rename from src/operators/usage/operator.ts rename to src/operators/usage.ts index 3ac71372..e5478c90 100644 --- a/src/operators/usage/operator.ts +++ b/src/operators/usage.ts @@ -1,6 +1,6 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { IApiUsageDetailResponse, IApiUsageListResponse } from './models'; +import { httpClient } from './common'; +import { IApiUsageDetailResponse, IApiUsageListResponse } from '@/models'; export interface IApiUsageQuery { user_id?: string; diff --git a/src/operators/usage/contants.ts b/src/operators/usage/contants.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/operators/usage/index.ts b/src/operators/usage/index.ts deleted file mode 100644 index 2e04d2d9..00000000 --- a/src/operators/usage/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './operator'; -export * from './models'; diff --git a/src/operators/user/operator.ts b/src/operators/user.ts similarity index 88% rename from src/operators/user/operator.ts rename to src/operators/user.ts index 3e5a71f2..5defce45 100644 --- a/src/operators/user/operator.ts +++ b/src/operators/user.ts @@ -1,6 +1,6 @@ import { AxiosResponse } from 'axios'; -import { httpClient } from '../instance'; -import { IUserDetailResponse, IUser, IUserListResponse } from './models'; +import { httpClient } from './common'; +import { IUserDetailResponse, IUser, IUserListResponse } from '@/models'; export interface IInviteesQuery { offset?: number; diff --git a/src/operators/user/index.ts b/src/operators/user/index.ts deleted file mode 100644 index 4a6cbae5..00000000 --- a/src/operators/user/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './models'; -export * from './operator'; diff --git a/src/pages/auth/Callback.vue b/src/pages/auth/Callback.vue index 26df870f..688c3c71 100644 --- a/src/pages/auth/Callback.vue +++ b/src/pages/auth/Callback.vue @@ -1,7 +1,6 @@