Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -147441,6 +147441,7 @@ class Chat {
console.time('code-review cost');
const prompt = this.generatePrompt(patch);
const isReasoning = this.isReasoningModel;
const temperature = Number(process.env.temperature || 1);
const res = await this.openai.chat.completions.create({
messages: [
{
Expand All @@ -147450,7 +147451,7 @@ class Chat {
],
model: this.model,
...(isReasoning ? {} : {
temperature: +(process.env.temperature || 0) || 1,
temperature: Number.isFinite(temperature) ? temperature : 1,
top_p: +(process.env.top_p || 0) || 1,
}),
max_tokens: process.env.max_tokens ? +process.env.max_tokens : undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Chat {
const prompt = this.generatePrompt(patch);

const isReasoning = this.isReasoningModel;
const temperature = Number(process.env.temperature || 1);

const res = await this.openai.chat.completions.create({
messages: [
Expand All @@ -109,7 +110,7 @@ export class Chat {
],
model: this.model,
...(isReasoning ? {} : {
temperature: +(process.env.temperature || 0) || 1,
temperature: Number.isFinite(temperature) ? temperature : 1,
top_p: +(process.env.top_p || 0) || 1,
}),
max_tokens: process.env.max_tokens ? +process.env.max_tokens : undefined,
Expand Down
17 changes: 17 additions & 0 deletions test/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ describe("Chat", () => {
expect(callArgs.response_format).toEqual({ type: "json_object" });
});

test.each(["0", "0.0"])("preserves zero temperature %s", async (temperature) => {
process.env.MODEL = "gpt-4o";
process.env.temperature = temperature;
const chat = new Chat("test-key");
await chat.codeReview("@@ -1 +1 @@\n-old\n+new");
expect(mockCreate.mock.calls[0][0].temperature).toBe(0);
});

test.each([undefined, "", "invalid"])("defaults temperature %s to one", async (temperature) => {
process.env.MODEL = "gpt-4o";
if (temperature === undefined) delete process.env.temperature;
else process.env.temperature = temperature;
const chat = new Chat("test-key");
await chat.codeReview("@@ -1 +1 @@\n-old\n+new");
expect(mockCreate.mock.calls[0][0].temperature).toBe(1);
});

test("returns empty review for empty patch", async () => {
const chat = new Chat("test-key");
const result = await chat.codeReview("");
Expand Down