From 43c5411265a8d48edaca5c03ad0e98b428fc99a8 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Thu, 24 Apr 2025 22:19:27 +0800 Subject: [PATCH] feat(webui): implement provider, platform, pipeline api request methods --- web_ui/src/app/infra/api/api-types/index.ts | 92 ++++++++++++++++++ web_ui/src/app/infra/http/HttpClient.ts | 101 +++++++++++++++++++- 2 files changed, 191 insertions(+), 2 deletions(-) diff --git a/web_ui/src/app/infra/api/api-types/index.ts b/web_ui/src/app/infra/api/api-types/index.ts index ce30d80b..d5615c9f 100644 --- a/web_ui/src/app/infra/api/api-types/index.ts +++ b/web_ui/src/app/infra/api/api-types/index.ts @@ -9,3 +9,95 @@ export interface I18nText { zh_CN: string; } +export interface ApiRespProviderRequesters { + requesters: Requester[]; +} + +export interface ApiRespProviderRequester { + requester: Requester; +} + +export interface Requester { + name: string; + label: I18nText; + description: I18nText; + icon?: string; + spec: object; +} + +export interface ApiRespProviderLLMModels { + models: LLMModel[]; +} + +export interface ApiRespProviderLLMModel { + model: LLMModel; +} + +export interface LLMModel { + name: string; + description: string; + uuid: string; + requester: string; + requester_config: object; + extra_args: object; + api_keys: string[]; + abilities: string[]; + created_at: string; + updated_at: string; +} + +export interface ApiRespPipelines { + pipelines: Pipeline[]; +} + +export interface ApiRespPipeline { + pipeline: Pipeline; +} + +export interface Pipeline { + uuid: string; + name: string; + description: string; + for_version: string; + config: object; + stages: string[]; + created_at: string; + updated_at: string; +} + +export interface ApiRespPlatformAdapters { + adapters: Adapter[]; +} + +export interface ApiRespPlatformAdapter { + adapter: Adapter; +} + +export interface Adapter { + name: string; + label: I18nText; + description: I18nText; + icon?: string; + spec: object; +} + +export interface ApiRespPlatformBots { + bots: Bot[]; +} + +export interface ApiRespPlatformBot { + bot: Bot; +} + +export interface Bot { + uuid: string; + name: string; + description: string; + enable: boolean; + adapter: string; + adapter_config: object; + use_pipeline_name: string; + use_pipeline_uuid: string; + created_at: string; + updated_at: string; +} \ No newline at end of file diff --git a/web_ui/src/app/infra/http/HttpClient.ts b/web_ui/src/app/infra/http/HttpClient.ts index e765e539..8618f973 100644 --- a/web_ui/src/app/infra/http/HttpClient.ts +++ b/web_ui/src/app/infra/http/HttpClient.ts @@ -1,8 +1,13 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios' +import { + ApiResponse, ApiRespProviderRequesters, ApiRespProviderRequester, ApiRespProviderLLMModels, + ApiRespProviderLLMModel, LLMModel, ApiRespPipelines, ApiRespPipeline, Pipeline, ApiRespPlatformAdapters, + ApiRespPlatformAdapter, ApiRespPlatformBots, ApiRespPlatformBot, Bot +} from '../api/api-types' type JSONValue = string | number | boolean | JSONObject | JSONArray | null interface JSONObject { [key: string]: JSONValue } -interface JSONArray extends Array {} +interface JSONArray extends Array { } export interface ResponseData { code: number @@ -42,7 +47,7 @@ class HttpClient { return "" } // 客户端环境 - return "" + return "" } // 获取Session @@ -172,6 +177,98 @@ class HttpClient { public delete(url: string, config?: RequestConfig) { return this.request({ method: 'delete', url, ...config }) } + + // real api request implementation + // ============ Provider API ============ + public getProviderRequesters(): Promise> { + return this.get('/api/v1/provider/requesters') + } + + public getProviderRequester(name: string): Promise> { + return this.get(`/api/v1/provider/requesters/${name}`) + } + + public getProviderRequesterIconURL(name: string): string { + return `/api/v1/provider/requesters/${name}/icon` + } + + // ============ Provider Model LLM ============ + public getProviderLLMModels(): Promise> { + return this.get('/api/v1/provider/models/llm') + } + + public getProviderLLMModel(uuid: string): Promise> { + return this.get(`/api/v1/provider/models/llm/${uuid}`) + } + + public createProviderLLMModel(model: LLMModel): Promise> { + return this.post('/api/v1/provider/models/llm', model) + } + + public deleteProviderLLMModel(uuid: string): Promise> { + return this.delete(`/api/v1/provider/models/llm/${uuid}`) + } + + // ============ Pipeline API ============ + public getGeneralPipelineMetadata(): Promise> { // as designed, this method will be deprecated, and only for developer to check the prefered config schema + return this.get('/api/v1/pipelines/_/metadata') + } + + public getPipelines(): Promise> { + return this.get('/api/v1/pipelines') + } + + public getPipeline(uuid: string): Promise> { + return this.get(`/api/v1/pipelines/${uuid}`) + } + + public createPipeline(pipeline: Pipeline): Promise> { + return this.post('/api/v1/pipelines', pipeline) + } + + public updatePipeline(uuid: string, pipeline: Pipeline): Promise> { + return this.put(`/api/v1/pipelines/${uuid}`, pipeline) + } + + public deletePipeline(uuid: string): Promise> { + return this.delete(`/api/v1/pipelines/${uuid}`) + } + + // ============ Platform API ============ + public getAdapters(): Promise> { + return this.get('/api/v1/platform/adapters') + } + + public getAdapter(name: string): Promise> { + return this.get(`/api/v1/platform/adapters/${name}`) + } + + public getAdapterIconURL(name: string): string { + return `/api/v1/platform/adapters/${name}/icon` + } + + // ============ Platform Bots ============ + public getBots(): Promise> { + return this.get('/api/v1/platform/bots') + } + + public getBot(uuid: string): Promise> { + return this.get(`/api/v1/platform/bots/${uuid}`) + } + + public createBot(bot: Bot): Promise> { + return this.post('/api/v1/platform/bots', bot) + } + + public updateBot(uuid: string, bot: Bot): Promise> { + return this.put(`/api/v1/platform/bots/${uuid}`, bot) + } + + public deleteBot(uuid: string): Promise> { + return this.delete(`/api/v1/platform/bots/${uuid}`) + } + + // ============ Plugins API ============ } export const httpClient = new HttpClient()