MCPcopy
hub / github.com/di-sukharev/opencommit / MistralAiEngine

Class MistralAiEngine

src/engine/mistral.ts:13–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11export type MistralCompletionMessageParam = Array<any>;
12
13export class MistralAiEngine implements AiEngine {
14 config: MistralAiConfig;
15 client: any; // Using any type for Mistral client to avoid TS errors
16
17 constructor(config: MistralAiConfig) {
18 this.config = config;
19
20 if (!config.baseURL) {
21 this.client = new Mistral({ apiKey: config.apiKey });
22 } else {
23 this.client = new Mistral({
24 apiKey: config.apiKey,
25 serverURL: config.baseURL
26 });
27 }
28 }
29
30 public generateCommitMessage = async (
31 messages: Array<OpenAI.Chat.Completions.ChatCompletionMessageParam>
32 ): Promise<string | null> => {
33 const params = {
34 model: this.config.model,
35 messages: messages as MistralCompletionMessageParam,
36 topP: 0.1,
37 maxTokens: this.config.maxTokensOutput
38 };
39
40 try {
41 const REQUEST_TOKENS = messages
42 .map((msg) => tokenCount(msg.content as string) + 4)
43 .reduce((a, b) => a + b, 0);
44
45 if (
46 REQUEST_TOKENS >
47 this.config.maxTokensInput - this.config.maxTokensOutput
48 )
49 throw new Error(GenerateCommitMessageErrorEnum.tooMuchTokens);
50
51 const completion = await this.client.chat.complete(params);
52
53 if (!completion.choices) throw Error('No completion choice available.');
54
55 const message = completion.choices[0].message;
56
57 if (!message || !message.content)
58 throw Error('No completion choice available.');
59
60 let content = message.content as string;
61 return removeContentTags(content, 'think');
62 } catch (error) {
63 throw normalizeEngineError(error, 'mistral', this.config.model);
64 }
65 };
66}

Callers

nothing calls this directly

Calls 4

tokenCountFunction · 0.90
removeContentTagsFunction · 0.90
normalizeEngineErrorFunction · 0.90
completeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…