-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from tjake/tool-calling
Add tool calling support
- Loading branch information
Showing
29 changed files
with
592 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ public interface Generator { | |
enum FinishReason { | ||
MAX_TOKENS, | ||
STOP_TOKEN, | ||
TOOL_CALL, | ||
ERROR | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
jlama-core/src/main/java/com/github/tjake/jlama/safetensors/prompt/Function.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.github.tjake.jlama.safetensors.prompt; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.google.common.base.Preconditions; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* FunctionObject | ||
*/ | ||
@JsonPropertyOrder({Function.JSON_PROPERTY_NAME, Function.JSON_PROPERTY_DESCRIPTION, Function.JSON_PROPERTY_PARAMETERS}) | ||
public class Function { | ||
public static final String JSON_PROPERTY_NAME = "name"; | ||
private final String name; | ||
|
||
public static final String JSON_PROPERTY_DESCRIPTION = "description"; | ||
private final String description; | ||
|
||
public static final String JSON_PROPERTY_PARAMETERS = "parameters"; | ||
private final Parameters parameters; | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private String name; | ||
private String description = ""; | ||
|
||
private Parameters.Builder parameters = Parameters.builder(); | ||
|
||
public Builder description(String description) { | ||
this.description = description; | ||
return this; | ||
} | ||
|
||
public Builder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder addParameter(String name, String type, String description, boolean required) { | ||
this.parameters.addProperty(name, type, description, required); | ||
return this; | ||
} | ||
|
||
public Builder addParameter(String name, Map<String, Object> properties, boolean required) { | ||
this.parameters.addProperty(name, properties, required); | ||
return this; | ||
} | ||
|
||
public Function build() { | ||
Preconditions.checkNotNull(name, "name is required"); | ||
|
||
return new Function(name, description, parameters.build()); | ||
} | ||
} | ||
|
||
private Function(String name, String description, Parameters parameters) { | ||
this.name = name; | ||
this.description = description; | ||
this.parameters = parameters; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public Parameters getParameters() { | ||
return parameters; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
jlama-core/src/main/java/com/github/tjake/jlama/safetensors/prompt/Parameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.github.tjake.jlama.safetensors.prompt; | ||
|
||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* Parameters | ||
*/ | ||
@JsonPropertyOrder({ | ||
Parameters.JSON_PROPERTY_TYPE, | ||
Parameters.JSON_PROPERTY_PROPERTIES, | ||
Parameters.JSON_PROPERTY_REQUIRED}) | ||
public class Parameters { | ||
|
||
public static final String JSON_PROPERTY_TYPE = "type"; | ||
private final String type = "object"; | ||
|
||
public static final String JSON_PROPERTY_PROPERTIES = "properties"; | ||
private final Map<String, Map<String, Object>> properties; | ||
|
||
public static final String JSON_PROPERTY_REQUIRED = "required"; | ||
private List<String> required; | ||
|
||
public Parameters(Map<String, Map<String, Object>> properties, List<String> required) { | ||
this.properties = properties; | ||
this.required = required; | ||
} | ||
|
||
public Parameters(Map<String, Map<String, Object>> properties) { | ||
this.properties = properties; | ||
this.required = null; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
private Map<String, Map<String, Object>> properties = new LinkedHashMap<>(); | ||
private Set<String> required = new LinkedHashSet<>(); | ||
|
||
public Builder addProperty(String name, String type, String description, boolean required) { | ||
Map<String, Object> properties = new LinkedHashMap<>(); | ||
properties.put("type", type); | ||
properties.put("description", description); | ||
return addProperty(name, properties, required); | ||
} | ||
|
||
public Builder addProperty(String name, Map<String, Object> properties, boolean required) { | ||
this.properties.put(name, properties); | ||
if (required) { | ||
this.required.add(name); | ||
} | ||
return this; | ||
} | ||
|
||
public Parameters build() { | ||
return new Parameters(properties, new ArrayList<>(required)); | ||
} | ||
} | ||
|
||
public String getType() { | ||
return this.type; | ||
} | ||
|
||
public Map<String, Map<String, Object>> getProperties() { | ||
return properties; | ||
} | ||
|
||
public List<String> getRequired() { | ||
return required; | ||
} | ||
} |
Oops, something went wrong.