add openai validation
This commit is contained in:
@@ -16,6 +16,7 @@ import Dashboard from '../_components/dashboard';
|
||||
import DashboardCards from '../_components/dashboard-cards';
|
||||
import Recommendations from '../_components/recommendations';
|
||||
import RecommendationsSkeleton from '../_components/recommendations-skeleton';
|
||||
import { isValidOpenAiEnv } from '../_lib/server/is-valid-open-ai-env';
|
||||
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
||||
|
||||
export const generateMetadata = async () => {
|
||||
@@ -52,17 +53,16 @@ async function UserHomePage() {
|
||||
/>
|
||||
<PageBody>
|
||||
<Dashboard account={account} bmiThresholds={bmiThresholds} />
|
||||
{process.env.OPENAI_API_KEY &&
|
||||
process.env.PROMPT_ID_ANALYSIS_RECOMMENDATIONS && (
|
||||
<>
|
||||
<h4>
|
||||
<Trans i18nKey="dashboard:recommendations.title" />
|
||||
</h4>
|
||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||
<Recommendations account={account} />
|
||||
</Suspense>
|
||||
</>
|
||||
)}
|
||||
{(await isValidOpenAiEnv()) && (
|
||||
<>
|
||||
<h4>
|
||||
<Trans i18nKey="dashboard:recommendations.title" />
|
||||
</h4>
|
||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||
<Recommendations account={account} />
|
||||
</Suspense>
|
||||
</>
|
||||
)}
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
|
||||
13
app/home/(user)/_lib/server/is-valid-open-ai-env.ts
Normal file
13
app/home/(user)/_lib/server/is-valid-open-ai-env.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user