Class CompatOAIModel
java.lang.Object
com.google.genkit.plugins.compatoai.CompatOAIModel
- All Implemented Interfaces:
Model,Action<ModelRequest,,ModelResponse, ModelResponseChunk> Registerable
OpenAI-compatible API model implementation for Genkit.
This implementation can be used by any provider that offers an
OpenAI-compatible API endpoint.
-
Constructor Summary
ConstructorsConstructorDescriptionCompatOAIModel(String modelName, String label, CompatOAIPluginOptions options) Creates a new CompatOAIModel (backward compatible - uses modelName for both).CompatOAIModel(String modelName, String apiModelName, String label, CompatOAIPluginOptions options) Creates a new CompatOAIModel with separate Genkit and API model names. -
Method Summary
Modifier and TypeMethodDescriptiongetInfo()Gets information about the model's capabilities.getName()Returns the name of the action.run(ActionContext context, ModelRequest request) Generates a response from the given request.run(ActionContext context, ModelRequest request, Consumer<ModelResponseChunk> streamCallback) Generates a streaming response from the given request.booleanReturns whether this model supports streaming.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.google.genkit.ai.Model
getDesc, getInputSchema, getMetadata, getOutputSchema, getType, register, runJson, runJsonWithTelemetry
-
Constructor Details
-
CompatOAIModel
public CompatOAIModel(String modelName, String apiModelName, String label, CompatOAIPluginOptions options) Creates a new CompatOAIModel with separate Genkit and API model names.- Parameters:
modelName- the Genkit model name (e.g., "groq/llama-3.3-70b-versatile")apiModelName- the API model name (e.g., "llama-3.3-70b-versatile")label- the display label (e.g., "Groq llama-3.3-70b-versatile")options- the plugin options
-
CompatOAIModel
Creates a new CompatOAIModel (backward compatible - uses modelName for both).- Parameters:
modelName- the model name (e.g., "gpt-4", "grok-beta")label- the display label (e.g., "XAI grok-beta")options- the plugin options
-
-
Method Details
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<ModelRequest,ModelResponse, ModelResponseChunk> - Returns:
- the action name
-
getInfo
Description copied from interface:ModelGets information about the model's capabilities. -
supportsStreaming
public boolean supportsStreaming()Description copied from interface:ModelReturns whether this model supports streaming.- Specified by:
supportsStreamingin interfaceModel- Returns:
- true if streaming is supported
-
run
Description copied from interface:ModelGenerates a response from the given request.- Specified by:
runin interfaceAction<ModelRequest,ModelResponse, ModelResponseChunk> - Specified by:
runin interfaceModel- Parameters:
context- the action contextrequest- the model request- Returns:
- the model response
-
run
public ModelResponse run(ActionContext context, ModelRequest request, Consumer<ModelResponseChunk> streamCallback) Description copied from interface:ModelGenerates a streaming response from the given request.- Specified by:
runin interfaceAction<ModelRequest,ModelResponse, ModelResponseChunk> - Specified by:
runin interfaceModel- Parameters:
context- the action contextrequest- the model requeststreamCallback- callback for streaming chunks- Returns:
- the final model response
-