alpha version

This commit is contained in:
Hk-Gosuto
2024-04-05 17:38:06 +08:00
parent ac57b2c770
commit 958ab02d1e
16 changed files with 1118 additions and 177 deletions

View File

@@ -7,7 +7,7 @@ import {
} from "../constant";
import { ChatMessage, ModelType, useAccessStore, useChatStore } from "../store";
import { ChatGPTApi } from "./platforms/openai";
import { FileApi } from "./platforms/utils";
import { FileApi, FileInfo } from "./platforms/utils";
import { GeminiProApi } from "./platforms/google";
export const ROLES = ["system", "user", "assistant"] as const;
export type MessageRole = (typeof ROLES)[number];
@@ -27,6 +27,7 @@ export interface MultimodalContent {
export interface RequestMessage {
role: MessageRole;
content: string | MultimodalContent[];
fileInfos?: FileInfo[];
}
export interface LLMConfig {
@@ -74,6 +75,7 @@ export interface ChatOptions {
}
export interface AgentChatOptions {
chatSessionId?: string;
messages: RequestMessage[];
config: LLMConfig;
agentConfig: LLMAgentConfig;
@@ -84,6 +86,13 @@ export interface AgentChatOptions {
onController?: (controller: AbortController) => void;
}
export interface CreateRAGStoreOptions {
chatSessionId: string;
fileInfos: FileInfo[];
onError?: (err: Error) => void;
onController?: (controller: AbortController) => void;
}
export interface LLMUsage {
used: number;
total: number;
@@ -106,6 +115,7 @@ export abstract class LLMApi {
abstract speech(options: SpeechOptions): Promise<ArrayBuffer>;
abstract transcription(options: TranscriptionOptions): Promise<string>;
abstract toolAgentChat(options: AgentChatOptions): Promise<void>;
abstract createRAGSore(options: CreateRAGStoreOptions): Promise<void>;
abstract usage(): Promise<LLMUsage>;
abstract models(): Promise<LLMModel[]>;
}
@@ -213,8 +223,8 @@ export function getHeaders(ignoreHeaders?: boolean) {
const apiKey = isGoogle
? accessStore.googleApiKey
: isAzure
? accessStore.azureApiKey
: accessStore.openaiApiKey;
? accessStore.azureApiKey
: accessStore.openaiApiKey;
const makeBearer = (s: string) =>
`${isGoogle || isAzure ? "" : "Bearer "}${s.trim()}`;