Skip to content

Instantly share code, notes, and snippets.

@davila7
Created December 15, 2022 20:20
Show Gist options
  • Select an option

  • Save davila7/3fd811856c9930db26e20f9b513b5ec8 to your computer and use it in GitHub Desktop.

Select an option

Save davila7/3fd811856c9930db26e20f9b513b5ec8 to your computer and use it in GitHub Desktop.
const few_shot_text = `Bot: Ask me any question.
Me: Can I ask you something about programming?.
Bot: Yes, of course. Tell me your question and I will answer it
Me: My question about Javascript is: Write a JavaScript function to apply Bubble Sort algorithm.
Bot:
Here is a JavaScript function to apply Bubble Sort algorithm:
function bubbleSort(arr) {
let swapped;
do {
swapped = false;
for (let i = 0; i < arr.length; i++) {
if (arr[i] > arr[i + 1]) {
let temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
swapped = true;
}
}
} while (swapped);
return arr;
}
Me: Can you write the same function in Python?
Bot:`;
async function main() {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: few_shot_text,
temperature: 0,
max_tokens: 250,
top_p: 1.0,
frequency_penalty: 0.5,
presence_penalty: 0.0,
stop: ["END"],
});
console.log(completion.data.choices[0].text)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment