Skip to content

Commit

Permalink
[access] Warn when proper env vars for model access are not set
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhancock committed Nov 26, 2024
1 parent 14dc240 commit 89da1fa
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 24 deletions.
55 changes: 33 additions & 22 deletions ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Tabs from './components/Tabs';
import MoreMenu from './components/MoreMenu';
import { Bird } from './components/ui/icons';
import LoadingGoose from './components/LoadingGoose';
import { ApiKeyWarning } from './components/ApiKeyWarning';
// import fakeToolInvocations from './fixtures/tool-calls-and-results.json';

export interface Chat {
Expand Down Expand Up @@ -225,6 +226,9 @@ function ChatContent({
}

export default function ChatWindow() {
// Check if API key is missing from the window arguments
const apiCredsMissing = window.electron.getConfig().apiCredsMissing;

// Get initial query and history from URL parameters
const searchParams = new URLSearchParams(window.location.search);
const initialQuery = searchParams.get('initialQuery');
Expand Down Expand Up @@ -259,30 +263,37 @@ export default function ChatWindow() {

return (
<div className="relative w-screen h-screen overflow-hidden bg-transparent flex flex-col">
{/* Always render ChatContent but control its visibility */}
<div style={{ display: mode === 'expanded' ? 'block' : 'none' }}>
<Routes>
<Route
path="/chat/:id"
element={
<ChatContent
key={selectedChatId}
chats={chats}
setChats={setChats}
selectedChatId={selectedChatId}
setSelectedChatId={setSelectedChatId}
initialQuery={initialQuery}
setProgressMessage={setProgressMessage}
setWorking={setWorking}
{apiCredsMissing ? (
<div className="w-full h-full">
<ApiKeyWarning className="w-full h-full" />
</div>
) : (
<>
<div style={{ display: mode === 'expanded' ? 'block' : 'none' }}>
<Routes>
<Route
path="/chat/:id"
element={
<ChatContent
key={selectedChatId}
chats={chats}
setChats={setChats}
selectedChatId={selectedChatId}
setSelectedChatId={setSelectedChatId}
initialQuery={initialQuery}
setProgressMessage={setProgressMessage}
setWorking={setWorking}
/>
}
/>
}
/>
<Route path="*" element={<Navigate to="/chat/1" replace />} />
</Routes>
</div>
<Route path="*" element={<Navigate to="/chat/1" replace />} />
</Routes>
</div>

{/* Always render WingView but control its visibility */}
<WingView onExpand={toggleMode} progressMessage={progressMessage} working={working} />
{/* Always render WingView but control its visibility */}
<WingView onExpand={toggleMode} progressMessage={progressMessage} working={working} />
</>
)}
</div>
);
}
Expand Down
43 changes: 43 additions & 0 deletions ui/desktop/src/components/ApiKeyWarning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { Card } from './ui/card';
import { Bird } from './ui/icons';

interface ApiKeyWarningProps {
className?: string;
}

export function ApiKeyWarning({ className }: ApiKeyWarningProps) {
return (
<Card className={`flex flex-col items-center justify-center p-8 space-y-6 bg-card-gradient w-full h-full ${className}`}>
<div className="w-16 h-16">
<Bird />
</div>
<div className="text-center space-y-4">
<h2 className="text-2xl font-semibold text-gray-800">API Key Required</h2>
<div className="whitespace-pre-wrap">
To use Goose, you need to set some combination of the following env variables
<br />
<br />
# OpenAI
<br />
<br />
export GOOSE_PROVIDER__TYPE=openai<br />
GOOSE_PROVIDER__HOST=https://api.openai.com<br />
GOOSE_PROVIDER__MODEL=gpt-4o<br />
GOOSE_PROVIDER__API_KEY=...<br />
<br />
<br />
# Databricks + Claude
<br />
<br />
export GOOSE_PROVIDER__TYPE=databricks<br />
export GOOSE_PROVIDER__HOST=...<br />
export GOOSE_PROVIDER__MODEL="claude-3-5-sonnet-2"<br />
<br />
<br />
Please export these and restart the application.
</div>
</div>
</Card>
);
}
23 changes: 21 additions & 2 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,27 @@ if (started) app.quit();

declare var MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
declare var MAIN_WINDOW_VITE_NAME: string;
let appConfig = { GOOSE_SERVER__PORT: 3000, GOOSE_API_HOST: 'http://127.0.0.1' };

const checkApiCredentials = () => {
const isDatabricksConfigValid =
process.env.GOOSE_PROVIDER__TYPE === 'databricks' &&
process.env.GOOSE_PROVIDER__HOST &&
process.env.GOOSE_PROVIDER__MODEL;

const isOpenAIDirectConfigValid =
process.env.GOOSE_PROVIDER__TYPE === 'openai' &&
process.env.GOOSE_PROVIDER__HOST === 'https://api.openai.com' &&
process.env.GOOSE_PROVIDER__MODEL &&
process.env.GOOSE_PROVIDER__API_KEY;

return isDatabricksConfigValid || isOpenAIDirectConfigValid
};

let appConfig = {
GOOSE_SERVER__PORT: 3000,
GOOSE_API_HOST: 'http://127.0.0.1',
apiCredsMissing: !checkApiCredentials()
};

const createLauncher = () => {
const launcherWindow = new BrowserWindow({
Expand Down Expand Up @@ -173,7 +193,6 @@ const showWindow = () => {
});
};


app.whenReady().then(async () => {
// Load zsh environment variables in production mode only
const isProduction = app.isPackaged;
Expand Down
1 change: 1 addition & 0 deletions ui/desktop/src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contextBridge.exposeInMainWorld('appConfig', {
});

contextBridge.exposeInMainWorld('electron', {
getConfig: () => config,
hideWindow: () => ipcRenderer.send('hide-window'),
createChatWindow: (query) => ipcRenderer.send('create-chat-window', query),
logInfo: (txt) => ipcRenderer.send('logInfo', txt),
Expand Down
5 changes: 5 additions & 0 deletions ui/desktop/src/types/electron.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
interface IElectronAPI {
hideWindow: () => void;
createChatWindow: (query: string) => void;
getConfig: () => {
GOOSE_SERVER__PORT: number;
GOOSE_API_HOST: string;
apiCredsMissing: boolean;
};
}

declare global {
Expand Down

0 comments on commit 89da1fa

Please sign in to comment.