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