Skip to content

Commit 8523158

Browse files
committed
record behavior and setup caching to test faster
Signed-off-by: Merwane Hamadi <[email protected]>
1 parent 20e7137 commit 8523158

File tree

9 files changed

+51
-36
lines changed

9 files changed

+51
-36
lines changed

src/cache/getMethodNameFromCache.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export default async function getMethodNameWithCache(
2828
// The cache key is a concatenation of `wholeSkeleton` and the name of the method
2929
const cacheKey =
3030
wholeSkeleton + (await getMethodName({ wholeSkeleton, brief }));
31-
31+
console.log(`cacheKey: ${cacheKey}`);
3232
// Try to read the cache first
3333
let methodName = await storage.getItem(cacheKey);
34+
console.log(`methodName: ${methodName}`);
3435

3536
// If it's not in the cache, call the actual function
3637
if (!methodName) {

src/extension.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import ensureDirectoryExistence from './manageStackFolder';
1111
import convertTypescriptToJson from './convertTypescriptToJson';
1212
require('dotenv').config();
1313

14-
const storage = require('node-persist');
15-
1614
// You must first call storage.init or storage.initSync
1715
// Set the storage file to be a hidden file, e.g., '.llmCache.json'
1816

src/stack/getMethodName.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import OpenAI from 'openai';
2-
3-
const openai = new OpenAI({
4-
apiKey: process.env.OPENAI_API_KEY,
5-
});
2+
import { openai } from './integrations/openai/construct';
63

74
interface InputType {
85
wholeSkeleton: string;

src/stack/integrations/generic/generateFunction.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import OpenAI from 'openai';
22
import { BoilerplateMetadata, Message } from '../lib/types';
33
import { processBoilerplate, readFunctionToString } from '../lib/utils';
44
import { combineSkeleton } from '../../createSkeleton';
5+
import { openai } from '../openai/construct';
6+
57

6-
const openai = new OpenAI({
7-
apiKey: process.env.OPENAI_API_KEY,
8-
});
98

109
export default async function generateFunction(
1110
briefSkeleton: string,

src/stack/integrations/openai/construct/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ const pinecone = new Pinecone({
77
environment: process.env.PINECONE_ENVIRONMENT as string,
88
});
99

10-
const openai = new OpenAI({
11-
apiKey: process.env.OPENAI_API_KEY as string,
10+
const defaultHeaders = process.env.HELICONE_API_KEY ? {
11+
'Helicone-Auth': `Bearer ${process.env.HELICONE_API_KEY}`,
12+
'Helicone-Cache-Enabled': 'true',
13+
} : {};
14+
15+
export const openai = new OpenAI({
16+
apiKey: process.env.OPENAI_API_KEY,
17+
baseURL: 'https://oai.hconeai.com/v1',
18+
defaultHeaders: defaultHeaders,
1219
});
1320

1421
export default async function constructOpenAI(

test-workspace/fixtures/arrays/output.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ stack(
55
}
66
);
77

8-
import processStringArray from '../../stacks/processStringArray';
8+
import validateInputArray from '../../stacks/validateInputArray';
99

10-
processStringArray(
10+
validateInputArray(
1111
'this is an example', 'this is an example'
1212
);
1313

1414

1515
/**
1616
* Brief: brief
1717
*/
18-
export default async function processStringArray(input: string[]): Promise<null> {
19-
input.forEach((str) => {
20-
console.log(str);
21-
});
18+
export default async function validateInputArray(input: string[]): Promise<null> {
19+
if (!Array.isArray(input)) {
20+
throw new Error('Input must be an array');
21+
}
22+
23+
for (let i = 0; i < input.length; i++) {
24+
if (typeof input[i] !== 'string') {
25+
throw new Error(`Element at index ${i} is not a string`);
26+
}
27+
}
28+
2229
return null;
2330
}

test-workspace/fixtures/inputEmptyString/output.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ stack('this is an example', {
33
outExample: true,
44
});
55

6-
import generateBooleanResponse from '../../stacks/generateBooleanResponse';
6+
import generateBooleanOutput from '../../stacks/generateBooleanOutput';
77

8-
generateBooleanResponse(
8+
generateBooleanOutput(
99
''
1010
);
1111

1212

1313
/**
1414
* Brief: this is an example
1515
*/
16-
export default async function generateBooleanResponse(input: string): Promise<string> {
17-
let response = '';
18-
if (input.toLowerCase() === 'true' || input.toLowerCase() === 'false') {
19-
response = 'boolean';
16+
export default async function generateBooleanOutput(input: string): Promise<string> {
17+
let output = '';
18+
if (input) {
19+
output = 'true';
2020
} else {
21-
response = 'not boolean';
21+
output = 'false';
2222
}
23-
return response;
23+
return output;
2424
}

test-workspace/fixtures/simple/output.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ stack('this is an example', {
55

66

77

8+
import generateBooleanOutput from '../../stacks/generateBooleanOutput';
89

9-
stack('this is an example', {
10-
input: 'this is an example',
11-
outExample: true,
12-
});
10+
generateBooleanOutput(
11+
'this is an example'
12+
);
1313

1414

1515

1616

17+
/**
18+
* Brief: this is an example
19+
*/
20+
export default async function generateBooleanOutput(input: string): Promise<string> {
21+
let output = '';
22+
if (input) {
23+
output = 'true';
24+
} else {
25+
output = 'false';
26+
}
27+
return output;
28+
}

test-workspace/stacks/multiplyNumbers.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)