forked from stackwiseai/stackwise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
120 lines (106 loc) · 3.01 KB
/
index.ts
File metadata and controls
120 lines (106 loc) · 3.01 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import getMethodName from '../getMethodName';
import {
generateSignature,
createMD5HashFromSignature,
} from '../generateSignature';
import stackRegistry from '../registry';
import extractBrief from '../extractBrief';
import jsonify from '../jsonify/jsonify';
import flattenInputJson from '../flattenInputJson';
import getMethodNameWithCache from '../../cache/getMethodNameFromCache';
import createSkeleton from '../createSkeleton';
interface OutputType {
brief: string;
functionId: string;
documentContent: string;
functionExists: boolean;
methodName: string;
inputString: string;
briefSkeleton: string;
functionAndOutputSkeleton: string;
inputValues: string;
}
interface InputType {
stackSnippet: string;
inputJSON: { [key: string]: any };
outputJSON: { [key: string]: any };
}
export default async function buildStack({
inputJSON,
outputJSON,
stackSnippet,
}: InputType): Promise<OutputType> {
const brief = extractBrief(stackSnippet);
console.log('brief after extraction');
console.log(brief);
const { in: inputString, inputValues} = jsonify(stackSnippet);
console.log('input after JSONIFY');
console.log(inputString);
// console.log('output after JSONIFY');
// console.log(out);
// Create a signature from the extracted parameters
const signature = generateSignature(
brief,
inputJSON,
outputJSON,
'stackwise'
);
console.log('signature');
console.log(signature);
const md5hash = createMD5HashFromSignature(signature);
console.log('md5hash');
console.log(md5hash);
const functionId = `a${md5hash}`;
console.log('functionId');
console.log(functionId);
const functionExists = stackRegistry.exists(functionId);
const flatInput = flattenInputJson(inputJSON);
console.log('Before Create Skeleton');
console.log('brief:');
console.log(brief);
console.log('inputJSON');
console.log(inputJSON);
console.log('outputJSON');
console.log(outputJSON);
console.log('flatInput');
console.log(flatInput);
let { briefSkeleton, functionAndOutputSkeleton } = createSkeleton(
brief,
inputJSON,
outputJSON,
functionId,
flatInput
);
const methodName = await getMethodNameWithCache(
briefSkeleton,
functionAndOutputSkeleton,
brief
);
// store this in the cache, the key should be the concatenation of wholeSkeleton and methodName and the value should be methodName
// the cache should be checked before calling getMethodName
// the cache is present in .stack/llmCache.json
// create the function
console.log(`we are here - methodName`);
console.log(methodName);
if (methodName) {
functionAndOutputSkeleton = functionAndOutputSkeleton.replace(
'placeholderStackwiseFunction',
methodName
);
functionAndOutputSkeleton = functionAndOutputSkeleton.replace(
functionId,
methodName
);
}
return {
brief,
functionId,
documentContent: 'unused',
functionExists,
methodName,
inputString,
briefSkeleton,
functionAndOutputSkeleton,
inputValues
};
}