Files
AlphaPulse/web/src/apis/settings.ts
T
eezd 5db3ead883 Add AI chat with skills management and model provider settings
- Model providers for OpenAI and Anthropic message formats (e.g. via
  Sub2API), with API keys encrypted at rest and never returned
- Skills tree with markdown editing, priorities, drafts, publishing and
  rollback; only published skills enter the chat prompt
- Chat page with tool calls over collected news and Binance USD-M
  klines, a persisted CONTEXT.md, reset, and stop-generation support
- Chat may only create skill drafts and update CONTEXT.md; publishing,
  deleting, moving and priority changes stay with the user
2026-10-14 13:11:45 +08:00

59 lines
1.4 KiB
TypeScript

import { http } from "@/http"
export type Protocol = "openai" | "anthropic"
export interface Provider {
id: number
name: string
protocol: Protocol
base_url: string
api_key_hint: string
model: string
max_tokens: number
context_window: number
temperature: number | null
is_default: boolean
updated_at: string
}
export interface ProviderForm {
name: string
protocol: Protocol
base_url: string
/** 编辑时为空表示不修改 */
api_key: string
model: string
max_tokens: number
context_window: number
temperature: number | null
is_default: boolean
}
export interface TestResult {
ok: boolean
elapsed_ms: number
reply: string | null
error: string | null
}
export function listProviders(): Promise<Provider[]> {
return http.get("/settings/providers")
}
export function createProvider(body: ProviderForm): Promise<Provider> {
return http.post("/settings/providers", body)
}
export function patchProvider(id: number, body: Partial<ProviderForm>): Promise<Provider> {
return http.patch(`/settings/providers/${id}`, body)
}
export function deleteProvider(id: number): Promise<void> {
return http.delete(`/settings/providers/${id}`)
}
export function testProvider(id: number): Promise<TestResult> {
// 模型接口超时 120s 且 SDK 会重试,前端放宽等待时间
return http.post(`/settings/providers/${id}/test`, null, { timeout: 400000 })
}