-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from namankhurpia/dev
Concurrent Async Chat Completion with Multiple keys
- Loading branch information
Showing
12 changed files
with
275 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
src/main/java/io/github/namankhurpia/Interfaces/ConcurrentApiInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package io.github.namankhurpia.Interfaces; | ||
|
||
import io.github.namankhurpia.Pojo.ChatCompletion.ChatCompletionRequest; | ||
import io.github.namankhurpia.Pojo.MyModels.ChatCompletionRequestList; | ||
import io.github.namankhurpia.Pojo.MyModels.ChatCompletionResponseList; | ||
import io.github.namankhurpia.Pojo.MyModels.ModerationRequestList; | ||
import io.github.namankhurpia.Pojo.MyModels.ModerationResponseList; | ||
|
||
import java.util.ArrayList; | ||
|
||
public interface ConcurrentApiInterface { | ||
|
||
ModerationResponseList CallMultipleModerationAPI(String key,ModerationRequestList requestList); | ||
|
||
ChatCompletionResponseList CallMultipleChatCompletionAPI(String key, ChatCompletionRequestList requestList); | ||
|
||
ChatCompletionResponseList CallMultipleChatCompletionAPI(ArrayList<String> keyList, ChatCompletionRequestList requestList); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.github.namankhurpia; | ||
|
||
import io.github.namankhurpia.DAO.AsyncDAOImpl; | ||
import io.github.namankhurpia.Pojo.ChatCompletion.ChatCompletionRequest; | ||
import io.github.namankhurpia.Pojo.ChatCompletion.ChatCompletionResponse; | ||
import io.github.namankhurpia.Pojo.ChatCompletion.ChatMessage; | ||
import io.github.namankhurpia.Pojo.Moderations.ModerationAPIRequest; | ||
import io.github.namankhurpia.Pojo.Moderations.ModerationAPIResponse; | ||
import io.github.namankhurpia.Service.EasyopenaiAsyncService; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import static io.github.namankhurpia.Interfaces.EndPoints.OPENAI_KEY; | ||
|
||
public class RunnerForAsync { | ||
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { | ||
|
||
/** | ||
* Asynchronous chat | ||
*/ | ||
|
||
EasyopenaiAsyncService easyopenaiAsyncService_chat = new EasyopenaiAsyncService(new AsyncDAOImpl()); | ||
|
||
ChatMessage chatMessage = new ChatMessage(); | ||
chatMessage.setRole("user"); | ||
chatMessage.setContent("what is the capital of combodia?"); | ||
|
||
List<ChatMessage> messages = new ArrayList<>(); | ||
messages.add(chatMessage); | ||
|
||
ChatCompletionRequest request_chat = new ChatCompletionRequest(); | ||
request_chat.setModel("gpt-3.5-turbo"); | ||
request_chat.setMessages(messages); //old conversations as well | ||
ChatCompletionResponse response_chat = easyopenaiAsyncService_chat.getAsyncChatCompletion(OPENAI_KEY,request_chat); | ||
|
||
/** | ||
* Asynchronous moderation | ||
*/ | ||
|
||
EasyopenaiAsyncService easyopenaiAsyncService_mod = new EasyopenaiAsyncService(new AsyncDAOImpl()); | ||
|
||
ModerationAPIRequest request_mod = new ModerationAPIRequest(); | ||
request_mod.setInput("kill me now"); | ||
request_mod.setModel("text-moderation-latest"); | ||
|
||
ModerationAPIResponse response_mod = easyopenaiAsyncService_mod.getASyncModeration(OPENAI_KEY,request_mod); | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/io/github/namankhurpia/RunnerForSingleInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.github.namankhurpia; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class RunnerForSingleInstance { | ||
public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { | ||
System.out.println("Hello world!"); | ||
|
||
/** | ||
* Moderation API single | ||
*/ | ||
/* | ||
ModerationAPIRequest request = new ModerationAPIRequest(); | ||
request.setInput("kill me now"); | ||
request.setModel("text-moderation-latest"); | ||
EasyopenaiService obj = new EasyopenaiService(new DAOImpl()); | ||
ModerationAPIResponse res = obj.getmoderation(OPENAI_KEY,request); | ||
*/ | ||
|
||
/** | ||
* Chat Completion API single | ||
*/ | ||
/* | ||
EasyopenaiService obj = new EasyopenaiService(new DAOImpl()); | ||
ChatMessage chatMessage = new ChatMessage(); | ||
chatMessage.setRole("user"); | ||
chatMessage.setContent("what is the capital of combodia?"); | ||
List<ChatMessage> messages = new ArrayList<>(); | ||
messages.add(chatMessage); | ||
ChatCompletionRequest request = new ChatCompletionRequest(); | ||
request.setModel("gpt-3.5-turbo"); | ||
request.setMessages(messages); //old conversations as well | ||
ChatCompletionResponse res = obj.chatCompletion(OPENAI_KEY,request); | ||
*/ | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
Oops, something went wrong.