Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 252db27

Browse filesBrowse files
authored
Update EditResult and fix the Edit test (TheoKanning#26)
OpenAI's example curl used an invalid engine, and the api returned a confusing error message. Now everything works with text-davinci-edit-001
1 parent ff06ffb commit 252db27
Copy full SHA for 252db27

File tree

Expand file treeCollapse file tree

4 files changed

+44
-9
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+44
-9
lines changed

‎api/src/main/java/com/theokanning/openai/edit/EditRequest.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/edit/EditRequest.java
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.theokanning.openai.edit;
22

3-
import lombok.AllArgsConstructor;
4-
import lombok.Builder;
5-
import lombok.Data;
6-
import lombok.NoArgsConstructor;
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.*;
75

86
/**
97
* Given a prompt and an instruction, OpenAi will return an edited version of the prompt
@@ -25,8 +23,14 @@ public class EditRequest {
2523
* The instruction that tells the model how to edit the prompt.
2624
* For example, "Fix the spelling mistakes"
2725
*/
26+
@NonNull
2827
String instruction;
2928

29+
/**
30+
* How many edits to generate for the input and instruction.
31+
*/
32+
Integer n;
33+
3034
/**
3135
* What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
3236
*
@@ -39,5 +43,6 @@ public class EditRequest {
3943
*
4044
* We generally recommend altering this or {@link EditRequest#temperature} but not both.
4145
*/
46+
@JsonProperty("top_p")
4247
Double topP;
4348
}

‎api/src/main/java/com/theokanning/openai/edit/EditResult.java

Copy file name to clipboardExpand all lines: api/src/main/java/com/theokanning/openai/edit/EditResult.java
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public class EditResult {
2626
* A list of generated edits.
2727
*/
2828
List<EditChoice> choices;
29+
30+
/**
31+
* The API usage for this request
32+
*/
33+
EditUsage usage;
2934
}
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.theokanning.openai.edit;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* An object containing the API usage for an edit request
7+
*
8+
* https://beta.openai.com/docs/api-reference/edits/create
9+
*/
10+
@Data
11+
public class EditUsage {
12+
13+
/**
14+
* The number of prompt tokens consumed.
15+
*/
16+
String promptTokens;
17+
18+
/**
19+
* The number of completion tokens consumed.
20+
*/
21+
String completionTokens;
22+
23+
/**
24+
* The number of total tokens consumed.
25+
*/
26+
String totalTokens;
27+
}

‎client/src/test/java/com/theokanning/openai/EditTest.java

Copy file name to clipboardExpand all lines: client/src/test/java/com/theokanning/openai/EditTest.java
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import com.theokanning.openai.edit.EditRequest;
44
import com.theokanning.openai.edit.EditResult;
5-
import org.junit.jupiter.api.Disabled;
65
import org.junit.jupiter.api.Test;
76

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertNotNull;
98

10-
@Disabled // disabled until edit example CURL works
119
public class EditTest {
1210

1311
String token = System.getenv("OPENAI_TOKEN");
@@ -20,8 +18,8 @@ void edit() {
2018
.instruction("Fix the spelling mistakes")
2119
.build();
2220

23-
EditResult result = service.createEdit("text-ada-001", request);
21+
EditResult result = service.createEdit("text-davinci-edit-001", request);
2422

25-
assertEquals("What day of the week is it?", result.getChoices().get(0).getText());
23+
assertNotNull(result.getChoices().get(0).getText());
2624
}
2725
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.