| 10 | const MLX_CHAT_PATH = '/v1/chat/completions'; |
| 11 | |
| 12 | export class MLXEngine implements AiEngine { |
| 13 | config: MLXConfig; |
| 14 | client: AxiosInstance; |
| 15 | private chatUrl: string; |
| 16 | |
| 17 | constructor(config) { |
| 18 | this.config = config; |
| 19 | |
| 20 | const baseUrl = config.baseURL || DEFAULT_MLX_URL; |
| 21 | this.chatUrl = `${baseUrl}${MLX_CHAT_PATH}`; |
| 22 | |
| 23 | this.client = axios.create({ |
| 24 | headers: { 'Content-Type': 'application/json' } |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | async generateCommitMessage( |
| 29 | messages: Array<OpenAI.Chat.Completions.ChatCompletionMessageParam> |
| 30 | ): Promise<string | undefined> { |
| 31 | const params = { |
| 32 | messages, |
| 33 | temperature: 0, |
| 34 | top_p: 0.1, |
| 35 | repetition_penalty: 1.5, |
| 36 | stream: false |
| 37 | }; |
| 38 | try { |
| 39 | const response = await this.client.post(this.chatUrl, params); |
| 40 | |
| 41 | const choices = response.data.choices; |
| 42 | const message = choices[0].message; |
| 43 | let content = message?.content; |
| 44 | return removeContentTags(content, 'think'); |
| 45 | } catch (error) { |
| 46 | throw normalizeEngineError(error, 'mlx', this.config.model); |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…