|
@@ -2,6 +2,7 @@ import { getClientConfig } from "../config/client";
|
|
import { ACCESS_CODE_PREFIX, Azure, ServiceProvider } from "../constant";
|
|
import { ACCESS_CODE_PREFIX, Azure, ServiceProvider } from "../constant";
|
|
import { ChatMessage, ModelType, useAccessStore } from "../store";
|
|
import { ChatMessage, ModelType, useAccessStore } from "../store";
|
|
import { ChatGPTApi } from "./platforms/openai";
|
|
import { ChatGPTApi } from "./platforms/openai";
|
|
|
|
+import { OauthUserApi } from "@/app/client/platforms/user";
|
|
|
|
|
|
export const ROLES = ["system", "user", "assistant"] as const;
|
|
export const ROLES = ["system", "user", "assistant"] as const;
|
|
export type MessageRole = (typeof ROLES)[number];
|
|
export type MessageRole = (typeof ROLES)[number];
|
|
@@ -49,6 +50,10 @@ export abstract class LLMApi {
|
|
abstract models(): Promise<LLMModel[]>;
|
|
abstract models(): Promise<LLMModel[]>;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+export abstract class UserApi {
|
|
|
|
+ abstract userinfo(): Promise<void>;
|
|
|
|
+}
|
|
|
|
+
|
|
type ProviderName = "openai" | "azure" | "claude" | "palm";
|
|
type ProviderName = "openai" | "azure" | "claude" | "palm";
|
|
|
|
|
|
interface Model {
|
|
interface Model {
|
|
@@ -72,9 +77,11 @@ interface ChatProvider {
|
|
|
|
|
|
export class ClientApi {
|
|
export class ClientApi {
|
|
public llm: LLMApi;
|
|
public llm: LLMApi;
|
|
|
|
+ public user: UserApi;
|
|
|
|
|
|
constructor() {
|
|
constructor() {
|
|
this.llm = new ChatGPTApi();
|
|
this.llm = new ChatGPTApi();
|
|
|
|
+ this.user = new OauthUserApi();
|
|
}
|
|
}
|
|
|
|
|
|
config() {}
|
|
config() {}
|
|
@@ -139,9 +146,12 @@ export function getHeaders() {
|
|
const makeBearer = (s: string) => `${isAzure ? "" : "Bearer "}${s.trim()}`;
|
|
const makeBearer = (s: string) => `${isAzure ? "" : "Bearer "}${s.trim()}`;
|
|
const validString = (x: string) => x && x.length > 0;
|
|
const validString = (x: string) => x && x.length > 0;
|
|
|
|
|
|
|
|
+ // console.log('ServiceProvider', accessStore.provider)
|
|
// use user's api key first
|
|
// use user's api key first
|
|
if (validString(apiKey)) {
|
|
if (validString(apiKey)) {
|
|
headers[authHeader] = makeBearer(apiKey);
|
|
headers[authHeader] = makeBearer(apiKey);
|
|
|
|
+ } else if (accessStore.provider === ServiceProvider.Oauth) {
|
|
|
|
+ headers[authHeader] = makeBearer(accessStore.accessToken);
|
|
} else if (
|
|
} else if (
|
|
accessStore.enabledAccessControl() &&
|
|
accessStore.enabledAccessControl() &&
|
|
validString(accessStore.accessCode)
|
|
validString(accessStore.accessCode)
|