watsonx go
v1.0.1
watsonx-go
es un cliente watsonx para Go
go get -u github.com/IBM/watsonx-go
import (
wx "github.com/IBM/watsonx-go/pkg/models"
)
export WATSONX_API_KEY= " YOUR WATSONX API KEY "
export WATSONX_PROJECT_ID= " YOUR WATSONX PROJECT ID "
Crear un cliente:
client , _ := wx . NewClient ()
O pase los secretos requeridos directamente:
client , err := wx . NewClient (
wx . WithWatsonxAPIKey ( apiKey ),
wx . WithWatsonxProjectID ( projectID ),
)
Generación:
result , _ := client . GenerateText (
"meta-llama/llama-3-1-8b-instruct" ,
"Hi, who are you?" ,
wx . WithTemperature ( 0.4 ),
wx . WithMaxNewTokens ( 512 ),
)
println ( result . Text )
Generación de corriente:
dataChan , _ := client . GenerateTextStream (
"meta-llama/llama-3-1-8b-instruct" ,
"Hi, who are you?" ,
wx . WithTemperature ( 0.4 ),
wx . WithMaxNewTokens ( 512 ),
)
for data := range dataChan {
print ( data . Text ) // print the result as it's being generated
}
Incrustación | Consulta única:
result , _ := client . EmbedQuery (
"ibm/slate-30m-english-rtrvr" ,
"Hello, world!" ,
wx . WithEmbeddingTruncateInputTokens ( 2 ),
wx . WithEmbeddingReturnOptions ( true ),
)
embeddingVector := result . Results [ 0 ]. Embedding
Incrustación | Varios documentos:
result , _ := clientl . EmbedDocuments (
"ibm/slate-30m-english-rtrvr" ,
[] string { "Hello, world!" , "Goodbye, world!" },
wx . WithEmbeddingTruncateInputTokens ( 2 ),
wx . WithEmbeddingReturnOptions ( true ),
)
for _ , doc := range result . Results {
fmt . Println ( doc . Embedding )
}
export WATSONX_API_KEY= " YOUR WATSONX API KEY "
export WATSONX_PROJECT_ID= " YOUR WATSONX PROJECT ID "
go test ./...
Ejecute el siguiente comando para ejecutar el formato de confirmación previa:
git config --local core.hooksPath .githooks/
Hay dos métodos para configurar el cliente Watsonx para usarlo con el entorno de prueba:
Especifique la URL de Watsonx y el punto final de IAM mediante variables de entorno:
export WATSONX_URL_HOST= " us-south.ml.test.cloud.ibm.com "
export WATSONX_IAM_HOST= " iam.test.cloud.ibm.com "
NewClient
Especifique la URL de Watsonx y el punto final de IAM a través de los parámetros de la función NewClient:
client , err := wx . NewClient (
wx . WithURL ( "us-south.ml.test.cloud.ibm.com" ),
wx . WithIAM ( "iam.test.cloud.ibm.com" ),
wx . WithWatsonxAPIKey ( apiKey ),
wx . WithWatsonxProjectID ( projectID ),
)