Skip to content

Commit

Permalink
fixing top_p by adding serialized name
Browse files Browse the repository at this point in the history
  • Loading branch information
namankhurpia committed Mar 14, 2024
1 parent c630c88 commit 965d064
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/io/github/namankhurpia/DAO/AsyncDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class AsyncDAOImpl implements AsyncApiInterface {
ChatCompletionResponse chatCompletionResponseObj;

VisionApiResponse visionApiResponseObj;

private static Logger LOGGER = LoggerFactory.getLogger(AsyncDAOImpl.class);

RetrofitApiInterface retrofitApiInterfaceObj;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.github.namankhurpia.Documentation;

import io.github.namankhurpia.DAO.DAOImpl;
import io.github.namankhurpia.Pojo.ChatCompletion.ChatCompletionRequest;
import io.github.namankhurpia.Pojo.ChatCompletion.ChatCompletionResponse;
import io.github.namankhurpia.Pojo.ChatCompletion.Message;
import io.github.namankhurpia.Service.EasyopenaiService;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class IssueSolving {

public static void main(String[] args) throws IOException {

usingTopp();
}

public static void usingTopp() throws IOException {
ArrayList<String> keys = readKeys();
Message message = Message.builder()
.role("user")
.content("what is the capital of Cambodia?")
.build();

List<Message> messages = new ArrayList<>();
messages.add(message);

ChatCompletionRequest request = ChatCompletionRequest.builder()
.model("gpt-3.5-turbo")
.messages(messages)
.temperature(1.0d)
.topP(1.0d)
.build();

ChatCompletionResponse response = new EasyopenaiService(new DAOImpl()).chatCompletion(keys.get(0),request);
System.out.println(response);

}

public static ArrayList<String> readKeys()
{
String filePath = "keys.txt";
ArrayList<String> keyList = new ArrayList<>();

// Open the file using Scanner
try {
File file = new File(filePath);
Scanner scanner = new Scanner(file);

// Read each line and extract keys
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// Assuming each line contains a key
keyList.add(line);
//System.out.println("Key: " + line);
}

// Close the scanner
scanner.close();
} catch (FileNotFoundException e) {
System.out.println("File not found: " + filePath);
e.printStackTrace();
}
return keyList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class RunnerForAsync {
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {


RunnerForAsync_chatCompletion();
RunnerForAsync_ModerationAPI();
RunnerForAsync_VisionAPI();
Expand All @@ -47,6 +46,7 @@ public static void RunnerForAsync_chatCompletion() throws IOException, Executio
request_chat.setModel("gpt-3.5-turbo");
request_chat.setMessages(messages); //old conversations as well
ChatCompletionResponse response_chat = easyopenaiAsyncService_chat.getAsyncChatCompletion(keys.get(0),request_chat);
System.out.println(response_chat);
}

public static void RunnerForAsync_ModerationAPI() throws IOException, ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.namankhurpia.Pojo.ChatCompletion;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -115,6 +116,8 @@ public class ChatCompletionRequest {
* with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.<br>
* We generally recommend altering this or temperature but not both.
*/

@SerializedName("top_p")
@JsonProperty("top_p")
Double topP;

Expand Down

0 comments on commit 965d064

Please sign in to comment.