mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
Assistant: ensure that ASSISTANT_API_KEY is a real synonym for OPEN_AI_KEY
This was flagged as inconsistent in a community post. https://community.getgrist.com/t/does-the-ai-formula-assist-also-works-with-the-desktop-mac-app/5677/6
This commit is contained in:
parent
fb85f92382
commit
35a429d99e
@ -158,8 +158,7 @@ export class OpenAIAssistant implements Assistant {
|
|||||||
private _maxTokens = process.env.ASSISTANT_MAX_TOKENS ?
|
private _maxTokens = process.env.ASSISTANT_MAX_TOKENS ?
|
||||||
parseInt(process.env.ASSISTANT_MAX_TOKENS, 10) : undefined;
|
parseInt(process.env.ASSISTANT_MAX_TOKENS, 10) : undefined;
|
||||||
|
|
||||||
public constructor() {
|
public constructor(apiKey: string | undefined) {
|
||||||
const apiKey = process.env.ASSISTANT_API_KEY || process.env.OPENAI_API_KEY;
|
|
||||||
const endpoint = process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT;
|
const endpoint = process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT;
|
||||||
if (!apiKey && !endpoint) {
|
if (!apiKey && !endpoint) {
|
||||||
throw new Error('Please set either OPENAI_API_KEY or ASSISTANT_CHAT_COMPLETION_ENDPOINT');
|
throw new Error('Please set either OPENAI_API_KEY or ASSISTANT_CHAT_COMPLETION_ENDPOINT');
|
||||||
@ -485,11 +484,13 @@ class EchoAssistant implements Assistant {
|
|||||||
* Instantiate an assistant, based on environment variables.
|
* Instantiate an assistant, based on environment variables.
|
||||||
*/
|
*/
|
||||||
export function getAssistant() {
|
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();
|
return new EchoAssistant();
|
||||||
}
|
}
|
||||||
if (process.env.OPENAI_API_KEY || process.env.ASSISTANT_CHAT_COMPLETION_ENDPOINT) {
|
if (apiKey || 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');
|
throw new Error('Please set OPENAI_API_KEY or ASSISTANT_CHAT_COMPLETION_ENDPOINT');
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,9 @@ export function makeGristConfig(options: MakeGristConfigOptions): GristLoadConfi
|
|||||||
supportedLngs: readLoadedLngs(req?.i18n),
|
supportedLngs: readLoadedLngs(req?.i18n),
|
||||||
namespaces: readLoadedNamespaces(req?.i18n),
|
namespaces: readLoadedNamespaces(req?.i18n),
|
||||||
featureComments: isAffirmative(process.env.COMMENTS),
|
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,
|
assistantService: process.env.OPENAI_API_KEY ? 'OpenAI' : undefined,
|
||||||
permittedCustomWidgets: getPermittedCustomWidgets(server),
|
permittedCustomWidgets: getPermittedCustomWidgets(server),
|
||||||
supportEmail: SUPPORT_EMAIL,
|
supportEmail: SUPPORT_EMAIL,
|
||||||
|
Loading…
Reference in New Issue
Block a user