From ed10ade455608ff9fa210435ea3049dbfa29c69d Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Wed, 28 Aug 2024 15:09:38 +0200 Subject: [PATCH] make it work --- pom.xml | 5 ++ src/main/java/eu/m724/Main.java | 18 ++++++-- src/main/java/eu/m724/chat/Chat.java | 12 ++++- src/main/java/eu/m724/chat/ChatMessage.java | 12 +++-- .../java/eu/m724/example/ExampleSource.groovy | 46 +++++++++++++++++++ .../eu/m724/responsesource/ChatResponse.java | 23 +++++++++- .../responsesource/ChatResponseSource.java | 4 +- .../eu/m724/responsesource/net/Requester.java | 4 ++ thinking.txt | 1 + 9 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/main/java/eu/m724/example/ExampleSource.groovy create mode 100644 src/main/java/eu/m724/responsesource/net/Requester.java diff --git a/pom.xml b/pom.xml index 76f9835..d606ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,11 @@ groovy 4.0.22 + + com.google.code.gson + gson + 2.11.0 + \ No newline at end of file diff --git a/src/main/java/eu/m724/Main.java b/src/main/java/eu/m724/Main.java index c8f937e..1c68170 100644 --- a/src/main/java/eu/m724/Main.java +++ b/src/main/java/eu/m724/Main.java @@ -1,12 +1,22 @@ package eu.m724; +import eu.m724.chat.Chat; +import eu.m724.chat.ChatMessage; +import eu.m724.example.ExampleSource; +import eu.m724.responsesource.ChatResponse; +import eu.m724.responsesource.ChatResponseSource; import groovy.lang.GroovyShell; public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); - GroovyShell shell = new GroovyShell(); - Object result = shell.evaluate("2 + 2"); - System.out.println(result); + ChatResponseSource source = new ExampleSource(); + + Chat chat = new Chat(); + chat.messages.add(new ChatMessage(false, "hello")); + + ChatResponse chatResponse = source.ask(chat); + + System.out.println(chatResponse.text().join()); + System.out.println(chatResponse.message().text); } } \ No newline at end of file diff --git a/src/main/java/eu/m724/chat/Chat.java b/src/main/java/eu/m724/chat/Chat.java index 861b939..44cffee 100644 --- a/src/main/java/eu/m724/chat/Chat.java +++ b/src/main/java/eu/m724/chat/Chat.java @@ -1,5 +1,15 @@ package eu.m724.chat; -public class Chat { +import java.util.ArrayList; +import java.util.List; +public class Chat { + public String systemPrompt = null; // TODO move that away? + public List messages = new ArrayList<>(); + + public Chat(String systemPrompt) { + this.systemPrompt = systemPrompt; + } + + public Chat() {} } diff --git a/src/main/java/eu/m724/chat/ChatMessage.java b/src/main/java/eu/m724/chat/ChatMessage.java index 5cd6c04..0cd975a 100644 --- a/src/main/java/eu/m724/chat/ChatMessage.java +++ b/src/main/java/eu/m724/chat/ChatMessage.java @@ -1,8 +1,14 @@ package eu.m724.chat; -public interface ChatMessage { - boolean isStreaming(); +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Flow; - String getContent(); +public class ChatMessage { + public boolean assistant; + public String text; // TODO make it private and modifiable other way + public ChatMessage(boolean assistant, String text) { + this.assistant = assistant; + this.text = text; + } } diff --git a/src/main/java/eu/m724/example/ExampleSource.groovy b/src/main/java/eu/m724/example/ExampleSource.groovy new file mode 100644 index 0000000..4d86ba0 --- /dev/null +++ b/src/main/java/eu/m724/example/ExampleSource.groovy @@ -0,0 +1,46 @@ +package eu.m724.example + +import eu.m724.chat.Chat +import eu.m724.chat.ChatMessage +import eu.m724.responsesource.ChatResponse +import eu.m724.responsesource.ChatResponseSource +import eu.m724.responsesource.ChatResponseSourceInfo + +import java.util.concurrent.CompletableFuture + +/** + * an example chatresponsesource chatresponsesource ChatResponseSource CHATRESPONSESOURCE CAHTSERREPOSNECSOURCE + * note to self: rename that already... + */ +class ExampleSource implements ChatResponseSource { + private ChatResponseSourceInfo info = + new ChatResponseSourceInfo("yo", "ye", "1.0", 1) + + @Override + ChatResponseSourceInfo info() { + return info + } + + @Override + ChatResponse ask(Chat chat) { + return new ChatResponse() { + String[] parts + CompletableFuture completableFuture = new CompletableFuture<>(); + + @Override + boolean isStreaming() { + return false + } + + @Override + CompletableFuture text() { + return CompletableFuture.completedFuture("hello how can i assist you today") + } + + @Override + ChatMessage message() { + return new ChatMessage(true, "i assisted you already bye") + } + } + } +} diff --git a/src/main/java/eu/m724/responsesource/ChatResponse.java b/src/main/java/eu/m724/responsesource/ChatResponse.java index 5b3b17a..2abb90e 100644 --- a/src/main/java/eu/m724/responsesource/ChatResponse.java +++ b/src/main/java/eu/m724/responsesource/ChatResponse.java @@ -1,6 +1,27 @@ package eu.m724.responsesource; +import eu.m724.chat.ChatMessage; + +import java.util.concurrent.CompletableFuture; + public interface ChatResponse { + /** + * is this response streaming + * @return is this response streaming + */ boolean isStreaming(); - // TODO + + /** + * if streamed, text token by token as it goes (or other splitting depending on the source) + * if not, the {@link CompletableFuture} returns just the whole response after it's ready + * @return yeah + */ + CompletableFuture text(); // TODO completablefuture is not correct here also fix the doc + + /** + * gets the resulting {@link ChatMessage} + * TODO I think it should be available after streaming is done so maybe wrap this in {@link CompletableFuture} + * @return the resulting {@link ChatMessage} + */ + ChatMessage message(); } diff --git a/src/main/java/eu/m724/responsesource/ChatResponseSource.java b/src/main/java/eu/m724/responsesource/ChatResponseSource.java index 9835f73..2f9a2c6 100644 --- a/src/main/java/eu/m724/responsesource/ChatResponseSource.java +++ b/src/main/java/eu/m724/responsesource/ChatResponseSource.java @@ -1,7 +1,9 @@ package eu.m724.responsesource; +import eu.m724.chat.Chat; + public interface ChatResponseSource { ChatResponseSourceInfo info(); - ChatResponse + ChatResponse ask(Chat chat); } diff --git a/src/main/java/eu/m724/responsesource/net/Requester.java b/src/main/java/eu/m724/responsesource/net/Requester.java new file mode 100644 index 0000000..b48dd24 --- /dev/null +++ b/src/main/java/eu/m724/responsesource/net/Requester.java @@ -0,0 +1,4 @@ +package eu.m724.responsesource.net; + +public interface Requester { +} diff --git a/thinking.txt b/thinking.txt index 4a586d7..386a2e8 100644 --- a/thinking.txt +++ b/thinking.txt @@ -52,6 +52,7 @@ here's what claude recommended to consider: (I only edited the headers) | Piet | No | Very limited | Requires interpreter | Minimal | N/A | For when your code should literally be a work of art | | C# | No | Limited | Often required | Very active | Yes | Java's arch-nemesis with a Microsoft accent | +I think the name "source" is fine, but I don't think that's how the class should be named because it may be confused with java stuff similar thing probably exists... I'm sure it does, but I do it as I'd like, maybe it will end up being better sorry for such mess, I'm typing fast so I don't forget, and I'm out of water as for now, and distracting music