Skip to content

Commit 3037cce

Browse files
Initial commit
0 parents  commit 3037cce

14 files changed

+492
-0
lines changed

.gitignore

Whitespace-only changes.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SilentGPT
2+
3+
This tool monitors the clipboard for new copy events, sends the content to the ChatGPT API, and replaces the clipboard content with the response.
4+
5+
## Features
6+
7+
- No API key required
8+
- Its running in the background so no one can actually see that you are using SilentGPT
9+
- Copy specific commands to your clipboard for running actions (read below)
10+
- This tool can remember the previous conversation like in the normal ChatGPT interface
11+
- This tool can play a sound (windows sound) for notifying you as soon as the answer is in your clipboard
12+
13+
## Commands
14+
15+
If you want to execute one of the following actions you just have to copy the command into your clipboard
16+
- Close SilentGPT
17+
```
18+
SILENTGPT_CLOSE
19+
```
20+
- Toggle notifications (disabled by default)
21+
```
22+
SILENTGPT_NOTIFY
23+
```
24+
- Toggle remembering conversations (disabled by default)
25+
```
26+
SILENTGPT_REMEMBER_CONVERSATION
27+
```
28+
29+
## Installation
30+
31+
1. **Requirements:**
32+
- Java Development Kit (JDK) 11 or higher
33+
34+
2. **Download:**
35+
- Download the latest release from the [Releases page](https://github.com/SocketC0nnection/SilentGPT/releases).
36+
37+
## Usage
38+
39+
1. **Start:**
40+
- Run the JAR file via command-line or just double click it:
41+
42+
```sh
43+
java -jar SilentGPT.jar
44+
```
45+
46+
2. **Monitor Clipboard:**
47+
- Copy text to the clipboard. The tool will automatically send the text to the ChatGPT API and replace the clipboard content with the response.
48+
49+
## Contributions
50+
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
51+
52+
## License
53+
This project is licensed under the MIT License. See the LICENSE file for details.
54+
55+
## Acknowledgements
56+
- Gson for JSON processing
57+
- [aiforcause](https://github.com/brahmai-research/aiforcause) for accessing ChatGPT API

SilentGPT.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="gson-2.10.1" level="project" />
11+
</component>
12+
</module>

src/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: net.socket.silentgpt.SilentGPT
3+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package net.socket.silentgpt;
2+
3+
import net.socket.silentgpt.client.HttpClient;
4+
import net.socket.silentgpt.commands.CloseCommand;
5+
import net.socket.silentgpt.commands.NotificationCommand;
6+
import net.socket.silentgpt.commands.RememberConversationCommand;
7+
import net.socket.silentgpt.handlers.ClipboardUpdateHandler;
8+
import net.socket.silentgpt.managers.ClipboardManager;
9+
import net.socket.silentgpt.managers.CommandManager;
10+
import net.socket.silentgpt.managers.ConversationManager;
11+
12+
public class SilentGPT {
13+
14+
private static SilentGPT instance;
15+
16+
private final ClipboardManager clipboardManager;
17+
private final CommandManager commandManager;
18+
private final ConversationManager conversationManager;
19+
20+
private final HttpClient httpClient;
21+
22+
private boolean notification;
23+
private boolean rememberConversation;
24+
25+
public SilentGPT() {
26+
instance = this;
27+
28+
clipboardManager = new ClipboardManager();
29+
commandManager = new CommandManager();
30+
conversationManager = new ConversationManager();
31+
httpClient = new HttpClient(this);
32+
33+
commandManager.register(new CloseCommand());
34+
commandManager.register(new NotificationCommand());
35+
commandManager.register(new RememberConversationCommand());
36+
37+
new ClipboardUpdateHandler(this).start();
38+
}
39+
40+
public static void main(String[] args) {
41+
new SilentGPT();
42+
}
43+
44+
public HttpClient getHttpClient() {
45+
return httpClient;
46+
}
47+
48+
public ConversationManager getConversationManager() {
49+
return conversationManager;
50+
}
51+
52+
public CommandManager getCommandManager() {
53+
return commandManager;
54+
}
55+
56+
public ClipboardManager getClipboardManager() {
57+
return clipboardManager;
58+
}
59+
60+
public boolean getRememberConversation() {
61+
return rememberConversation;
62+
}
63+
64+
public void setRememberConversation(boolean rememberConversation) {
65+
this.rememberConversation = rememberConversation;
66+
}
67+
68+
public boolean getNotification() {
69+
return notification;
70+
}
71+
72+
public void setNotification(boolean notification) {
73+
this.notification = notification;
74+
}
75+
76+
public static SilentGPT getInstance() {
77+
return instance;
78+
}
79+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package net.socket.silentgpt.client;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonArray;
5+
import com.google.gson.JsonObject;
6+
import net.socket.silentgpt.SilentGPT;
7+
import net.socket.silentgpt.managers.ConversationManager;
8+
9+
import java.net.URI;
10+
import java.net.http.HttpRequest;
11+
import java.net.http.HttpResponse;
12+
13+
public class HttpClient {
14+
15+
private final Gson gson;
16+
private final java.net.http.HttpClient client;
17+
18+
private final SilentGPT silentGPT;
19+
20+
public HttpClient(SilentGPT silentGPT) {
21+
gson = new Gson();
22+
client = java.net.http.HttpClient.newHttpClient();
23+
24+
this.silentGPT = silentGPT;
25+
}
26+
27+
public String send(String question) {
28+
JsonObject object = new JsonObject();
29+
30+
JsonArray messages;
31+
32+
if(silentGPT.getRememberConversation()) {
33+
messages = silentGPT.getConversationManager().getMessages();
34+
35+
silentGPT.getConversationManager().addMessage(ConversationManager.Role.USER, question);
36+
} else {
37+
messages = new JsonArray();
38+
39+
JsonObject message = new JsonObject();
40+
41+
message.addProperty("role", "user");
42+
message.addProperty("content", question);
43+
44+
messages.add(message);
45+
}
46+
47+
object.addProperty("model", "gpt-35-turbo");
48+
object.add("messages", messages);
49+
object.addProperty("stream", false);
50+
51+
String text = "";
52+
53+
try {
54+
HttpRequest request = HttpRequest.newBuilder()
55+
.uri(new URI("https://aiforcause.deepnight.tech/openai/"))
56+
.header("Content-Type", "application/json")
57+
.header("Authorization", "Bearer IDK")
58+
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(object)))
59+
.build();
60+
61+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
62+
63+
JsonObject jsonReponse = gson.fromJson(response.body(), JsonObject.class);
64+
65+
text = jsonReponse
66+
.getAsJsonArray("choices")
67+
.get(0)
68+
.getAsJsonObject()
69+
.getAsJsonObject("message")
70+
.get("content")
71+
.getAsString();
72+
73+
silentGPT.getConversationManager().addMessage(ConversationManager.Role.ASSISTANT, text);
74+
} catch (Exception ignored) {}
75+
76+
return text;
77+
}
78+
79+
public SilentGPT getSilentGPT() {
80+
return silentGPT;
81+
}
82+
83+
public java.net.http.HttpClient getClient() {
84+
return client;
85+
}
86+
87+
public Gson getGson() {
88+
return gson;
89+
}
90+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.socket.silentgpt.commands;
2+
3+
public class CloseCommand extends Command {
4+
5+
public CloseCommand() {
6+
super("SILENTGPT_CLOSE");
7+
}
8+
9+
@Override
10+
public void onExecute() {
11+
System.exit(0);
12+
}
13+
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.socket.silentgpt.commands;
2+
3+
public abstract class Command {
4+
5+
private final String command;
6+
7+
public Command(String command) {
8+
this.command = command;
9+
}
10+
11+
public abstract void onExecute();
12+
13+
public String getCommand() {
14+
return command;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.socket.silentgpt.commands;
2+
3+
import net.socket.silentgpt.SilentGPT;
4+
5+
public class NotificationCommand extends Command {
6+
7+
public NotificationCommand() {
8+
super("SILENTGPT_NOTIFY");
9+
}
10+
11+
@Override
12+
public void onExecute() {
13+
SilentGPT.getInstance().setNotification(!SilentGPT.getInstance().getNotification());
14+
}
15+
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.socket.silentgpt.commands;
2+
3+
import net.socket.silentgpt.SilentGPT;
4+
5+
public class RememberConversationCommand extends Command {
6+
7+
public RememberConversationCommand() {
8+
super("SILENTGPT_REMEMBER_CONVERSATION");
9+
}
10+
11+
@Override
12+
public void onExecute() {
13+
SilentGPT.getInstance().setRememberConversation(!SilentGPT.getInstance().getRememberConversation());
14+
15+
if(SilentGPT.getInstance().getRememberConversation()) {
16+
SilentGPT.getInstance().getConversationManager().reset();
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)