Skip to content

Commit

Permalink
fix(networks): correct error if no api key mistral
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Mar 26, 2024
1 parent 0c20631 commit bb00786
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion client/src/api/networks/network/communities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 14 additions & 3 deletions client/src/api/networks/network/openai.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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: [
{
Expand Down Expand Up @@ -50,8 +55,14 @@ export async function openAiLabeledClusters(clusters: Array<any>) {

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]
Expand Down

0 comments on commit bb00786

Please sign in to comment.