Skip to content

Commit

Permalink
Assistant: ensure that ASSISTANT_API_KEY is a real synonym for OPEN_A…
Browse files Browse the repository at this point in the history
  • Loading branch information
jordigh committed Oct 1, 2024
1 parent 77194dc commit 858bd53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/server/lib/Assistance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ export class OpenAIAssistant implements Assistant {
private _maxTokens = process.env.ASSISTANT_MAX_TOKENS ?
parseInt(process.env.ASSISTANT_MAX_TOKENS, 10) : undefined;

public constructor() {
const apiKey = process.env.ASSISTANT_API_KEY || process.env.OPENAI_API_KEY;
public constructor(apiKey: string | undefined) {
const endpoint = process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT;
if (!apiKey && !endpoint) {
throw new Error('Please set either OPENAI_API_KEY or ASSISTANT_CHAT_COMPLETION_ENDPOINT');
Expand Down Expand Up @@ -485,11 +484,13 @@ class EchoAssistant implements Assistant {
* Instantiate an assistant, based on environment variables.
*/
export function getAssistant() {
if (process.env.OPENAI_API_KEY === 'test') {
const apiKey = process.env.ASSISTANT_API_KEY || process.env.OPENAI_API_KEY;

if (apiKey === 'test') {
return new EchoAssistant();
}
if (process.env.OPENAI_API_KEY || process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT) {
return new OpenAIAssistant();
return new OpenAIAssistant(apiKey);
}
throw new Error('Please set OPENAI_API_KEY or ASSISTANT_CHAT_COMPLETION_ENDPOINT');
}
Expand Down
4 changes: 3 additions & 1 deletion app/server/lib/sendAppPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export function makeGristConfig(options: MakeGristConfigOptions): GristLoadConfi
supportedLngs: readLoadedLngs(req?.i18n),
namespaces: readLoadedNamespaces(req?.i18n),
featureComments: isAffirmative(process.env.COMMENTS),
featureFormulaAssistant: Boolean(process.env.OPENAI_API_KEY || process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT),
featureFormulaAssistant: Boolean(process.env.OPENAI_API_KEY ||
process.env.ASSISTANT_API_KEY ||
process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT),
assistantService: process.env.OPENAI_API_KEY ? 'OpenAI' : undefined,
permittedCustomWidgets: getPermittedCustomWidgets(server),
supportEmail: SUPPORT_EMAIL,
Expand Down

0 comments on commit 858bd53

Please sign in to comment.