Migrate new service (#1)
This commit is contained in:
1 parent
f13ca37d63
commit
28da0263dc
109 files changed
+1160
-1053
No files matched your search
@@ -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;
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,85 +0,0 @@
|
||||
export interface IForm {
|
||||
queries?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
body?: {
|
||||
[key: string]: string | object | boolean | number | object[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface ISchema {
|
||||
properties?: {
|
||||
[key: string]: ISchema;
|
||||
};
|
||||
items?: ISchema[];
|
||||
enum?: (string | number)[];
|
||||
type: 'object' | 'array' | 'string' | 'number' | 'boolean';
|
||||
title: string;
|
||||
optional?: boolean;
|
||||
example?: string | number;
|
||||
}
|
||||
|
||||
export interface IRequest {
|
||||
id: string;
|
||||
body: ISchema;
|
||||
headers: ISchema;
|
||||
queries: ISchema;
|
||||
params: ISchema;
|
||||
method: 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
||||
}
|
||||
|
||||
export interface IResponse {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
example?: string;
|
||||
is_success: boolean;
|
||||
error_code?: string;
|
||||
status_code: number;
|
||||
body: ISchema;
|
||||
headers: ISchema;
|
||||
}
|
||||
|
||||
export interface IPackage {
|
||||
id: string;
|
||||
amount: number;
|
||||
price: number;
|
||||
}
|
||||
|
||||
export enum IApiUnit {
|
||||
COUNT = 'Count'
|
||||
}
|
||||
|
||||
export interface IApi {
|
||||
id: string;
|
||||
path: string;
|
||||
endpoint: string;
|
||||
price?: number;
|
||||
unit?: IApiUnit;
|
||||
title?: string;
|
||||
introduction?: string;
|
||||
applied_count?: number;
|
||||
application_id?: string;
|
||||
free_amount?: number;
|
||||
applied?: boolean;
|
||||
tags?: string[];
|
||||
request: IRequest;
|
||||
request_id: string;
|
||||
responses: IResponse[];
|
||||
response_ids: string[];
|
||||
document_id?: string;
|
||||
packages?: IPackage[];
|
||||
service_id?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IApiListResponse {
|
||||
count: number;
|
||||
items: IApi[];
|
||||
}
|
||||
|
||||
export type IApiDetailResponse = IApi;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,42 +0,0 @@
|
||||
import { IApi } from '../api';
|
||||
|
||||
export enum IApplicationType {
|
||||
API = 'Api'
|
||||
}
|
||||
|
||||
export enum ICredentialType {
|
||||
TOKEN = 'Token',
|
||||
IDENTITY = 'Identity'
|
||||
}
|
||||
|
||||
export interface ICredential {
|
||||
type: ICredentialType;
|
||||
name?: string;
|
||||
token?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IApplication {
|
||||
id?: string;
|
||||
api?: IApi;
|
||||
type?: IApplicationType;
|
||||
api_id?: string;
|
||||
proxy_id?: string;
|
||||
api_key?: string;
|
||||
user_id?: string;
|
||||
remaining_amount?: number;
|
||||
used_amount?: number;
|
||||
credential?: ICredential;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IApplicationListResponse {
|
||||
count: number;
|
||||
items: IApplication[];
|
||||
}
|
||||
|
||||
export type IApplicationDetailResponse = IApplication;
|
||||
@@ -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 {
|
||||
@@ -1,16 +0,0 @@
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export interface ITokenResponse extends IToken {}
|
||||
|
||||
export interface IOAuthTokenRequest {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface IOAuthTokenResponse {
|
||||
access_token: string;
|
||||
expires_in: number;
|
||||
refresh_token: string;
|
||||
}
|
||||
@@ -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<AxiosResponse<IChatConversationResponse>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
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<AxiosResponse<IChatConversationsResponse>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
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();
|
||||
@@ -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 视觉模型,支持图片输入和识别'
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
export * from './constants';
|
||||
@@ -1,98 +0,0 @@
|
||||
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';
|
||||
|
||||
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;
|
||||
|
||||
export interface IChatModel {
|
||||
apiId: string;
|
||||
name: IChatModelName;
|
||||
displayName: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
interface IError {
|
||||
code: string;
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
export enum IChatMessageState {
|
||||
PENDING = 'pending',
|
||||
ANSWERING = 'answering',
|
||||
FINISHED = 'finished',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IChatMessageContentItem {
|
||||
type: string;
|
||||
text?: string;
|
||||
image_url?: string;
|
||||
}
|
||||
|
||||
export interface IChatMessage {
|
||||
state?: IChatMessageState;
|
||||
content?: string | IChatMessageContentItem[];
|
||||
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
|
||||
error?: IError;
|
||||
}
|
||||
|
||||
export interface IChatConversation {
|
||||
id: string;
|
||||
messages: IChatMessage[];
|
||||
title?: string;
|
||||
deleting?: boolean;
|
||||
editing?: boolean;
|
||||
new?: boolean;
|
||||
}
|
||||
|
||||
export interface IChatAskOptions {
|
||||
stream?: (response: IChatAskResponse) => void;
|
||||
token: string;
|
||||
endpoint: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface IChatConversationOptions {
|
||||
endpoint: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface IChatAskRequest {
|
||||
question: string;
|
||||
references?: string[];
|
||||
stateful?: boolean;
|
||||
conversation_id?: string;
|
||||
}
|
||||
|
||||
export interface IChatAskResponse {
|
||||
answer: string;
|
||||
delta_answer: string;
|
||||
conversation_id?: string;
|
||||
}
|
||||
|
||||
export enum IChatConversationAction {
|
||||
RETRIEVE = 'retrieve',
|
||||
UPDATE = 'update',
|
||||
DELETE = 'delete',
|
||||
RETRIEVE_BATCH = 'retrieve_batch'
|
||||
}
|
||||
|
||||
export interface IChatConversationRequest {
|
||||
action: IChatConversationAction;
|
||||
id: string;
|
||||
messages?: IChatMessage[];
|
||||
}
|
||||
|
||||
export type IChatConversationResponse = IChatConversation;
|
||||
@@ -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<AxiosResponse<IChatAskResponse>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
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<AxiosResponse<IChatConversation[]>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
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<AxiosResponse<IChatConversation>> {
|
||||
return await axios.post(
|
||||
`/chatgpt/conversations`,
|
||||
{
|
||||
action: IChatConversationAction.UPDATE,
|
||||
...payload
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
baseURL: BASE_URL_API
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const chatOperator = new ChatOperator();
|
||||
@@ -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<AxiosResponse<IChatdocRepositoriesResponse>> {
|
||||
async getRepositories(filter: {
|
||||
ids?: string[];
|
||||
applicationId?: string;
|
||||
}): Promise<AxiosResponse<IChatdocRepositoriesResponse>> {
|
||||
return await axios.post(
|
||||
`/chatdoc/repositories`,
|
||||
{
|
||||
action: ACTION_RETRIEVE_BATCH,
|
||||
ids
|
||||
...(filter.ids
|
||||
? {
|
||||
ids: filter.ids
|
||||
}
|
||||
: {}),
|
||||
...(filter.applicationId
|
||||
? {
|
||||
application_id: filter.applicationId
|
||||
}
|
||||
: {})
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -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';
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,76 +0,0 @@
|
||||
import { ACTION_CREATE, ACTION_DELETE, ACTION_UPDATE, ROLE_ASSISTANT, ROLE_SYSTEM, ROLE_USER } from '@/constants';
|
||||
|
||||
export interface IError {
|
||||
code: string;
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
export interface IChatdocRepository {
|
||||
id: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
deleting?: boolean;
|
||||
editing?: boolean;
|
||||
documents?: IChatdocDocument[];
|
||||
conversations?: IChatdocConversation[];
|
||||
}
|
||||
|
||||
export interface IChatdocDocument {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
file_url: string;
|
||||
file_name: string;
|
||||
}
|
||||
|
||||
export interface IChatdocConversation {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
messages: IChatdocMessage[];
|
||||
editing?: boolean;
|
||||
deleting?: boolean;
|
||||
}
|
||||
|
||||
export interface IChatdocMessage {
|
||||
content?: string;
|
||||
error?: IError;
|
||||
state?: IChatdocMessageState;
|
||||
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
|
||||
}
|
||||
|
||||
export enum IChatdocMessageState {
|
||||
PENDING = 'pending',
|
||||
ANSWERING = 'answering',
|
||||
FINISHED = 'finished',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IChatdocChatRequest {
|
||||
repository_id: string;
|
||||
messages: IChatdocMessage[];
|
||||
temperature?: number;
|
||||
knowledge_fallback?: boolean;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentRequest extends IChatdocDocument {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
callback_url?: string;
|
||||
}
|
||||
|
||||
export interface IChatdocDocumentResponse extends IChatdocDocument {}
|
||||
|
||||
export type IChatdocConversationsResponse = IChatdocConversation[];
|
||||
|
||||
export interface IChatdocRepositoryRequest extends IChatdocRepository {
|
||||
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
|
||||
}
|
||||
|
||||
export interface IChatdocRepositoryResponse extends IChatdocRepository {}
|
||||
export type IChatdocRepositoriesResponse = IChatdocRepository[];
|
||||
export type IChatdocDocumentsResponse = IChatdocDocument[];
|
||||
|
||||
export interface IChatdocChatResponse {
|
||||
answer: string;
|
||||
delta_answer: string;
|
||||
repository_id?: string;
|
||||
conversation_id?: string;
|
||||
}
|
||||
File renamed without changes.
@@ -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;
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './operator';
|
||||
export * from './models';
|
||||
@@ -1,54 +0,0 @@
|
||||
import { IOrder } from '../order';
|
||||
|
||||
export interface IDistributionHistory {
|
||||
id: string;
|
||||
user_id: string;
|
||||
invitee_id: string;
|
||||
order?: IOrder;
|
||||
order_id?: string;
|
||||
price: number;
|
||||
reward: number;
|
||||
percentage: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IDistributionLevel {
|
||||
id: string;
|
||||
level: number;
|
||||
threshold: number;
|
||||
percentage: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IDistributionStatus {
|
||||
id: string;
|
||||
user_id: string;
|
||||
price: number;
|
||||
reward: number;
|
||||
level_id?: string;
|
||||
level?: IDistributionLevel;
|
||||
percentage: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IDistributionStatusListResponse {
|
||||
count: number;
|
||||
items: IDistributionStatus[];
|
||||
}
|
||||
|
||||
export type IDistributionStatusDetailResponse = IDistributionStatus;
|
||||
|
||||
export interface IDistributionHistoryListResponse {
|
||||
count: number;
|
||||
items: IDistributionHistory[];
|
||||
}
|
||||
|
||||
export type IDistributionHistoryDetailResponse = IDistributionHistory;
|
||||
|
||||
export interface IDistributionLevelListResponse {
|
||||
count: number;
|
||||
items: IDistributionLevel[];
|
||||
}
|
||||
@@ -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';
|
||||
@@ -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<AxiosResponse<IMidjourneyImagineTaskResponse>> {
|
||||
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<AxiosResponse<IMidjourneyImagineTasksResponse>> {
|
||||
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<AxiosResponse<IMidjourneyImagineResponse>> {
|
||||
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();
|
||||
@@ -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')
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './constants';
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,90 +0,0 @@
|
||||
export interface IMidjourneyChannel {
|
||||
icon: string;
|
||||
apiId: string;
|
||||
name: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface IMidjourneyPreset {
|
||||
model?: string;
|
||||
ratio?: string;
|
||||
version?: string;
|
||||
stylize?: number;
|
||||
chaos?: number;
|
||||
advanced?: boolean;
|
||||
quality?: string;
|
||||
weird?: number;
|
||||
iw?: number;
|
||||
style?: string;
|
||||
translation?: boolean;
|
||||
}
|
||||
|
||||
export enum MidjourneyImagineAction {
|
||||
GENERATE = 'generate',
|
||||
UPSAMPLE1 = 'upsample1',
|
||||
UPSAMPLE2 = 'upsample2',
|
||||
UPSAMPLE3 = 'upsample3',
|
||||
UPSAMPLE4 = 'upsample4',
|
||||
VARIATION1 = 'variation1',
|
||||
VARIATION2 = 'variation2',
|
||||
VARIATION3 = 'variation3',
|
||||
VARIATION4 = 'variation4',
|
||||
HIGH_VARIATION = 'high_variation',
|
||||
LOW_VARIATION = 'low_variation',
|
||||
ZOOM_OUT_2X = 'zoom_out_2x',
|
||||
ZOOM_OUT_1_5X = 'zoom_out_1_5x',
|
||||
SQUARE = 'square',
|
||||
PAN_LEFT = 'pan_left',
|
||||
PAN_UP = 'pan_up',
|
||||
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'
|
||||
}
|
||||
|
||||
export enum MidjourneyImagineState {
|
||||
PENDING = 'pending',
|
||||
GENERATING = 'generating',
|
||||
FINISHED = 'finished',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineRequest {
|
||||
action?: MidjourneyImagineAction;
|
||||
prompt?: string;
|
||||
image_id?: string;
|
||||
translation?: boolean;
|
||||
callback_url?: string;
|
||||
application_id?: string;
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineResponse {
|
||||
task_id: string;
|
||||
progress: number;
|
||||
image_id: string;
|
||||
image_url: string;
|
||||
trace_id: string;
|
||||
raw_image_url: string;
|
||||
actions: MidjourneyImagineAction[];
|
||||
code?: string;
|
||||
detail?: string;
|
||||
success?: boolean;
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineTask {
|
||||
id: string;
|
||||
created_at?: string;
|
||||
request?: IMidjourneyImagineRequest;
|
||||
response?: IMidjourneyImagineResponse;
|
||||
state?: MidjourneyImagineState;
|
||||
}
|
||||
|
||||
export interface IMidjourneyImagineOptions {
|
||||
stream?: (response: IMidjourneyImagineResponse) => void;
|
||||
token?: string;
|
||||
endpoint?: string;
|
||||
path?: string;
|
||||
}
|
||||
@@ -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<AxiosResponse<IMidjourneyImagineTask>> {
|
||||
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<AxiosResponse<IMidjourneyImagineTask[]>> {
|
||||
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<AxiosResponse<IMidjourneyImagineResponse>> {
|
||||
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();
|
||||
@@ -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;
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,33 +0,0 @@
|
||||
import { IApplication } from '../application';
|
||||
|
||||
export enum OrderState {
|
||||
PENDING = 'Pending',
|
||||
PAID = 'Paid',
|
||||
EXPIRED = 'Expired',
|
||||
FAILED = 'Failed'
|
||||
}
|
||||
|
||||
export interface IOrder {
|
||||
id?: string;
|
||||
description?: string;
|
||||
state?: OrderState;
|
||||
price?: number;
|
||||
amount?: number;
|
||||
user_id?: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
application?: IApplication;
|
||||
application_id?: string;
|
||||
wechatpay_url?: string;
|
||||
pay_id?: string;
|
||||
pay_url?: string;
|
||||
alipay_url?: string;
|
||||
pay_way?: string;
|
||||
}
|
||||
|
||||
export interface IOrderListResponse {
|
||||
count: number;
|
||||
items: IOrder[];
|
||||
}
|
||||
|
||||
export type IOrderDetailResponse = IOrder;
|
||||
@@ -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<AxiosResponse<IServiceListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`, {
|
||||
params: query
|
||||
});
|
||||
}
|
||||
|
||||
async get(id: string): Promise<AxiosResponse<IServiceDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: IService): Promise<AxiosResponse<IServiceDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: string, data: IService): Promise<AxiosResponse<IServiceDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceOperator = new ServiceOperator();
|
||||
@@ -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;
|
||||
Whitespace-only changes.
@@ -1,2 +0,0 @@
|
||||
export * from './operator';
|
||||
export * from './models';
|
||||
@@ -1,19 +0,0 @@
|
||||
import { IApi } from '../api';
|
||||
|
||||
export interface IApiUsage {
|
||||
id?: string;
|
||||
api?: IApi;
|
||||
api_id?: string;
|
||||
application_id?: string;
|
||||
trace_id?: string;
|
||||
metadata?: any;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IApiUsageListResponse {
|
||||
count: number;
|
||||
items: IApiUsage[];
|
||||
}
|
||||
|
||||
export type IApiUsageDetailResponse = IApiUsage;
|
||||
@@ -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;
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -1,20 +0,0 @@
|
||||
export interface IUser {
|
||||
id?: string;
|
||||
username?: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
email?: string;
|
||||
nickname?: string;
|
||||
gender?: number;
|
||||
city?: string;
|
||||
province?: string;
|
||||
country?: string;
|
||||
avatar?: string;
|
||||
}
|
||||
|
||||
export interface IUserListResponse {
|
||||
count: number;
|
||||
items: IUser[];
|
||||
}
|
||||
|
||||
export interface IUserDetailResponse extends IUser {}
|
||||
Reference in new issue
Block a user