forked from stackwiseai/stackwise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.test.ts
More file actions
92 lines (70 loc) · 2.65 KB
/
generate.test.ts
File metadata and controls
92 lines (70 loc) · 2.65 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import path from 'path';
import fs from 'fs/promises';
import generateFunction from './generateFunction';
jest.setTimeout(15000);
const tsFilePath = path.join(__dirname, 'tempFunction.ts');
describe('generateFunction', () => {
test('sum two numbers', async () => {
const functionAndOutputSkeleton = `export default async function sumTwoNumbers(x: number, y: number): Promise<number> {
return 0;
}`;
const brief = 'Make me a function that adds the two numbers that I give it';
const exampleBoilerplate = null;
const integration = 'generic';
const briefSkeleton = `/**
* Brief: ${brief}
*/`;
const generatedFunction = await generateFunction(
briefSkeleton,
functionAndOutputSkeleton,
brief,
exampleBoilerplate,
integration
);
console.log(`generatedFunction`, generatedFunction);
// Write the generated function to a file
await fs.writeFile(tsFilePath, generatedFunction);
const method = await import(tsFilePath);
const sumTwoNumbers = method.default;
expect(await sumTwoNumbers(1, 2)).toBe(3);
expect(await sumTwoNumbers(7, 8)).toBe(15);
expect(await sumTwoNumbers(0, 0)).toBe(0);
expect(await sumTwoNumbers(-1, -1)).toBe(-2);
await fs.unlink(tsFilePath);
});
// test.only('call openai model with prompt', async () => {
// const functionAndOutputSkeleton = `export default async function callOpenAI(prompt: string): Promise<string> {
// return '';
// }`;
// const brief = 'Call openai using gpt-3.5-turbo with the prompt that I gave';
// // this means no similar was found, will use default boilerplate
// const exampleBoilerplate = null;
// const integration = 'openai';
// const briefSkeleton = `/**
// * Brief: ${brief}
// */`;
// const generatedFunction = await generateFunction(
// briefSkeleton,
// functionAndOutputSkeleton,
// brief,
// exampleBoilerplate,
// integration
// );
// console.log(`generatedFunction`, generatedFunction);
// // Write the generated function to a file
// await fs.writeFile(tsFilePath, generatedFunction);
// const method = await import(tsFilePath);
// const callOpenAI = method.default;
// expect(
// await callOpenAI(
// `Return absolutely nothing but 'hi there'. Do not return anything before or after`
// )
// ).toContain('hi there');
// expect(
// await callOpenAI(
// `Return absolutely nothing but 'Yes I do'. Do not return anything before or after`
// )
// ).toContain('Yes I do');
// await fs.unlink(tsFilePath);
// });
});