Skip to content

Commit

Permalink
[backend] Upgrade of mistral ai client version (#9481)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
aHenryJard and renovate[bot] authored Jan 28, 2025
1 parent 9276b5a commit 790ad21
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
5 changes: 3 additions & 2 deletions opencti-platform/opencti-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@graphql-tools/schema": "10.0.6",
"@graphql-tools/utils": "10.5.4",
"@jorgeferrero/stream-to-buffer": "2.0.6",
"@mistralai/mistralai": "0.5.0",
"@mistralai/mistralai": "1.3.6",
"@node-saml/passport-saml": "5.0.0",
"@opensearch-project/opensearch": "2.12.0",
"@opentelemetry/api": "1.9.0",
Expand Down Expand Up @@ -160,7 +160,8 @@
"winston": "3.17.0",
"winston-daily-rotate-file": "5.0.0",
"ws": "8.18.0",
"xml2js": "0.6.2"
"xml2js": "0.6.2",
"zod": "3.24.1"
},
"devDependencies": {
"@graphql-codegen/cli": "5.0.3",
Expand Down
21 changes: 15 additions & 6 deletions opencti-platform/opencti-graphql/src/database/ai-llm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MistralClient from '@mistralai/mistralai';
import { Mistral } from '@mistralai/mistralai';
import OpenAI from 'openai';
import conf, { BUS_TOPICS, logApp } from '../config/conf';
import { isEmptyField } from './utils';
Expand All @@ -13,11 +13,20 @@ const AI_ENDPOINT = conf.get('ai:endpoint');
const AI_TOKEN = conf.get('ai:token');
const AI_MODEL = conf.get('ai:model');

let client: MistralClient | OpenAI | null = null;
let client: Mistral | OpenAI | null = null;
if (AI_ENABLED && AI_TOKEN) {
switch (AI_TYPE) {
case 'mistralai':
client = new MistralClient(AI_TOKEN, isEmptyField(AI_ENDPOINT) ? undefined : AI_ENDPOINT);
client = new Mistral({
serverURL: isEmptyField(AI_ENDPOINT) ? undefined : AI_ENDPOINT,
apiKey: AI_TOKEN,
/* uncomment if you need low level debug on AI
debugLogger: {
log: (message, args) => logApp.info(`[AI] log ${message}`, { message }),
group: (label) => logApp.info(`[AI] group ${label} start.`),
groupEnd: () => logApp.info('[AI] group end.'),
} */
});
break;
case 'openai':
client = new OpenAI({
Expand All @@ -36,16 +45,16 @@ export const queryMistralAi = async (busId: string | null, question: string, use
}
try {
logApp.debug('[AI] Querying MistralAI with prompt', { questionStart: question.substring(0, 100) });
const response = (client as MistralClient)?.chatStream({
const response = await (client as Mistral)?.chat.stream({
model: AI_MODEL,
messages: [{ role: 'user', content: question }],
});
let content = '';
if (response) {
// eslint-disable-next-line no-restricted-syntax
for await (const chunk of response) {
if (chunk.choices[0].delta.content !== undefined) {
const streamText = chunk.choices[0].delta.content;
if (chunk.data.choices[0].delta.content !== undefined) {
const streamText = chunk.data.choices[0].delta.content;
content += streamText;
if (busId !== null) {
await notify(BUS_TOPICS[AI_BUS].EDIT_TOPIC, { bus_id: busId, content }, user);
Expand Down
22 changes: 15 additions & 7 deletions opencti-platform/opencti-graphql/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3069,12 +3069,12 @@ __metadata:
languageName: node
linkType: hard

"@mistralai/mistralai@npm:0.5.0":
version: 0.5.0
resolution: "@mistralai/mistralai@npm:0.5.0"
dependencies:
node-fetch: "npm:^2.6.7"
checksum: 10/788e4b6d4bb124131272beea1079081f4b279befc8608ac4fcf0efa147f524c48e4af4b68414c6f71a32704eaf0c9c6d5550634ed6be8a9bcf9cc8d15d55161a
"@mistralai/mistralai@npm:1.3.6":
version: 1.3.6
resolution: "@mistralai/mistralai@npm:1.3.6"
peerDependencies:
zod: ">= 3"
checksum: 10/ff5869f5c829b050b2ec10338270e3c9b916ea0e84064ee0cabf47b91f4b34f8810a2b7495c21fe8c192ffa1f5f015344d23dff4112f20c5a6f488777dac1ad9
languageName: node
linkType: hard

Expand Down Expand Up @@ -11391,7 +11391,7 @@ __metadata:
"@graphql-tools/utils": "npm:10.5.4"
"@jorgeferrero/stream-to-buffer": "npm:2.0.6"
"@luckycatfactory/esbuild-graphql-loader": "npm:3.8.1"
"@mistralai/mistralai": "npm:0.5.0"
"@mistralai/mistralai": "npm:1.3.6"
"@node-saml/passport-saml": "npm:5.0.0"
"@opensearch-project/opensearch": "npm:2.12.0"
"@opentelemetry/api": "npm:1.9.0"
Expand Down Expand Up @@ -11532,6 +11532,7 @@ __metadata:
winston-daily-rotate-file: "npm:5.0.0"
ws: "npm:8.18.0"
xml2js: "npm:0.6.2"
zod: "npm:3.24.1"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -14851,3 +14852,10 @@ __metadata:
checksum: 10/aa5abd6a89590eadeba040afbc375f53337f12637e5e98330012a12d9886cde7a3ccc28bd91aafab50576035bbb1de39a9a316eecf2411c8b9009c9f94f0db27
languageName: node
linkType: hard

"zod@npm:3.24.1":
version: 3.24.1
resolution: "zod@npm:3.24.1"
checksum: 10/54e25956495dec22acb9399c168c6ba657ff279801a7fcd0530c414d867f1dcca279335e160af9b138dd70c332e17d548be4bc4d2f7eaf627dead50d914fec27
languageName: node
linkType: hard

0 comments on commit 790ad21

Please sign in to comment.