From bb00786d709de71fcbc497a815ac8d1d741ac3fa Mon Sep 17 00:00:00 2001 From: victor barbier Date: Tue, 26 Mar 2024 09:11:27 +0100 Subject: [PATCH] fix(networks): correct error if no api key mistral --- client/src/api/networks/network/communities.ts | 1 - client/src/api/networks/network/openai.ts | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/src/api/networks/network/communities.ts b/client/src/api/networks/network/communities.ts index 7e03cdfa..a5323f5a 100644 --- a/client/src/api/networks/network/communities.ts +++ b/client/src/api/networks/network/communities.ts @@ -75,7 +75,6 @@ export default async function communitiesCreate(graph: Graph, computeClusters: b const communities = Promise.all( Array.from({ length: count }, async (_, index) => { const hits = await networkSearchHits(query, model, communityGetLinks(graph, index)) - console.log("trois") const community = { index: index, diff --git a/client/src/api/networks/network/openai.ts b/client/src/api/networks/network/openai.ts index c6b19f1d..9c3b9139 100644 --- a/client/src/api/networks/network/openai.ts +++ b/client/src/api/networks/network/openai.ts @@ -1,10 +1,15 @@ import MistralClient, { ResponseFormats } from "@mistralai/mistralai" const ENABLED = false -const { VITE_MISTRAL_API_KEY } = import.meta.env -const mistral = new MistralClient(VITE_MISTRAL_API_KEY) async function mistralLabelsFromDomains(domains: any): Promise { + const { VITE_MISTRAL_API_KEY } = import.meta.env + + if (!VITE_MISTRAL_API_KEY) { + throw new Error("Mistral error: bad api key") + } + + const mistral = new MistralClient(VITE_MISTRAL_API_KEY) const completion = await mistral.chat({ messages: [ { @@ -50,8 +55,14 @@ export async function openAiLabeledClusters(clusters: Array) { if (!domains) return clusters - const mistral_labels = await mistralLabelsFromDomains(domains).then((response) => JSON.parse(response)) + const mistral_labels = await mistralLabelsFromDomains(domains).then( + (response) => JSON.parse(response), + (err) => console.log(err) + ) console.log("mistral_labels", mistral_labels) + if (!mistral_labels || mistral_labels.constructor != Object) { + return clusters + } Object.entries(mistral_labels).forEach((entries, index) => { const value = entries[1]