The GenAI API also provides the convenience methods described in
this section under the ml
namespace. These methods act as wrappers for the
LLM
methods; rather than being
invoked as LLM instance methods, they take the model ID as one
one of the options passed to them.
ml.generate()
and
ml.rag()
return only the text
portions of the values returned by their LLM counterparts.
This method is wrapper for
LLM.generate()
. It loads the
model specified by the model_id
specified as one of the options
,
generates a response based on the prompt using this model, and
returns the response. The default model_id
("cohere.command"
) is used if one is not
specified.
Arguments
prompt
(String
) (default"cohere.command"
): The desired promptoptions
(Object
) (default{}
): The options employed for generation; these follow the same rules as the options used withLLM.generate()
Return type
String
: The text of the response
Usage
// Both invocations use "cohere.command" as the model_id let response = ml.generate("What is Mysql?", {max_tokens: 10}) let response = ml.generate("What is Mysql?", {model_id: "cohere.command", max_tokens: 10})
This method is a wrapper for
LLM.embed()
.
Arguments
query
(String
): Text of a natural-language queryoptions
(Object
) (default{}
): The options employed for generation; these follow the same rules as the options used withLLM.embed()
; the defaultmodel_id
is"all_minilm_l12_v2"
Return type
Float32Array
(MySQLVECTOR
): The embedding
Usage
// These produce the same result let embedding = ml.embed("What is Mysql?", {model_id: "all_minilm_l12_v2"}) let embedding = ml.embed("What is Mysql?", {})
This is a wrapper for
LLM.rag()
.
Arguments
query
(String
): Text of a natural-language queryoptions
(Object
) (default{}
): The options employed for generation; these follow the same rules as the options used withLLM.rag()
; the defaultmodel_id
is"mistral-7b-instruct-v1"
Return type
String
: Response text
Usage
// These produce the same result let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1, model_options: {model_id: "mistral-7b-instruct-v1"}}) let result = ml.rag("What is MySql?", {schema: ["vector_store"], n_citations: 1})