Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions ui/desktop/src/components/BottomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}) {
const [isModelMenuOpen, setIsModelMenuOpen] = useState(false);
const { currentModel } = useModel();
const { recentModels } = useRecentModels(); // Get recent models

Check warning on line 20 in ui/desktop/src/components/BottomMenu.tsx

View workflow job for this annotation

GitHub Actions / Lint Electron Desktop App

'recentModels' is assigned a value but never used. Allowed unused vars must match /^_/u
const dropdownRef = useRef<HTMLDivElement>(null);

const [isGooseModeMenuOpen, setIsGooseModeMenuOpen] = useState(false);
Expand Down Expand Up @@ -118,10 +118,7 @@
};
}, [isGooseModeMenuOpen]);

let envModelProvider = null;
if (window.electron.getConfig().GOOSE_MODEL && window.electron.getConfig().GOOSE_PROVIDER) {
envModelProvider = `${window.electron.getConfig().GOOSE_MODEL} - ${window.electron.getConfig().GOOSE_PROVIDER}`;
}
// Removed the envModelProvider code that was checking for environment variables

return (
<div className="flex justify-between items-center text-textSubtle relative bg-bgSubtle border-t border-borderSubtle text-xs pl-4 h-[40px] pb-1 align-middle">
Expand Down Expand Up @@ -167,9 +164,7 @@
className="flex items-center cursor-pointer"
onClick={() => setIsModelMenuOpen(!isModelMenuOpen)}
>
<span>
{envModelProvider || (currentModel?.alias ?? currentModel?.name) || 'Select Model'}
</span>
<span>{(currentModel?.alias ?? currentModel?.name) || 'Select Model'}</span>
{isModelMenuOpen ? (
<ChevronDown className="w-4 h-4 ml-1" />
) : (
Expand Down
69 changes: 46 additions & 23 deletions ui/desktop/src/utils/providerUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getApiUrl, getSecretKey } from '../config';
import { loadAndAddStoredExtensions } from '../extensions';
import { GOOSE_PROVIDER } from '../env_vars';
import { GOOSE_PROVIDER, GOOSE_MODEL } from '../env_vars';
import { Model } from '../components/settings/models/ModelContext';
import { gooseModels } from '../components/settings/models/GooseModels';

export function getStoredProvider(config: any): string | null {
return config.GOOSE_PROVIDER || localStorage.getItem(GOOSE_PROVIDER);
Expand Down Expand Up @@ -31,28 +32,6 @@ export interface Provider {
requiredKeys: string[]; // List of required keys
}

export async function getProvidersList(): Promise<Provider[]> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unused function

const response = await fetch(getApiUrl('/agent/providers'), {
method: 'GET',
});

if (!response.ok) {
throw new Error(`Failed to fetch providers: ${response.statusText}`);
}

const data = await response.json();
console.log('Raw API Response:', data); // Log the raw response

// Format the response into an array of providers
return data.map((item: any) => ({
id: item.id, // Root-level ID
name: item.details?.name || 'Unknown Provider', // Nested name in details
description: item.details?.description || 'No description available.', // Nested description
models: item.details?.models || [], // Nested models array
requiredKeys: item.details?.required_keys || [], // Nested required keys array
}));
}

const addAgent = async (provider: string, model: string) => {
const response = await fetch(getApiUrl('/agent'), {
method: 'POST',
Expand Down Expand Up @@ -92,6 +71,10 @@ export const initializeSystem = async (provider: string, model: string) => {
console.log('initializing agent with provider', provider, 'model', model);
await addAgent(provider.toLowerCase().replace(/ /g, '_'), model);

// Sync the model state with React
const syncedModel = syncModelWithAgent(provider, model);
console.log('Model synced with React state:', syncedModel);

// Extend the system prompt with desktop-specific information
const response = await fetch(getApiUrl('/agent/prompt'), {
method: 'POST',
Expand All @@ -116,3 +99,43 @@ export const initializeSystem = async (provider: string, model: string) => {
throw error;
}
};

// This function ensures the agent initialization values and React model state stay in sync
const syncModelWithAgent = (provider: string, modelName: string): Model | null => {
console.log('Syncing model state with agent:', { provider, modelName });

// First, try to find a matching model in our predefined list
let matchingModel = gooseModels.find(
(m) => m.name === modelName && m.provider.toLowerCase() === provider.toLowerCase()
);

// If no match by exact name and provider, try just by provider
if (!matchingModel) {
matchingModel = gooseModels.find((m) => m.provider.toLowerCase() === provider.toLowerCase());

if (matchingModel) {
console.log('Found model by provider only:', matchingModel);
}
}

// If still no match, create a custom model
if (!matchingModel) {
console.log('No matching model found, creating custom model');
matchingModel = {
id: Date.now(),
name: modelName,
provider: provider,
alias: `${provider} - ${modelName}`,
};
}

// Update localStorage with the model
if (matchingModel) {
localStorage.setItem(GOOSE_PROVIDER, matchingModel.provider.toLowerCase());
localStorage.setItem(GOOSE_MODEL, JSON.stringify(matchingModel));

return matchingModel;
}

return null;
};
Loading