update api integration
This commit is contained in:
1 parent
7880b1d5d0
commit
8c1f3ab04d
15 files changed
+155
-127
No files matched your search
@@ -35,14 +35,6 @@ class ApplicationOperator {
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async rotateCredential(id: string): Promise<AxiosResponse<IApplicationDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/${id}/rotate-credential/`);
|
||||
}
|
||||
|
||||
async updateRemainingAmount(id: string, data: IApplication): Promise<AxiosResponse<IApplicationDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/${id}/update-remaining-amount/`, data);
|
||||
}
|
||||
}
|
||||
|
||||
export const applicationOperator = new ApplicationOperator();
|
||||
@@ -1,5 +1,6 @@
|
||||
export const API_ID_CHATGPT = '3333';
|
||||
export const API_ID_CHATGPT4 = '3333';
|
||||
export const API_ID_CHATGPT_BROWSING = '3333';
|
||||
export const API_ID_CHATGPT4_BROWSING = '3333';
|
||||
export const API_ID_CHATGPT_16k = '3333';
|
||||
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';
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
export * from './constants';
|
||||
@@ -48,5 +48,6 @@ export interface IChatResponse {
|
||||
|
||||
export interface IChatOptions {
|
||||
stream?: (response: IChatResponse) => void;
|
||||
api_id: string;
|
||||
token: string;
|
||||
endpoint?: string;
|
||||
}
|
||||
@@ -1,35 +1,25 @@
|
||||
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios';
|
||||
import { IChatOptions, IChatRequest, IChatResponse } from './models';
|
||||
import store from '@/store';
|
||||
import { IApplication } from '@/store/models';
|
||||
|
||||
class ChatOperator {
|
||||
async request(data: IChatRequest, config?: IChatOptions): Promise<AxiosResponse<IChatResponse>> {
|
||||
const applications: IApplication[] = store.getters.applications;
|
||||
// find related application
|
||||
const application = applications?.filter((application: IApplication) => {
|
||||
return (application.api_id = config?.api_id);
|
||||
})?.[0];
|
||||
if (!application) {
|
||||
return Promise.reject('no application');
|
||||
}
|
||||
const token = application?.credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
async request(data: IChatRequest, options: IChatOptions): Promise<AxiosResponse<IChatResponse>> {
|
||||
return await axios.post(`/chatgpt`, data, {
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
authorization: `Bearer ${options.token}`,
|
||||
accept: 'application/x-ndjson',
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
baseURL: options.endpoint,
|
||||
responseType: 'stream',
|
||||
onDownloadProgress: (event) => {
|
||||
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 (config?.stream) {
|
||||
config?.stream(jsonData as IChatResponse);
|
||||
if (options?.stream) {
|
||||
options?.stream(jsonData as IChatResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ const httpClient: AxiosInstance = axios.create({
|
||||
});
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.getters.accessToken;
|
||||
const accessToken = store.getters.token.access;
|
||||
if (!config.headers) {
|
||||
config.headers = {};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export interface IUser {
|
||||
id: string;
|
||||
id?: string;
|
||||
username?: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
@@ -10,15 +10,6 @@ export interface IUser {
|
||||
province?: string;
|
||||
country?: string;
|
||||
avatar?: string;
|
||||
type: 'user';
|
||||
}
|
||||
|
||||
export interface IBot {
|
||||
id?: string;
|
||||
username?: string;
|
||||
nickname?: string;
|
||||
avatar?: string;
|
||||
type: 'bot';
|
||||
}
|
||||
|
||||
export interface IUserDetailResponse extends IUser {}
|
||||
Reference in new issue
Block a user