File tree Expand file tree Collapse file tree 9 files changed +51
-36
lines changed
Expand file tree Collapse file tree 9 files changed +51
-36
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ import ensureDirectoryExistence from './manageStackFolder';
1111import convertTypescriptToJson from './convertTypescriptToJson' ;
1212require ( '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
Original file line number Diff line number Diff line change 11import 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
74interface InputType {
85 wholeSkeleton : string ;
Original file line number Diff line number Diff line change @@ -2,10 +2,9 @@ import OpenAI from 'openai';
22import { BoilerplateMetadata , Message } from '../lib/types' ;
33import { processBoilerplate , readFunctionToString } from '../lib/utils' ;
44import { 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
109export default async function generateFunction (
1110 briefSkeleton : string ,
Original file line number Diff line number Diff 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
1421export default async function constructOpenAI (
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments