forked from stackwiseai/stackwise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMethodName.ts
More file actions
39 lines (36 loc) · 1.29 KB
/
Copy pathgetMethodName.ts
File metadata and controls
39 lines (36 loc) · 1.29 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
import OpenAI from 'openai';
import { openai } from './integrations/openai/construct';
interface InputType {
wholeSkeleton: string;
brief: string;
}
export default async function getMethodName({
wholeSkeleton,
brief,
}: InputType): Promise<string> {
if (brief === 'test') {
return null;
} else {
try {
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'user',
content: `Find a good name for this function given the brief that generated it.
Brief: ${brief}
Function: ${wholeSkeleton}
Now, come up with a name for the function to replace the 'placeholderStackwiseFunction'. It should be a unique, descriptive name including verb that describes what the function does. Do not include the word 'function' or 'Stackwise' in the name unless it is in the brief.
Respond with nothing but the name of the function. Literally the only thing in your response should be the name of the function.`,
// TODO: pass previous names and ask not the same unless it absolutely has to be
},
],
temperature: 0.3,
});
return response.choices[0].message.content;
} catch (error) {
console.error('Error querying OpenAI:', error);
throw error;
}
}
}