-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaskhal.js
More file actions
58 lines (51 loc) · 1.85 KB
/
Copy pathaskhal.js
File metadata and controls
58 lines (51 loc) · 1.85 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { processCLIArguments } from './cli.js';
import { checkEnvAPIKey } from './env.js';
import { log } from './log.js';
import { run } from './run.js';
import { resolveProvider } from './providers.js';
import OpenAI from 'openai';
async function main() {
const program = processCLIArguments();
const model = program.opts().model;
const system = program.opts().system;
const contextPath = program.opts().context;
const contextType = (program.opts().type).toLowerCase();
const user = program.opts().user;
const stream = program.opts().responsive;
const compress = program.opts().fit;
let providerName = program.opts().provider;
const apiKey = (program.opts().key) ? program.opts().key : checkEnvAPIKey('AI_PROVIDER_KEY');
let baseURL;
let headers;
if (program.opts().url) {
providerName = 'custom';
baseURL = program.opts().url;
headers = {};
} else {
const providerConfig = resolveProvider(providerName);
baseURL = providerConfig.baseURL;
headers = providerConfig.headers;
}
const client = new OpenAI({
baseURL,
apiKey,
defaultHeaders: headers
});
const aiParameters = {};
aiParameters.TEMPERATURE = program.opts().temperature;
aiParameters.TOP_K = program.opts().topk;
aiParameters.TOP_P = program.opts().topp;
aiParameters.FREQUENCY_PENALTY = program.opts().frequency;
aiParameters.REPETITION_PENALTY = program.opts().repetition;
aiParameters.PRESENCE_PENALTY = program.opts().presence;
await run(client, model, system, user, { contextPath, contextType, stream, compress, aiParameters, providerName });
}
main()
.catch((err) => {
if (typeof err.format === 'function') {
log.error(err.format());
} else {
log.error(err.message);
}
process.exit(1);
});