This commit is contained in:
eduardruzga
2024-12-16 11:07:22 +02:00
28 changed files with 467 additions and 194 deletions

View File

@@ -39,6 +39,8 @@ export function getAPIKey(cloudflareEnv: Env, provider: string, userApiKeys?: Re
return env.TOGETHER_API_KEY || cloudflareEnv.TOGETHER_API_KEY;
case 'xAI':
return env.XAI_API_KEY || cloudflareEnv.XAI_API_KEY;
case 'Perplexity':
return env.PERPLEXITY_API_KEY || cloudflareEnv.PERPLEXITY_API_KEY;
case 'Cohere':
return env.COHERE_API_KEY;
case 'AzureOpenAI':

View File

@@ -128,6 +128,15 @@ export function getXAIModel(apiKey: OptionalApiKey, model: string) {
return openai(model);
}
export function getPerplexityModel(apiKey: OptionalApiKey, model: string) {
const perplexity = createOpenAI({
baseURL: 'https://api.perplexity.ai/',
apiKey,
});
return perplexity(model);
}
export function getModel(
provider: string,
model: string,
@@ -170,6 +179,8 @@ export function getModel(
return getXAIModel(apiKey, model);
case 'Cohere':
return getCohereAIModel(apiKey, model);
case 'Perplexity':
return getPerplexityModel(apiKey, model);
default:
return getOllamaModel(baseURL, model);
}

View File

@@ -5,19 +5,42 @@ import {
isLocalModelsEnabled,
LOCAL_PROVIDERS,
providersStore,
latestBranch,
} from '~/lib/stores/settings';
import { useCallback, useEffect, useState } from 'react';
import Cookies from 'js-cookie';
import type { IProviderSetting, ProviderInfo } from '~/types/model';
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
import commit from '~/commit.json';
interface CommitData {
commit: string;
}
export function useSettings() {
const providers = useStore(providersStore);
const debug = useStore(isDebugMode);
const eventLogs = useStore(isEventLogsEnabled);
const isLocalModel = useStore(isLocalModelsEnabled);
const useLatest = useStore(latestBranch);
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
// Function to check if we're on stable version
const checkIsStableVersion = async () => {
try {
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
if (!stableResponse.ok) {
console.warn('Failed to fetch stable commit info');
return false;
}
const stableData = await stableResponse.json() as CommitData;
return commit.commit === stableData.commit;
} catch (error) {
console.warn('Error checking stable version:', error);
return false;
}
};
// reading values from cookies on mount
useEffect(() => {
const savedProviders = Cookies.get('providers');
@@ -60,6 +83,19 @@ export function useSettings() {
if (savedLocalModels) {
isLocalModelsEnabled.set(savedLocalModels === 'true');
}
// load latest branch setting from cookies or determine based on version
const savedLatestBranch = Cookies.get('useLatestBranch');
if (savedLatestBranch === undefined) {
// If setting hasn't been set by user, check version
checkIsStableVersion().then(isStable => {
const shouldUseLatest = !isStable;
latestBranch.set(shouldUseLatest);
Cookies.set('useLatestBranch', String(shouldUseLatest));
});
} else {
latestBranch.set(savedLatestBranch === 'true');
}
}, []);
// writing values to cookies on change
@@ -111,6 +147,12 @@ export function useSettings() {
Cookies.set('isLocalModelsEnabled', String(enabled));
}, []);
const enableLatestBranch = useCallback((enabled: boolean) => {
latestBranch.set(enabled);
logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`);
Cookies.set('useLatestBranch', String(enabled));
}, []);
return {
providers,
activeProviders,
@@ -121,5 +163,7 @@ export function useSettings() {
enableEventLogs,
isLocalModel,
enableLocalModels,
useLatestBranch: useLatest,
enableLatestBranch,
};
}

View File

@@ -46,3 +46,5 @@ export const isDebugMode = atom(false);
export const isEventLogsEnabled = atom(false);
export const isLocalModelsEnabled = atom(true);
export const latestBranch = atom(false);