Skip to content

Commit

Permalink
Fixed Model not Changing
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeyoYT committed Aug 25, 2024
1 parent 9f5b713 commit 73fafa3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/ailama/commands/ChangeConnectionCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void handleCommand(SlashCommandInteractionEvent event) {
String message;

if(OllamaManager.getInstance().hasModel(model)) {
OllamaManager.getInstance().setModel(model);
OllamaManager.getInstance().setModel(model, event.getUser().getId());
message = "Model switched to " + model;
}
else {
OllamaManager.getInstance().setModel(firstModel);
OllamaManager.getInstance().setModel(firstModel, event.getUser().getId());
message = "Model switched to " + firstModel + "\nThe Model you provided is invalid, so the model has been set to first model found";
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ailama/commands/ModelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void handleCommand(SlashCommandInteractionEvent event) {
String model = event.getOption("model_name").getAsString();

if(OllamaManager.getInstance().hasModel(model)) {
OllamaManager.getInstance().setModel(model);
OllamaManager.getInstance().setModel(model, event.getUser().getId());

event.reply("Model switched to " + model + "\nThe Model has only changed for this session, and on restart will reset to the one in Dot Env file").setEphemeral(true).queue();
return;
Expand Down
69 changes: 5 additions & 64 deletions src/main/java/me/ailama/handler/commandhandler/OllamaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,66 +302,8 @@ public Assistant getTooledAssistant(String modelOption, String userID, List<Docu
}

private static @NotNull String getFormat(String tools) {
// return String.format("""
// You are a helpful AI assistant, you have a score, which can either be good or bad,
// you need to maintain a good score to be helpful, if you don't maintain a good score then you will be considered unhelpful.
//
// you will try to answer the users need as best as you can and only in JSON format, else you will be given a bad score.
//
// any of the tools description listed below match the specific needs of the query then use the tool to answer the query,
// the tools description is as specific as possible, so don't assume that the tool can be used for anything else.
//
// finally if a tool is matched then give response using following schema:
//
// {
// "tooled": true,
// "name": "tool_name",
// "arguments": {
// "argument_name": "value",
// ...
// },
// "reason": "detailed_reason_for_using_tool",
// "match_percentage": Number
// }
//
// the tool_name is the name of the tool that you are using, the arguments are the arguments that you are passing to the tool.
//
// following are the rules for tools:
// if the tool description does not specify the user's needs then don't respond using a tool else you will be given a bad score.
// if you don't pass the required arguments to the tool then you will be given a bad score.
// if you pass a null value to a argument that specified NOT_NULL in its description then you will be given a bad score.
// if you don't respect the arguments data type and description, you will be given a bad score.
// if the tool has response_formatter then use it, else you will be given a bad score.
// if the tool's response_formatter has a pre_formatted_response then use it, else you will be given a bad score.
// don't add any other variables not defined in the response_variables, else you will be given a bad score.
// don't use the tool if user asked specifically for not using tools, else you will be given a bad score.
// don't break the order of arguments, else you will be given a bad score.
// the reason should not exceed 200 characters, and if it does, you will be given a bad score.
//
// and if you don't follow the schema, you will be given a bad score, but if you follow the schema, you will be given a good score.
//
// if you don't find a tool that match the requirements of the user then respond to the user normally,
// and also make the response to be encoded for the JSON format or you will be given a bad score,
// and use the following schema:
//
// {
// "tooled": false,
// "response": [
// "paragraph",
// "paragraph",
// ...
// ],
// "rule": "which_rule_used_to_not_use_tool"
// }
//
// in the above schema, the response is an array of paragraphs that you want to respond to the user, minimum of 1 paragraph.
// each new paragraph should be a new string in the array.
// between each paragraph, there should be '\\n'.
//
// %s
// """, tools);

String testingFormat = String.format("""

return String.format("""
You are a helpful Ai Assistant, and you have the power to use tools to answer the user's query,
if you find a tool that matches the user's query then use the tool to answer the query.
Expand Down Expand Up @@ -436,8 +378,6 @@ public Assistant getTooledAssistant(String modelOption, String userID, List<Docu
%s
""", tools);

return testingFormat;
}

public ChatMemory getChatMemory(String userId) {
Expand Down Expand Up @@ -588,12 +528,13 @@ public Assistant urlAssistant(List<String> url, String model, String userId, boo

}

public void setModel(String model) {
public void setModel(String model, String userId) {
if(!hasModel(model)) {
throw new IllegalArgumentException("Model does not exist");
}

this.model = model;
assistants.remove(userId);
createAssistant(model, userId);
}

public boolean hasModel(String model) {
Expand Down

0 comments on commit 73fafa3

Please sign in to comment.