Skip to content

Commit

Permalink
♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
PlexPt committed Dec 12, 2022
1 parent 45fa1d8 commit 25c2bd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/github/plexpt/chatgpt/Chatbot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Chatbot {
private String cfClearance;
private String userAgent;
private String parentId;
private Map<String, String> headers;
private Map<String, String> headers = new HashMap<>();

private String conversationIdPrev;
private String parentIdPrev;
Expand Down Expand Up @@ -260,12 +260,15 @@ public void refreshSession() {
// Set cookies
session.getCookies().put("__Secure-next-auth.session-token", sessionToken);
session.getCookies().put("cf_clearance", cfClearance);
Map<String, String> map = new HashMap<>();
map.put("User-Agent", userAgent);
session.setHeaders(map);

String urlSession = "https://chat.openai.com/api/auth/session";
HttpResponse response = session.get2(urlSession,
Collections.singletonMap("User-Agent", userAgent));
HttpResponse response = session.get2(urlSession);

if (response.getStatus() != 200) {
System.out.println("err code: " + response.getStatus());
System.err.println("err code: " + response.getStatus());
System.out.println("cf_clearance: " + cfClearance);
System.out.println("token: " + sessionToken);
System.out.println("userAgent: " + userAgent);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/github/plexpt/chatgpt/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public Response get(String url, Map<String, String> data) {
return response;
}

public HttpResponse get2(String url, Map<String, String> data) {
public HttpResponse get2(String url) {
getCookiesString();

Map<String, Object> map = new HashMap<>(data);
return HttpUtil.createGet(url)
.addHeaders(headers)
.cookie(getCookiesString())
.form(map)
.execute();
}

Expand Down

0 comments on commit 25c2bd2

Please sign in to comment.