-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
63 lines (54 loc) · 1.6 KB
/
index.ts
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
59
60
61
62
63
import process from 'node:process';
import { config } from '@dotenvx/dotenvx';
import { StringOutputParser } from '@langchain/core/output_parsers';
import {
ChatPromptTemplate,
HumanMessagePromptTemplate,
} from '@langchain/core/prompts';
import { RunnableSequence } from '@langchain/core/runnables';
import { ChatOpenAI } from '@langchain/openai';
import { defineCommand, runMain } from 'citty';
import { consola } from 'consola';
import { PangeaAuditCallbackHandler } from './tracers/audit.js';
config({ override: true, quiet: true });
const prompt = ChatPromptTemplate.fromMessages([
HumanMessagePromptTemplate.fromTemplate('{input}'),
]);
const main = defineCommand({
args: {
prompt: { type: 'positional' },
auditConfigId: {
type: 'string',
description: 'Pangea Secure Audit Log configuration ID.',
},
model: {
type: 'string',
default: 'gpt-4o-mini',
description: 'OpenAI model.',
},
},
async run({ args }) {
const auditToken = process.env.PANGEA_AUDIT_TOKEN;
if (!auditToken) {
consola.warn('PANGEA_AUDIT_TOKEN is not set.');
return;
}
const pangeaDomain = process.env.PANGEA_DOMAIN || 'aws.us.pangea.cloud';
const auditCallback = new PangeaAuditCallbackHandler(
auditToken,
args.auditConfigId,
pangeaDomain
);
const model = new ChatOpenAI({
model: args.model,
callbacks: [auditCallback],
});
const chain = RunnableSequence.from([
prompt,
model,
new StringOutputParser(),
]);
consola.log(await chain.invoke({ input: args.prompt }));
},
});
runMain(main);