Go SDK
Overview​
With the "openapi-generator-cli" Python package and the OpenAPI specification file for the h2oGPTe REST API, we generated SDKs in multiple programming languages, enabling quick integration with the API. One of the SDKs generated is the Go SDK.
- Download Go SDK
Steps to generate and test the Go SDK​
-
Create a Go project named "my-project" and initiate it:
mkdir my-project
cd my-project
go mod init my-project -
Download the OpenAPI specification file of the h2oGPTe REST API and move it to the "my-project" folder: Download api-spec.yaml.
-
In the "my-project" directory, set up a Python environment with Python 3.8 or later and install the OpenAPI Generator CLI v7.10.0:
python3 -m venv venv
source venv/bin/activate
pip install openapi-generator-cli==7.10.0 -
In the "my-project" directory, run the following command (CLI) to create the Go SDK using the OpenAPI Generator CLI:
openapi-generator-cli generate \
-i rest_api_spec_h2ogpte.yaml \
-g go \
-o h2ogpte_rest_client \
--additional-properties=packageName=h2ogpte_rest_client,packageVersion=1.6.2,projectName=h2ogpte_rest_client,goModuleName=h2ogpte_rest_client,isGoSubmodule=true -
In the "my-project" directory, create a work file to add the "h2ogpte_rest_api" module:
go work init
go work use ./h2ogpte_rest_client -
In the "my-project" directory, create the following file to test the newly created Go SDK (in particular, let's create a Collection to test the SDK):
touch create_a_collection.go
create_a_collection.gopackage main
import (
"context"
"fmt"
"os"
openapiclient "github.com/GIT_USER_ID/GIT_REPO_ID/h2ogpte_rest_client"
)
func main() {
collectionCreateRequest := *openapiclient.NewCollectionCreateRequest("The name of my Collection", "The description of my Collection") // CollectionCreateRequest |
configuration := openapiclient.NewConfiguration()
configuration.AddDefaultHeader("Authorization","Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
apiClient := openapiclient.NewAPIClient(configuration)
resp, r, err := apiClient.CollectionsAPI.CreateCollection(context.Background()).CollectionCreateRequest(collectionCreateRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CollectionsAPI.CreateCollection``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `CreateCollection`: Collection
fmt.Fprintf(os.Stdout, "Response from `CollectionsAPI.CreateCollection`: %v\n", resp)
}API key- The value of the
Authorization
key should contain a global API key. The API key should be prefixed withBearer
, followed by the API key. For example:configuration.AddDefaultHeader("Authorization","Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.- Make sure to replace
sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
with your actual API key.
- Make sure to replace
- To learn more about what is a global API key and how to create one, see APIs.
- All URIs are relative to https://h2ogpte.genai.h2o.ai/. The global API key must be created on this platform to ensure successful requests.
- The value of the
-
In the "my-project" directory, run the "create_a_collection.go" file:
go run create_a_collection.go
Response from `CollectionsAPI.CreateCollection`: &{e6926802-9529-419f-9ddd-cbb262137a8a The name of my Collection The description of my Collection BAAI/bge-large-en-v1.5 0 0 2024-12-11 23:43:19.972726 +0000 UTC 0 false sergio.perez@h2o.ai 0 <nil>}
- Submit and view feedback for this page
- Send feedback about Enterprise h2oGPTe to cloud-feedback@h2o.ai