aliyun-pai-ab-go-sdk

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2024 License: Apache-2.0

README

aliyun-pai-ab-go-sdk

Go sdk for PAI-ABTest server. Aliyun product docoment link.

Installation

go get github.com/aliyun/aliyun-pai-ab-go-sdk

Usage

   package main

import (
	"fmt"
	"log"
	"os"

	"github.com/aliyun/aliyun-pai-ab-go-sdk/api"
	"github.com/aliyun/aliyun-pai-ab-go-sdk/experiments"
	"github.com/aliyun/aliyun-pai-ab-go-sdk/model"
)

func main() {

	// init config
	region := "cn-beijing"
	accessId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
	accessKey := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
	config := api.NewConfiguration(region, accessId, accessKey)

	// init client
	client, err := experiments.NewExperimentClient(config, experiments.WithLogger(experiments.LoggerFunc(log.Printf)))
	if err != nil {
		log.Fatal(err)
	}

	// set up experiment context
	experimentContext := model.ExperimentContext{
		RequestId: "pvid",
		Uid:       "157",
		FilterParams: map[string]interface{}{
			"sex": "male",
			"age": 35,
		},
	}

	// match experiment
	// DefaultProject is project name
	experimentResult := client.MatchExperiment("DefaultProject", &experimentContext)

	// print experiment info
	fmt.Println(experimentResult.Info())
	// print exp id
	fmt.Println(experimentResult.GetExpId())

	// get experiment param value
	param := experimentResult.GetExperimentParams().GetString("ab_param_name", "not_exist")
	if param != "not_exist" {
		// experiment logic

	} else {
		// default logic

	}
}

If you call the ABTest service in Alibaba Cloud VPC, you can specify using the VPC to connect to the service.

	// init config
	region := "cn-beijing"
	accessId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
	accessKey := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
	config := api.NewConfiguration(region, accessId, accessKey)
	config.UseVpc(true)

Version Release Notes

1.0.0 (2024-08-01)

  • Initial release

Directories

Path Synopsis
* PAI-AB Server API * * PAI-AB Server API * * API version: 0.0.1 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
* PAI-AB Server API * * PAI-AB Server API * * API version: 0.0.1 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL