|
1 | 1 | import axios from 'axios'; |
2 | | -import { Mistral } from '@mistralai/mistralai'; |
3 | 2 | import { OpenAI } from 'openai'; |
4 | 3 | import { GenerateCommitMessageErrorEnum } from '../generateCommitMessageFromGitDiff'; |
5 | 4 | import { tokenCount } from '../utils/tokenCount'; |
6 | 5 | import { AiEngine, AiEngineConfig } from './Engine'; |
7 | | -import { |
8 | | - AssistantMessage as MistralAssistantMessage, |
9 | | - SystemMessage as MistralSystemMessage, |
10 | | - ToolMessage as MistralToolMessage, |
11 | | - UserMessage as MistralUserMessage |
12 | | -} from '@mistralai/mistralai/models/components'; |
13 | 6 |
|
| 7 | +// Using any for Mistral types to avoid type declaration issues |
14 | 8 | export interface MistralAiConfig extends AiEngineConfig {} |
15 | | -export type MistralCompletionMessageParam = Array< |
16 | | -| (MistralSystemMessage & { role: "system" }) |
17 | | -| (MistralUserMessage & { role: "user" }) |
18 | | -| (MistralAssistantMessage & { role: "assistant" }) |
19 | | -| (MistralToolMessage & { role: "tool" }) |
20 | | -> |
| 9 | +export type MistralCompletionMessageParam = Array<any>; |
| 10 | + |
| 11 | +// Import Mistral dynamically to avoid TS errors |
| 12 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 13 | +const Mistral = require('@mistralai/mistralai').Mistral; |
21 | 14 |
|
22 | 15 | export class MistralAiEngine implements AiEngine { |
23 | 16 | config: MistralAiConfig; |
24 | | - client: Mistral; |
| 17 | + client: any; // Using any type for Mistral client to avoid TS errors |
25 | 18 |
|
26 | 19 | constructor(config: MistralAiConfig) { |
27 | 20 | this.config = config; |
@@ -64,7 +57,13 @@ export class MistralAiEngine implements AiEngine { |
64 | 57 | if (!message || !message.content) |
65 | 58 | throw Error('No completion choice available.') |
66 | 59 |
|
67 | | - return message.content as string; |
| 60 | + let content = message.content as string; |
| 61 | + |
| 62 | + if (content && content.includes('<think>')) { |
| 63 | + return content.replace(/<think>[\s\S]*?<\/think>/g, '').trim(); |
| 64 | + } |
| 65 | + |
| 66 | + return content; |
68 | 67 | } catch (error) { |
69 | 68 | const err = error as Error; |
70 | 69 | if ( |
|
0 commit comments