Skip to content

Commit

Permalink
Fix warn about missing OpenAI API key on local deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Jul 10, 2023
1 parent c3dcc74 commit fb0b1d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules/llms/llm.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function callChatGenerateWithFunctions(llmId: DLLMId, messages: VCh
}


function getLLMAndVendorOrThrow(llmId: string) {
function getLLMAndVendorOrThrow(llmId: DLLMId) {
const llm = useModelsStore.getState().llms.find(llm => llm.id === llmId);
const vendor = findVendorById(llm?._source.vId);
if (!llm || !vendor) throw new Error(`callChat: Vendor not found for LLM ${llmId}`);
Expand Down
7 changes: 5 additions & 2 deletions src/modules/llms/openai/openai.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ async function openaiPOST<TBody, TOut>(access: AccessSchema, body: TBody, apiPat
export function openAIAccess(access: AccessSchema, apiPath: string): { headers: HeadersInit, url: string } {
// API key
const oaiKey = access.oaiKey || process.env.OPENAI_API_KEY || '';
if (!oaiKey) throw new Error('Missing OpenAI API Key. Add it on the UI (Models Setup) or server side (your deployment).');

// Organization ID
const oaiOrg = access.oaiOrg || process.env.OPENAI_API_ORG_ID || '';
Expand All @@ -218,9 +217,13 @@ export function openAIAccess(access: AccessSchema, apiPath: string): { headers:
// Helicone key
const heliKey = access.heliKey || process.env.HELICONE_API_KEY || '';

// warn if no key - only for OpenAI hosts
if (!oaiKey && oaiHost.indexOf('api.openai.com') !== -1)
throw new Error('Missing OpenAI API Key. Add it on the UI (Models Setup) or server side (your deployment).');

return {
headers: {
Authorization: `Bearer ${oaiKey}`,
...(oaiKey && { Authorization: `Bearer ${oaiKey}` }),
'Content-Type': 'application/json',
...(oaiOrg && { 'OpenAI-Organization': oaiOrg }),
...(heliKey && { 'Helicone-Auth': `Bearer ${heliKey}` }),
Expand Down

1 comment on commit fb0b1d0

@vercel
Copy link

@vercel vercel bot commented on fb0b1d0 Jul 10, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

big-agi – ./

get.big-agi.com
big-agi-git-main-enricoros.vercel.app
big-agi-enricoros.vercel.app

Please sign in to comment.