For full setup and authentication options, see the Installation guide: Installation guide and Authentication.
Parameters
Configuration for the client connection.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Unique identifier of the endpoint to invoke.
Arguments passed to the endpoint as a key-value map.
Request options for runtime behavior and configuration.
Metadata associated with the request for tracking and analytics.
Usage
from rapida import (
ConnectionConfig,
EndpointDefinition,
InvokeRequest,
invoke,
string_to_any,
)
from pprint import pprint
connection_config = ConnectionConfig.default_connection_config(
ConnectionConfig.with_sdk("{your-rapida-api-key}")
)
argument_value = string_to_any("Hello how are you doing")
metadata_value = string_to_any("metadata_to_track")
option_value = string_to_any("4567898656789")
response = invoke(
client_cfg=connection_config,
request=InvokeRequest(
endpoint=EndpointDefinition(endpointId=2223006263292198912),
args={"can": argument_value},
metadata={"test": metadata_value},
options={"opts1": option_value},
),
)
pprint(response)
package main
import (
"context"
"fmt"
clients "github.com/rapidaai/rapida-go/rapida/clients"
rapida_proto "github.com/rapidaai/rapida-go/rapida/clients/protos"
connections "github.com/rapidaai/rapida-go/rapida/connections"
"github.com/rapidaai/rapida-go/rapida/utils"
"google.golang.org/protobuf/types/known/anypb"
)
func main() {
// for more authentication check https://doc.rapida.ai/api-reference/authentication
connectionConfig := connections.
DefaultconnectionConfig(connections.WithSDK("RAPIDA_PROJECT_CREDENTIAL"))
argumentValue, _ := utils.StringToAny("Hello how are you doing")
metadataValue, _ := utils.StringToAny("metadata_to_track")
optionValue, _ := utils.Int64ToAny(4567898656789)
response, _ := clients.Invoke(context.Background(), connectionConfig, &rapida_proto.InvokeRequest{
Endpoint: &rapida_proto.EndpointDefinition{
EndpointId: RAPIDA_ENDPOINT_ID,
},
Args: map[string]*anypb.Any{
"can": argumentValue,
},
Metadata: map[string]*anypb.Any{
"test": metadataValue,
},
Options: map[string]*anypb.Any{
"opts1": optionValue,
},
})
for _, content:= range response.GetMetrics() {
fmt.Println(string(content.Name), string(content.Value))
}
for _, content:= range response.GetData() {
fmt.Println(string(content.GetContent()))
}
}
import {
Invoke,
ConnectionConfig,
GetEndpoint,
InvokeRequest,
EndpointDefinition,
StringToAny,
ToContentText
} from "@rapidaai/nodejs";
(async () => {
const connectionCfg = ConnectionConfig.DefaultConnectionConfig(
ConnectionConfig.WithSDK({
ApiKey: process.env.RAPIDA_PROJECT_CREDENTIAL,
})
);
invokeEndpoint(connectionCfg)
})();
async function invokeEndpoint(connectionCfg) {
const request = new InvokeRequest();
let endpointDef = new EndpointDefinition();
endpointDef.setEndpointid(RAPIDA_ENDPOINT_ID);
endpointDef.setVersion("latest");
request.setEndpoint(endpointDef);
request.getArgsMap().set("can", StringToAny("Prompt_ARGUMENT"));
request.getArgsMap().set("can", StringToAny("Prompt_ARGUMENT_2"));
// metadata
request.getMetadataMap().set("track", StringToAny("metadata_to_track"));
// options
request.getOptionsMap().set("model_options", StringToAny("x"));
const response = await Invoke(connectionCfg, request);
if (response.getError()) {
console.error(
"Error invoking endpoint:",
response.getError()?.getHumanmessage()
);
} else {
console.log("Endpoint invoked successfully:", ToContentText(response.getDataList()));
response.getMetricsList().forEach(x => console.log(x.getName(), x.getValue()))
}
}
Response
Numeric status code for the operation.
Indicates whether the operation was successful.
Unique ID for tracking the request.
Duration of the operation in milliseconds.