make it work
This commit is contained in:
parent
40cb1a012c
commit
ed10ade455
9 changed files with 115 additions and 10 deletions
5
pom.xml
5
pom.xml
|
@ -20,6 +20,11 @@
|
||||||
<artifactId>groovy</artifactId>
|
<artifactId>groovy</artifactId>
|
||||||
<version>4.0.22</version>
|
<version>4.0.22</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,12 +1,22 @@
|
||||||
package eu.m724;
|
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;
|
import groovy.lang.GroovyShell;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello world!");
|
ChatResponseSource source = new ExampleSource();
|
||||||
GroovyShell shell = new GroovyShell();
|
|
||||||
Object result = shell.evaluate("2 + 2");
|
Chat chat = new Chat();
|
||||||
System.out.println(result);
|
chat.messages.add(new ChatMessage(false, "hello"));
|
||||||
|
|
||||||
|
ChatResponse chatResponse = source.ask(chat);
|
||||||
|
|
||||||
|
System.out.println(chatResponse.text().join());
|
||||||
|
System.out.println(chatResponse.message().text);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,15 @@
|
||||||
package eu.m724.chat;
|
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<ChatMessage> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
public Chat(String systemPrompt) {
|
||||||
|
this.systemPrompt = systemPrompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chat() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package eu.m724.chat;
|
package eu.m724.chat;
|
||||||
|
|
||||||
public interface ChatMessage {
|
import java.util.concurrent.CompletableFuture;
|
||||||
boolean isStreaming();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
46
src/main/java/eu/m724/example/ExampleSource.groovy
Normal file
46
src/main/java/eu/m724/example/ExampleSource.groovy
Normal file
|
@ -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<String> completableFuture = new CompletableFuture<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isStreaming() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
CompletableFuture<String> text() {
|
||||||
|
return CompletableFuture.completedFuture("hello how can i assist you today")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
ChatMessage message() {
|
||||||
|
return new ChatMessage(true, "i assisted you already bye")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,27 @@
|
||||||
package eu.m724.responsesource;
|
package eu.m724.responsesource;
|
||||||
|
|
||||||
|
import eu.m724.chat.ChatMessage;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface ChatResponse {
|
public interface ChatResponse {
|
||||||
|
/**
|
||||||
|
* is this response streaming
|
||||||
|
* @return is this response streaming
|
||||||
|
*/
|
||||||
boolean isStreaming();
|
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<String> 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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package eu.m724.responsesource;
|
package eu.m724.responsesource;
|
||||||
|
|
||||||
|
import eu.m724.chat.Chat;
|
||||||
|
|
||||||
public interface ChatResponseSource {
|
public interface ChatResponseSource {
|
||||||
ChatResponseSourceInfo info();
|
ChatResponseSourceInfo info();
|
||||||
|
|
||||||
ChatResponse
|
ChatResponse ask(Chat chat);
|
||||||
}
|
}
|
||||||
|
|
4
src/main/java/eu/m724/responsesource/net/Requester.java
Normal file
4
src/main/java/eu/m724/responsesource/net/Requester.java
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package eu.m724.responsesource.net;
|
||||||
|
|
||||||
|
public interface Requester {
|
||||||
|
}
|
|
@ -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 |
|
| 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 |
|
| 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
|
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
|
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
|
||||||
|
|
Loading…
Reference in a new issue