Skip to content

Commit

Permalink
Log a debug message the first time checking OpenAI settings fails wit…
Browse files Browse the repository at this point in the history
…h e.g. a NetworkError

This will help users debug connectivity or LLM related issues.
  • Loading branch information
sd2k committed Aug 1, 2023
1 parent b060e32 commit e4b61c4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/llms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { isLiveChannelMessageEvent, LiveChannelAddress, LiveChannelMessageEvent, LiveChannelScope } from "@grafana/data";
import { getBackendSrv, getGrafanaLiveSrv } from "@grafana/runtime";
import { getBackendSrv, getGrafanaLiveSrv, logDebug } from "@grafana/runtime";

import { Observable } from "rxjs";
import { filter, map, takeWhile } from "rxjs/operators";
Expand Down Expand Up @@ -227,6 +227,8 @@ export function streamChatCompletions(request: ChatCompletionsRequest): Observab
);
}

let loggedWarning = false;

/**
* Check if the OpenAI API is enabled via the LLM plugin.
*/
Expand All @@ -236,7 +238,12 @@ export const enabled = async () => {
showSuccessAlert: false, showErrorAlert: false,
});
return settings.enabled && (settings?.secureJsonFields?.openAIKey ?? false);
} catch (_e) {
} catch (e) {
if (!loggedWarning) {
logDebug(String(e));
logDebug('Failed to check if OpenAI is enabled. This is expected if the Grafana LLM plugin is not installed, and the above error can be ignored.');
loggedWarning = true;
}
return false;
}
}

0 comments on commit e4b61c4

Please sign in to comment.