mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-15 15:00:58 +00:00
feat(webui): implement provider, platform, pipeline api request methods
This commit is contained in:
@@ -9,3 +9,95 @@ export interface I18nText {
|
|||||||
zh_CN: string;
|
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;
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'
|
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
|
type JSONValue = string | number | boolean | JSONObject | JSONArray | null
|
||||||
interface JSONObject { [key: string]: JSONValue }
|
interface JSONObject { [key: string]: JSONValue }
|
||||||
interface JSONArray extends Array<JSONValue> {}
|
interface JSONArray extends Array<JSONValue> { }
|
||||||
|
|
||||||
export interface ResponseData<T = unknown> {
|
export interface ResponseData<T = unknown> {
|
||||||
code: number
|
code: number
|
||||||
@@ -42,7 +47,7 @@ class HttpClient {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// 客户端环境
|
// 客户端环境
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取Session
|
// 获取Session
|
||||||
@@ -172,6 +177,98 @@ class HttpClient {
|
|||||||
public delete<T = unknown>(url: string, config?: RequestConfig) {
|
public delete<T = unknown>(url: string, config?: RequestConfig) {
|
||||||
return this.request<T>({ method: 'delete', url, ...config })
|
return this.request<T>({ method: 'delete', url, ...config })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// real api request implementation
|
||||||
|
// ============ Provider API ============
|
||||||
|
public getProviderRequesters(): Promise<ApiResponse<ApiRespProviderRequesters>> {
|
||||||
|
return this.get('/api/v1/provider/requesters')
|
||||||
|
}
|
||||||
|
|
||||||
|
public getProviderRequester(name: string): Promise<ApiResponse<ApiRespProviderRequester>> {
|
||||||
|
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<ApiResponse<ApiRespProviderLLMModels>> {
|
||||||
|
return this.get('/api/v1/provider/models/llm')
|
||||||
|
}
|
||||||
|
|
||||||
|
public getProviderLLMModel(uuid: string): Promise<ApiResponse<ApiRespProviderLLMModel>> {
|
||||||
|
return this.get(`/api/v1/provider/models/llm/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
public createProviderLLMModel(model: LLMModel): Promise<ApiResponse<object>> {
|
||||||
|
return this.post('/api/v1/provider/models/llm', model)
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteProviderLLMModel(uuid: string): Promise<ApiResponse<object>> {
|
||||||
|
return this.delete(`/api/v1/provider/models/llm/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ Pipeline API ============
|
||||||
|
public getGeneralPipelineMetadata(): Promise<ApiResponse<object>> { // 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<ApiResponse<ApiRespPipelines>> {
|
||||||
|
return this.get('/api/v1/pipelines')
|
||||||
|
}
|
||||||
|
|
||||||
|
public getPipeline(uuid: string): Promise<ApiResponse<ApiRespPipeline>> {
|
||||||
|
return this.get(`/api/v1/pipelines/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
public createPipeline(pipeline: Pipeline): Promise<ApiResponse<object>> {
|
||||||
|
return this.post('/api/v1/pipelines', pipeline)
|
||||||
|
}
|
||||||
|
|
||||||
|
public updatePipeline(uuid: string, pipeline: Pipeline): Promise<ApiResponse<object>> {
|
||||||
|
return this.put(`/api/v1/pipelines/${uuid}`, pipeline)
|
||||||
|
}
|
||||||
|
|
||||||
|
public deletePipeline(uuid: string): Promise<ApiResponse<object>> {
|
||||||
|
return this.delete(`/api/v1/pipelines/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ Platform API ============
|
||||||
|
public getAdapters(): Promise<ApiResponse<ApiRespPlatformAdapters>> {
|
||||||
|
return this.get('/api/v1/platform/adapters')
|
||||||
|
}
|
||||||
|
|
||||||
|
public getAdapter(name: string): Promise<ApiResponse<ApiRespPlatformAdapter>> {
|
||||||
|
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<ApiResponse<ApiRespPlatformBots>> {
|
||||||
|
return this.get('/api/v1/platform/bots')
|
||||||
|
}
|
||||||
|
|
||||||
|
public getBot(uuid: string): Promise<ApiResponse<ApiRespPlatformBot>> {
|
||||||
|
return this.get(`/api/v1/platform/bots/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
public createBot(bot: Bot): Promise<ApiResponse<object>> {
|
||||||
|
return this.post('/api/v1/platform/bots', bot)
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateBot(uuid: string, bot: Bot): Promise<ApiResponse<object>> {
|
||||||
|
return this.put(`/api/v1/platform/bots/${uuid}`, bot)
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteBot(uuid: string): Promise<ApiResponse<object>> {
|
||||||
|
return this.delete(`/api/v1/platform/bots/${uuid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============ Plugins API ============
|
||||||
}
|
}
|
||||||
|
|
||||||
export const httpClient = new HttpClient()
|
export const httpClient = new HttpClient()
|
||||||
|
|||||||
Reference in New Issue
Block a user