| 7 | interface OpenRouterConfig extends AiEngineConfig {} |
| 8 | |
| 9 | export class OpenRouterEngine implements AiEngine { |
| 10 | client: AxiosInstance; |
| 11 | |
| 12 | constructor(public config: OpenRouterConfig) { |
| 13 | this.client = axios.create({ |
| 14 | baseURL: 'https://openrouter.ai/api/v1/chat/completions', |
| 15 | headers: { |
| 16 | Authorization: `Bearer ${config.apiKey}`, |
| 17 | 'HTTP-Referer': 'https://github.com/di-sukharev/opencommit', |
| 18 | 'X-Title': 'OpenCommit', |
| 19 | 'Content-Type': 'application/json' |
| 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 | let content = message?.content; |
| 35 | return removeContentTags(content, 'think'); |
| 36 | } catch (error) { |
| 37 | throw normalizeEngineError(error, 'openrouter', this.config.model); |
| 38 | } |
| 39 | }; |
| 40 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…