add openai validation

This commit is contained in:
Danel Kungla
2025-09-26 16:18:50 +03:00
parent 0a61371271
commit c99beea46a
2 changed files with 24 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ import Dashboard from '../_components/dashboard';
import DashboardCards from '../_components/dashboard-cards'; import DashboardCards from '../_components/dashboard-cards';
import Recommendations from '../_components/recommendations'; import Recommendations from '../_components/recommendations';
import RecommendationsSkeleton from '../_components/recommendations-skeleton'; import RecommendationsSkeleton from '../_components/recommendations-skeleton';
import { isValidOpenAiEnv } from '../_lib/server/is-valid-open-ai-env';
import { loadCurrentUserAccount } from '../_lib/server/load-user-account'; import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
export const generateMetadata = async () => { export const generateMetadata = async () => {
@@ -52,8 +53,7 @@ async function UserHomePage() {
/> />
<PageBody> <PageBody>
<Dashboard account={account} bmiThresholds={bmiThresholds} /> <Dashboard account={account} bmiThresholds={bmiThresholds} />
{process.env.OPENAI_API_KEY && {(await isValidOpenAiEnv()) && (
process.env.PROMPT_ID_ANALYSIS_RECOMMENDATIONS && (
<> <>
<h4> <h4>
<Trans i18nKey="dashboard:recommendations.title" /> <Trans i18nKey="dashboard:recommendations.title" />

View File

@@ -0,0 +1,13 @@
import OpenAI from 'openai';
export const isValidOpenAiEnv = async () => {
const client = new OpenAI();
try {
await client.models.list();
return true;
} catch (e) {
console.log('No openAI env');
return false;
}
};