-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathllmservice.ts
More file actions
37 lines (30 loc) · 963 Bytes
/
llmservice.ts
File metadata and controls
37 lines (30 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import axios, { AxiosError } from 'axios';
import { ChatCompletionRequestMessage } from 'openai';
import { AiEngine } from './Engine';
import {
getConfig
} from '../commands/config';
const config = getConfig();
export class LlmService implements AiEngine {
async generateCommitMessage(
messages: Array<ChatCompletionRequestMessage>
): Promise<string | undefined> {
const gitDiff = messages[ messages.length - 1 ]?.content;
const url = `http://${config?.OCO_BACKEND_ENDPOINT}/${config?.OCO_BACKEND_PATH}`;
const payload = {
user_prompt: gitDiff
}
try {
const response = await axios.post(url, payload, {
headers: {
'Content-Type': 'application/json'
}
});
const message = response.data;
return message;
} catch (err: any) {
const message = err.response?.data?.error ?? err.message;
throw new Error('local model issues. details: ' + message);
}
}
}