log the response

This commit is contained in:
Jack Driscoll 2024-07-27 09:00:01 -07:00
commit 62fdb56591

View file

@ -5,6 +5,7 @@ import { Octokit } from "@octokit/rest";
import parseDiff, { Chunk, File } from "parse-diff"; import parseDiff, { Chunk, File } from "parse-diff";
import minimatch from "minimatch"; import minimatch from "minimatch";
import { parse } from "path"; import { parse } from "path";
import { APIPromise } from "openai/core";
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY"); const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
@ -132,11 +133,12 @@ async function getAIResponse(prompt: string): Promise<Array<{
presence_penalty: 0, presence_penalty: 0,
}; };
let response: OpenAI.Chat.Completions.ChatCompletion | null = null;
try { try {
const response = await openai.chat.completions.create({ response = await openai.chat.completions.create({
...queryConfig, ...queryConfig,
// return JSON if the model supports it: // return JSON if the model supports it:
response_format: { type: "json_object" }, response_format: { type: "json_object" as const },
messages: [ messages: [
{ {
role: "system", role: "system",
@ -156,7 +158,7 @@ async function getAIResponse(prompt: string): Promise<Array<{
const res = response.choices[0].message?.content?.trim() || "{}"; const res = response.choices[0].message?.content?.trim() || "{}";
return JSON.parse(res).reviews; return JSON.parse(res).reviews;
} catch (error) { } catch (error) {
console.error("Error:", error); console.error("Error:", error, response?.choices[0].message?.content);
return null; return null;
} }
} }