Compare commits

..

5 commits

4 changed files with 32 additions and 12 deletions

View file

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

View file

@ -75,9 +75,12 @@ class ExampleSource implements ChatSource {
}
String rollResponse(Chat chat) {
def special = -1
def prompt = chat.messages.getLast().text()
int messagesCount = (int) Math.ceil(chat.messages.size() / 2)
def counter = lastCounter
def response = ""
if (prompt.toLowerCase().startsWith("my name is")) {
options.setValue("name", prompt.substring(11))
@ -87,12 +90,28 @@ class ExampleSource implements ChatSource {
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) {
counter = random.nextInt(13)
}
lastCounter = counter
def response = ""
}
def words = prompt.split(" ")
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?"
break
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
case 12:
if (messagesCount > 1) {
@ -144,8 +163,8 @@ class ExampleSource implements ChatSource {
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())
break
}
break
case 13:
response = "And?"
break

View file

@ -35,6 +35,7 @@ class Main {
complainedApiKey = true;
}
//ChatSource source = new ExampleSource();
ChatSource source = new OaiSource(apiKey);
source.options().setValue("model", "chatgpt-4o-latest");
@ -140,15 +141,15 @@ class Main {
System.out.println("Available options:");
for (Option<?> option : options.getOptions()) {
String value = option.toString() + " (" + option.getType().getName() + ")";
String value = option.getValue().toString();
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 {
if (option.label.toLowerCase().contains("key")) {
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 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.setValue(option.fromString(text));
}