| 6 | interface AimlApiConfig extends AiEngineConfig {} |
| 7 | |
| 8 | export class AimlApiEngine implements AiEngine { |
| 9 | client: AxiosInstance; |
| 10 | |
| 11 | constructor(public config: AimlApiConfig) { |
| 12 | this.client = axios.create({ |
| 13 | baseURL: config.baseURL || 'https://api.aimlapi.com/v1/chat/completions', |
| 14 | headers: { |
| 15 | Authorization: `Bearer ${config.apiKey}`, |
| 16 | 'HTTP-Referer': 'https://github.com/di-sukharev/opencommit', |
| 17 | 'X-Title': 'opencommit', |
| 18 | 'Content-Type': 'application/json', |
| 19 | ...config.customHeaders |
| 20 | } |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | public generateCommitMessage = async ( |
| 25 | messages: Array<OpenAI.Chat.Completions.ChatCompletionMessageParam> |
| 26 | ): Promise<string | null> => { |
| 27 | try { |
| 28 | const response = await this.client.post('', { |
| 29 | model: this.config.model, |
| 30 | messages |
| 31 | }); |
| 32 | |
| 33 | const message = response.data.choices?.[0]?.message; |
| 34 | return message?.content ?? null; |
| 35 | } catch (error) { |
| 36 | throw normalizeEngineError(error, 'aimlapi', this.config.model); |
| 37 | } |
| 38 | }; |
| 39 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…