Skip to content

Commit

Permalink
Fix #191
Browse files Browse the repository at this point in the history
  • Loading branch information
obiscr committed Apr 18, 2023
1 parent 73a7fd7 commit e7ea274
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 91 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/obiscr/chatgpt/ChatGPTHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.fastjson2.JSON;
import com.intellij.openapi.project.Project;
import com.obiscr.chatgpt.core.builder.OfficialBuilder;
import com.obiscr.chatgpt.core.parser.OfficialParser;
import com.obiscr.chatgpt.settings.OpenAISettingsState;
import com.obiscr.chatgpt.ui.MainPanel;
Expand All @@ -21,6 +22,7 @@
import java.io.IOException;
import java.net.Proxy;
import java.nio.charset.StandardCharsets;
import java.util.Stack;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -32,6 +34,7 @@ public class ChatGPTHandler extends AbstractHandler {

private static final Logger LOG = LoggerFactory.getLogger(ChatGPTHandler.class);

private final Stack<String> gpt35Stack = new Stack<>();

public EventSource handle(MainPanel mainPanel, MessageComponent component, String question) {
myProject = mainPanel.getProject();
Expand Down Expand Up @@ -102,6 +105,14 @@ public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Null
if (parseResult == null) {
return;
}
if (!mainPanel.isChatGPTModel()) {
if (data.contains("\"finish_reason\":\"stop\"")) {
mainPanel.getContentPanel().getMessages().add(OfficialBuilder.assistantMessage(gpt35Stack.pop()));
gpt35Stack.clear();
} else {
gpt35Stack.push(parseResult.getSource());
}
}
// Copy action only needed source content
component.setSourceContent(parseResult.getSource());
component.setContent(parseResult.getHtml());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/obiscr/chatgpt/RequestProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class RequestProvider {

public static final String OFFICIAL_CONVERSATION_URL = "https://bypass.churchless.tech/api/conversation";
public static final String OFFICIAL_CONVERSATION_URL = "https://ai.fakeopen.com/api/conversation";
public static final String OFFICIAL_GPT35_TURBO_URL = "https://api.openai.com/v1/chat/completions";
private Project myProject;
private String url;
Expand Down
Loading

0 comments on commit e7ea274

Please sign in to comment.