watsonx go
v1.0.1
watsonx-go
é um 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 "
Crie um cliente:
client , _ := wx . NewClient ()
Ou passe diretamente os segredos necessários:
client , err := wx . NewClient (
wx . WithWatsonxAPIKey ( apiKey ),
wx . WithWatsonxProjectID ( projectID ),
)
Geração:
result , _ := client . GenerateText (
"meta-llama/llama-3-1-8b-instruct" ,
"Hi, who are you?" ,
wx . WithTemperature ( 0.4 ),
wx . WithMaxNewTokens ( 512 ),
)
println ( result . Text )
Geração de fluxo:
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
}
Incorporação | Consulta única:
result , _ := client . EmbedQuery (
"ibm/slate-30m-english-rtrvr" ,
"Hello, world!" ,
wx . WithEmbeddingTruncateInputTokens ( 2 ),
wx . WithEmbeddingReturnOptions ( true ),
)
embeddingVector := result . Results [ 0 ]. Embedding
Incorporação | Vários 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 ./...
Execute o seguinte comando para executar a formatação pré-confirmação:
git config --local core.hooksPath .githooks/
Existem dois métodos para configurar o cliente watsonx a ser usado com o ambiente de teste:
Especifique a URL do Watsonx e o terminal IAM usando variáveis de ambiente:
export WATSONX_URL_HOST= " us-south.ml.test.cloud.ibm.com "
export WATSONX_IAM_HOST= " iam.test.cloud.ibm.com "
NewClient
Especifique a URL do Watsonx e o terminal IAM por meio dos parâmetros da função 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 ),
)