Skip to content

Commit

Permalink
ConfigurableLanguageModel implements Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
lesters committed Nov 29, 2024
1 parent 0f0d6a9 commit f4869ec
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
13 changes: 6 additions & 7 deletions model-integration/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"ai.vespa.llm.clients.ConfigurableLanguageModel" : {
"superClass" : "java.lang.Object",
"interfaces" : [
"ai.vespa.llm.LanguageModel"
"ai.vespa.llm.LanguageModel",
"com.yahoo.language.process.Generator"
],
"attributes" : [
"public",
Expand All @@ -14,7 +15,8 @@
"protected java.lang.String getApiKey(ai.vespa.llm.InferenceParameters)",
"protected void setApiKey(ai.vespa.llm.InferenceParameters)",
"protected java.lang.String getEndpoint()",
"protected void setEndpoint(ai.vespa.llm.InferenceParameters)"
"protected void setEndpoint(ai.vespa.llm.InferenceParameters)",
"public java.lang.String generate(ai.vespa.llm.completion.Prompt, com.yahoo.language.process.Generator$Context)"
],
"fields" : [ ]
},
Expand Down Expand Up @@ -174,17 +176,14 @@
},
"ai.vespa.llm.clients.OpenAI" : {
"superClass" : "ai.vespa.llm.clients.ConfigurableLanguageModel",
"interfaces" : [
"com.yahoo.language.process.Generator"
],
"interfaces" : [ ],
"attributes" : [
"public"
],
"methods" : [
"public void <init>(ai.vespa.llm.clients.LlmClientConfig, ai.vespa.secret.Secrets)",
"public java.util.List complete(ai.vespa.llm.completion.Prompt, ai.vespa.llm.InferenceParameters)",
"public java.util.concurrent.CompletableFuture completeAsync(ai.vespa.llm.completion.Prompt, ai.vespa.llm.InferenceParameters, java.util.function.Consumer)",
"public java.lang.String generate(ai.vespa.llm.completion.Prompt, com.yahoo.language.process.Generator$Context)"
"public java.util.concurrent.CompletableFuture completeAsync(ai.vespa.llm.completion.Prompt, ai.vespa.llm.InferenceParameters, java.util.function.Consumer)"
],
"fields" : [ ]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ai.vespa.secret.Secrets;
import com.yahoo.api.annotations.Beta;
import com.yahoo.component.annotation.Inject;
import com.yahoo.language.process.Generator;

import java.util.HashMap;
import java.util.logging.Logger;
Expand All @@ -19,7 +20,7 @@
* @author lesters
*/
@Beta
public abstract class ConfigurableLanguageModel implements LanguageModel {
public abstract class ConfigurableLanguageModel implements LanguageModel, Generator {

private static final Logger log = Logger.getLogger(ConfigurableLanguageModel.class.getName());

Expand Down Expand Up @@ -77,4 +78,15 @@ protected void setEndpoint(InferenceParameters params) {
}
}

@Override
public String generate(Prompt prompt, Context context) {
var params = new HashMap<String, String>();
var options = new InferenceParameters(params::get);
setApiKey(options);

var completions = complete(prompt, options);
var firstCompletion = completions.get(0);
return firstCompletion.text();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import ai.vespa.llm.completion.Prompt;
import com.yahoo.component.AbstractComponent;
import com.yahoo.component.annotation.Inject;
import com.yahoo.document.DataType;
import com.yahoo.language.process.Generator;
import de.kherud.llama.LlamaModel;
import de.kherud.llama.ModelParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author lesters
*/
@Beta
public class OpenAI extends ConfigurableLanguageModel implements Generator {
public class OpenAI extends ConfigurableLanguageModel {

private final OpenAiClient client;

Expand All @@ -47,10 +47,5 @@ public CompletableFuture<Completion.FinishReason> completeAsync(Prompt prompt,
return client.completeAsync(prompt, parameters, consumer);
}

@Override
public String generate(Prompt prompt, Context context) {
return GeneratorUtils.generate(prompt, this);
}

}

2 changes: 2 additions & 0 deletions quickbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mvn clean install --threads 1C -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -DskipTests "$@"

0 comments on commit f4869ec

Please sign in to comment.