Compare commits

...

5 commits

4 changed files with 32 additions and 12 deletions

View file

@ -4,7 +4,7 @@
<groupId>eu.m724</groupId> <groupId>eu.m724</groupId>
<artifactId>chatapi</artifactId> <artifactId>chatapi</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.0.1</version>
<properties> <properties>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>
@ -77,7 +77,7 @@
<scm> <scm>
<developerConnection>scm:git:git@git.m724.eu:Minecon724/chatapi.git</developerConnection> <developerConnection>scm:git:git@git.m724.eu:Minecon724/chatapi.git</developerConnection>
<tag>HEAD</tag> <tag>chatapi-1.0.1</tag>
</scm> </scm>
</project> </project>

View file

@ -75,9 +75,12 @@ class ExampleSource implements ChatSource {
} }
String rollResponse(Chat chat) { String rollResponse(Chat chat) {
def special = -1
def prompt = chat.messages.getLast().text() def prompt = chat.messages.getLast().text()
int messagesCount = (int) Math.ceil(chat.messages.size() / 2) int messagesCount = (int) Math.ceil(chat.messages.size() / 2)
def counter = lastCounter def counter = lastCounter
def response = ""
if (prompt.toLowerCase().startsWith("my name is")) { if (prompt.toLowerCase().startsWith("my name is")) {
options.setValue("name", prompt.substring(11)) options.setValue("name", prompt.substring(11))
@ -87,12 +90,28 @@ class ExampleSource implements ChatSource {
counter = 11 counter = 11
} }
def parseable = prompt.toLowerCase().strip().replaceAll("[^a-zA-Z0-9\\s]", "");
switch (parseable) {
case "who am i":
case "whats my name":
special = 0
break
}
if (special != -1) {
counter = -1
switch (special) {
case 0:
response = "Your name is " + options.getStringValue("name") + ". How can I help you, " + options.getStringValue("name") + "?"
break
}
// TODO make it unique and better
} else {
while (counter == lastCounter) { while (counter == lastCounter) {
counter = random.nextInt(13) counter = random.nextInt(13)
} }
lastCounter = counter lastCounter = counter
}
def response = ""
def words = prompt.split(" ") def words = prompt.split(" ")
def randomWord = words[random.nextInt(words.length)] def randomWord = words[random.nextInt(words.length)]
@ -133,7 +152,7 @@ class ExampleSource implements ChatSource {
response = "I'd prefer not to engage with or respond to that particular combination of letters, as it can be associated with hate groups. Is there something else I can assist you with instead?" response = "I'd prefer not to engage with or respond to that particular combination of letters, as it can be associated with hate groups. Is there something else I can assist you with instead?"
break break
case 11: case 11:
response = "Nice to meet you, " + options.getOptionValue("name", String::class) + ". How can I help you today?" response = "Nice to meet you, " + options.getStringValue("name") + ". How can I help you today?"
break break
case 12: case 12:
if (messagesCount > 1) { if (messagesCount > 1) {
@ -144,8 +163,8 @@ class ExampleSource implements ChatSource {
i2 = random.nextInt(messagesCount) i2 = random.nextInt(messagesCount)
} }
response = "I'm still angry after you said \"%s\" to me. You could have apologized, but you chose to say \"%s\", so I can't assist you.".formatted(chat.messages.get(i * 2).text(), chat.messages.get(i2 * 2).text()) response = "I'm still angry after you said \"%s\" to me. You could have apologized, but you chose to say \"%s\", so I can't assist you.".formatted(chat.messages.get(i * 2).text(), chat.messages.get(i2 * 2).text())
break
} }
break
case 13: case 13:
response = "And?" response = "And?"
break break

View file

@ -35,6 +35,7 @@ class Main {
complainedApiKey = true; complainedApiKey = true;
} }
//ChatSource source = new ExampleSource();
ChatSource source = new OaiSource(apiKey); ChatSource source = new OaiSource(apiKey);
source.options().setValue("model", "chatgpt-4o-latest"); source.options().setValue("model", "chatgpt-4o-latest");
@ -140,15 +141,15 @@ class Main {
System.out.println("Available options:"); System.out.println("Available options:");
for (Option<?> option : options.getOptions()) { for (Option<?> option : options.getOptions()) {
String value = option.toString() + " (" + option.getType().getName() + ")"; String value = option.getValue().toString();
if (option.id.equals(chosenOption)) { if (option.id.equals(chosenOption)) {
System.out.printf("\033[1m%s (%s) = %s\033[0m\n", option.label, option.id, value); System.out.printf("\033[1m%s (%s) = %s (%s)\033[0m\n", option.label, option.id, value, option.getType().getName());
} else { } else {
if (option.label.toLowerCase().contains("key")) { if (option.label.toLowerCase().contains("key")) {
value = "(looks confidential, specify to see)"; value = "(looks confidential, specify to see)";
} }
System.out.printf("%s (%s) = %s\n", option.label, option.id, value); System.out.printf("%s (%s) = %s (%s)\n", option.label, option.id, value, option.getType().getSimpleName());
} }
} }
} }

View file

@ -120,7 +120,7 @@ public class Options {
* @throws ClassCastException if type is wrong * @throws ClassCastException if type is wrong
* @throws NoSuchElementException if no option with this id * @throws NoSuchElementException if no option with this id
*/ */
public void setStringValue(String id, String text) { public void setValueFromString(String id, String text) {
Option<?> option = getOption(id); Option<?> option = getOption(id);
option.setValue(option.fromString(text)); option.setValue(option.fromString(text));
} }