Spaces:
Sleeping
Sleeping
Download backend/src/lib/userSettings.ts from bardd/mike-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/userSettings.ts
- Command line
-
hf download hf://spaces/bardd/mike-backend/backend/src/lib/userSettings.ts
-
curl -L -o userSettings.ts https://huggingface.co/spaces/bardd/mike-backend/resolve/main/backend/src/lib/userSettings.ts
1.76 kB
| import { createServerSupabase } from "./supabase"; | |
| import { | |
| resolveModel, | |
| DEFAULT_MAIN_MODEL, | |
| type UserApiKeys, | |
| } from "./llm"; | |
| import { isOperatorUser, normalizeModelForAccess } from "./modelAccess"; | |
| export type UserModelSettings = { | |
| model: string; | |
| title_model: string; | |
| tabular_model: string; | |
| api_keys: UserApiKeys; | |
| }; | |
| export async function getUserModelSettings( | |
| userId: string, | |
| db?: ReturnType<typeof createServerSupabase>, | |
| ): Promise<UserModelSettings> { | |
| const client = db ?? createServerSupabase(); | |
| const { data } = await client | |
| .from("user_profiles") | |
| .select("model, gemini_api_key, openai_api_key") | |
| .eq("user_id", userId) | |
| .single(); | |
| const api_keys: UserApiKeys = { | |
| gemini: data?.gemini_api_key?.trim() || process.env.GEMINI_API_KEY || null, | |
| openai: data?.openai_api_key?.trim() || process.env.OPENAI_API_KEY || null, | |
| }; | |
| const isOperator = await isOperatorUser(userId); | |
| const model = normalizeModelForAccess( | |
| resolveModel(data?.model, DEFAULT_MAIN_MODEL), | |
| isOperator, | |
| ); | |
| return { | |
| model, | |
| title_model: model, | |
| tabular_model: model, | |
| api_keys, | |
| }; | |
| } | |
| export async function getUserApiKeys( | |
| userId: string, | |
| db?: ReturnType<typeof createServerSupabase>, | |
| ): Promise<UserApiKeys> { | |
| const client = db ?? createServerSupabase(); | |
| const { data } = await client | |
| .from("user_profiles") | |
| .select("gemini_api_key, openai_api_key") | |
| .eq("user_id", userId) | |
| .single(); | |
| return { | |
| gemini: data?.gemini_api_key?.trim() || process.env.GEMINI_API_KEY || null, | |
| openai: data?.openai_api_key?.trim() || process.env.OPENAI_API_KEY || null, | |
| }; | |
| } | |