autoheal
Version:
GPT Test driven development. Automatically fix tests and guide GPT to write and fix code using your tests.
38 lines (37 loc) • 1.73 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import chalk from "chalk";
import { Configuration, OpenAIApi } from "openai";
export function prompt(messages, model) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
try {
const searchTermsResponse = yield openai.createChatCompletion({
model,
temperature: 0.9,
messages,
});
return (_b = (_a = searchTermsResponse.data.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content;
}
catch (e) {
if (e.response.data.error) {
console.log(chalk.red('\nOpenAI API error: "' + e.response.data.error.message + '"'));
}
else {
console.log(chalk.red("\nOpenAI API error: " + e.message));
}
return "";
}
});
}