Skip to content

Commit

Permalink
Track LLM app plugin version in a constant
Browse files Browse the repository at this point in the history
This will be exposed in the plugin health check from version
0.3.0 onwards, and will be very useful to enable backwards
compatibility in the @grafana/experimental package.

See grafana/grafana-llm-app#62 for the
health check PR and #82 for an example of why knowing the
version will be useful.
  • Loading branch information
sd2k committed Sep 22, 2023
1 parent e389d4f commit 4a8c5b5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
},
"dependencies": {
"@types/uuid": "^8.3.3",
"semver": "^7.5.4",
"uuid": "^8.3.2"
}
}
17 changes: 17 additions & 0 deletions src/llms/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
import { logWarning } from "@grafana/runtime";

import { SemVer } from "semver";

export const LLM_PLUGIN_ID = 'grafana-llm-app';
export const LLM_PLUGIN_ROUTE = `/api/plugins/${LLM_PLUGIN_ID}`;

// The LLM app was at version 0.2.0 before we added the health check.
// If the health check fails, or the details don't exist on the response,
// we should assume it's this older version.
export let LLM_PLUGIN_VERSION = new SemVer('0.2.0');

export function setLLMPluginVersion(version: string) {
try {
LLM_PLUGIN_VERSION = new SemVer(version);
} catch (e) {
logWarning('Failed to parse version of grafana-llm-app; assuming old version is present.')
}
}
9 changes: 7 additions & 2 deletions src/llms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getBackendSrv, getGrafanaLiveSrv, logDebug } from "@grafana/runtime";
import { pipe, Observable, UnaryFunction } from "rxjs";
import { filter, map, scan, takeWhile } from "rxjs/operators";

import { LLM_PLUGIN_ID, LLM_PLUGIN_ROUTE } from "./constants";
import { LLM_PLUGIN_ID, LLM_PLUGIN_ROUTE, setLLMPluginVersion, LLM_PLUGIN_VERSION } from "./constants";
import { LLMAppHealthCheck } from "./types";

const OPENAI_CHAT_COMPLETIONS_PATH = 'openai/v1/chat/completions';
Expand Down Expand Up @@ -344,7 +344,12 @@ export const enabled = async () => {
}
return false;
}
// If the plugin is installed then check if it is configured.

const { details } = response;
// Update the version if it's present on the response.
if (details.version !== undefined) {
setLLMPluginVersion(details.version);
}
// If the plugin is installed then check if it is configured.
return details?.openAIEnabled ?? false;
}
1 change: 1 addition & 0 deletions src/llms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export type LLMAppHealthCheck = {
details: {
openAIEnabled?: boolean;
vectorEnabled?: boolean;
version?: string;
};
};
8 changes: 6 additions & 2 deletions src/llms/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { getBackendSrv, logDebug } from "@grafana/runtime";
import { LLM_PLUGIN_ROUTE } from "./constants";
import { LLM_PLUGIN_ROUTE, setLLMPluginVersion } from "./constants";
import { LLMAppHealthCheck } from "./types";

interface SearchResultPayload extends Record<string, any> { }
Expand Down Expand Up @@ -89,7 +89,11 @@ export const enabled = async () => {
}
return false;
}
// If the plugin is installed then check if it is configured.
const { details } = response;
// Update the version if it's present on the response.
if (details.version !== undefined) {
setLLMPluginVersion(details.version);
}
// If the plugin is installed then check if it is configured.
return details.vectorEnabled ?? false;
};
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6551,7 +6551,7 @@ semver@^7.3.5, semver@^7.3.7, semver@^7.5.0:
dependencies:
lru-cache "^6.0.0"

semver@^7.5.1:
semver@^7.5.1, semver@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
Expand Down

0 comments on commit 4a8c5b5

Please sign in to comment.