Compare commits

...

2 commits

Author SHA1 Message Date
ed10ade455
make it work 2024-08-28 15:09:38 +02:00
40cb1a012c
think 2024-08-28 13:42:32 +02:00
10 changed files with 174 additions and 15 deletions

View file

@ -1,7 +1,3 @@
This is a Java library you can write scripts for to support an api with conversational language models
The scripts are written in Groovy because it's powerful, but I'm thinking about other languages like Lua (which has not many features but I think some can be added)
Right now there is no sandboxing so every script has access to what this library has access
Don't take everything I wrote here for granted because I still have to think about how to make this stuff
I can't really say much because I'm still working out stuff so see `thinking.txt`

View file

@ -20,6 +20,11 @@
<artifactId>groovy</artifactId>
<version>4.0.22</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>

View file

@ -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);
}
}

View file

@ -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<ChatMessage> messages = new ArrayList<>();
public Chat(String systemPrompt) {
this.systemPrompt = systemPrompt;
}
public Chat() {}
}

View file

@ -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;
}
}

View 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")
}
}
}
}

View file

@ -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<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();
}

View file

@ -1,7 +1,9 @@
package eu.m724.responsesource;
import eu.m724.chat.Chat;
public interface ChatResponseSource {
ChatResponseSourceInfo info();
ChatResponse
ChatResponse ask(Chat chat);
}

View file

@ -0,0 +1,4 @@
package eu.m724.responsesource.net;
public interface Requester {
}

59
thinking.txt Normal file
View file

@ -0,0 +1,59 @@
okay so three things:
1. the chat, thread, conversation itself
2. the network thing
3. and something to script all that?
the chat I think it may be just messages, like user assistant and so on with an optional system prompt
however that may cause issues with tool models, but let's ignore that for now
oh yeah and something to convert the Chat into something the api accepts, but I think that may be just a function
now about requests
I think that's consistent so get post etc. requests
with text or json request body
that responds with a text or json body
but how?
I think a DIY interface is the way since each (or every?) platform has a different networking implementation
we could provide a reference implementation, but I don't know
okay now about scripting
the language that scripts are written in is Groovy
which may be too powerful to be called a scripting language but whatever
so:
- we need to label scripts somehow so a record (actually an object because I want to be compatible) with name, author, version is enough
and other metadata like streaming support or billing? billing later and TODO streaming should be also a setting
- permissions... that for later, including sandboxing
- settings, oh I just came up a name "source"
but as for settings maybe just a list of label, TODO type (slider, text, choice list etc.) and value range (how with various types is for later)
- and how it actually works, like when a message is sent we just call a function with the chat object.
it should return a ChatResponse which TODO has something to stream from and some other metadata?
choice of language
lua:
I considered Lua, but I don't know, it may be simpler to beginners (not to me though) but it's not as powerful and like javascript messy, inconsistent, vague etc.
actually I just found out Lua has coroutines, so maybe I was wrong
and a few more dependencies won't hurt
other languages:
I need a runtime that's maintained and up to date with the language, that doesn't rely on native libraries, and that wouldn't take much storage
here's what claude recommended to consider: (I only edited the headers)
| Language | JVM-based | Java Interop | Native Libraries | Maintenance | Sandboxing | CRINGE Notes |
|----------------------|-----------|--------------|----------------------|-------------|----------------------|-------------------------------------------------------|
| Groovy | Yes | Excellent | Not required | Active | Yes | Java's cool cousin who brings beer to family reunions |
| Kotlin | Yes | Excellent | Not required | Very active | Yes (careful config) | The overachiever making Java feel insecure |
| Lua (LuaJ) | Yes | Good | Not required | Moderate | Yes | The tiny language that could (and did) |
| JavaScript (GraalVM) | Yes | Good | Not required | Active | Yes | "I'm everywhere!" - JavaScript, probably |
| Python (Jython) | Yes | Good | Not required | Moderate | Yes | Like a snake in Java clothing |
| Scala | Yes | Excellent | Not required | Active | Yes (careful config) | For when you want your code to look like algebra |
| Clojure | Yes | Good | Not required | Active | Yes | Parentheses enthusiast's dream come true |
| Ruby (JRuby) | Yes | Good | Not required | Active | Yes | The language that makes programmers feel like poets |
| BeanShell | Yes | Excellent | Not required | Less active | Yes | Java's echo... echo... echo... |
| Rhino | Yes | Good | Not required | Less active | Yes | The JavaScript engine that refuses to go extinct |
| Frege | Yes | Good | Not required | Less active | Yes | Haskell's attempt at Java world domination |
| COBOL | Partially | Limited | Often required | Limited | Limited | Your grandpa's favorite programming language |
| 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
okay so my 22 track favorite list just ended so bye