add openai validation
This commit is contained in:
@@ -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,17 +53,16 @@ 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" />
|
</h4>
|
||||||
</h4>
|
<Suspense fallback={<RecommendationsSkeleton />}>
|
||||||
<Suspense fallback={<RecommendationsSkeleton />}>
|
<Recommendations account={account} />
|
||||||
<Recommendations account={account} />
|
</Suspense>
|
||||||
</Suspense>
|
</>
|
||||||
</>
|
)}
|
||||||
)}
|
|
||||||
</PageBody>
|
</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