aiservice

package module
v0.0.0-...-a41f703 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

aliyun-pai-aiservice-go-sdk

安装

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

使用说明

AI 图片检测代码示例
import sdk "github.com/aliyun/aliyun-pai-aiservice-go-sdk"

host  := "http://ai-service.ce8cc13b6421545749e7b4605f3d02607.cn-hangzhou.alicontainer.com"
appId := os.Getenv("APPID")
token := os.Getenv("TOKEN")

client := sdk.NewClient(host, appId, token)

// 检查图片列表
images := []string{"https://pai-aigc-photog-bj.oss-cn-beijing.aliyuncs.com/photog/user_images/foto/train/1.jpg", "https://pai-aigc-photog-bj.oss-cn-beijing.aliyuncs.com/photog/user_images/foto/train/0.jpg"}
response, err := client.AIGCApi.AigcImageCheck(images, "", nil)

if err != nil {
	log.Fatal(err)
    return
}

if response.Code != "OK" {
    log.Fatal("response error:%v", response)
    return
}

// 遍历图片检测结果
for _, result := range response.Data.CheckResults {
    fmt.Printf("code=%d\tfrontal=%v\turl=%s\n", result.Code, result.Frontal, result.Url)
}

AI图片,训练,写真完整示例参考
import sdk "github.com/aliyun/aliyun-pai-aiservice-go-sdk"

host  := "http://ai-service.ce8cc13b6421545749e7b4605f3d02607.cn-hangzhou.alicontainer.com"
appId := os.Getenv("APPID")
token := os.Getenv("TOKEN")

client := sdk.NewClient(host, appId, token)
images := []string{"https://pai-aigc-photog-bj.oss-cn-beijing.aliyuncs.com/photog/user_images/foto/train/1.jpg", "https://pai-aigc-photog-bj.oss-cn-beijing.aliyuncs.com/photog/user_images/foto/train/0.jpg"}
response, err := client.AIGCApi.AigcImagesTrain(images, "", nil)
if err != nil {
    log.Fatal(err)
}

// 任务ID
jobId := response.Data.JobId
modelId := response.Data.ModelId

for {
    jobResponse, err := client.JobApi.GetAsyncJobWithId(jobId)
    if err != nil {
        log.Fatal("get job fail", err)
    }

    if jobResponse.Data.Job.State == sdk.JOB_STATE_WAIT {
        fmt.Println("job running")
    } else if jobResponse.Data.Job.State == sdk.JOB_STATE_SUCCESS { // job success
        fmt.Println(jobResponse)
        fmt.Println("job success")
        break
    } else if jobResponse.Data.Job.State == sdk.JOB_STATE_FAILED {
        log.Fatal("job fail", err)
        return
    }

    time.Sleep(30 * time.Second)
}

createResponse, err := client.AIGCApi.AigcImagesCreate(modelId, "https://pai-aigc-photog-bj.oss-cn-beijing.aliyuncs.com/photog/user_weights/foto10/validation/global_step_Blue_1_100_0.jpg", "", nil)
if err != nil {
    log.Fatal(err)
}

// 生成的图片 base64 编码
fmt.Println(createResponse.Data.Image)

Documentation

Index

Constants

View Source
const (
	VIDEO_PATH       = "/api/v1/videos"
	BATCH_VIDEO_PATH = "/api/v1/batch_videos"
)
View Source
const (
	JOB_STATE_INIT    = 0
	JOB_STATE_WAIT    = 1
	JOB_STATE_SUCCESS = 2
	JOB_STATE_FAILED  = 3
)

Variables

View Source
var (
	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	AiCreationApi *AiServiceAiCreationApiService

	ImageApi *AiServiceImageApiService

	TextApi *AiServiceTextApiService

	ImageTextApi *AiServiceImageTextApiService

	VideoApi *AiServiceVideoApiService

	JobApi *AiServiceJobApiService

	AIGCApi *AigcImagesApiService

	LLMApi *AiServiceLlmApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the AI model Service Restful API API v1.0.0 In most cases there should be only one, shared, APIClient.

func NewClient

func NewClient(host, appId, token string) *APIClient

NewClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type AiServiceAiCreationApiService

type AiServiceAiCreationApiService service

func (*AiServiceAiCreationApiService) AICreation

func (a *AiServiceAiCreationApiService) AICreation(content, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceAiCreationApiService) AiModelCreation

AiModelCreation AiServiceAiCreationApiService AI创作接口 - @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). - @param body AI创作body return Response *

type AiServiceImageApiService

type AiServiceImageApiService service

func (*AiServiceImageApiService) AiModelImage

AiServiceImageApiService 图片检测接口

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body 图片检测body

@return Response

func (*AiServiceImageApiService) ClassifyImage

func (a *AiServiceImageApiService) ClassifyImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) DetectClassifyImage

func (a *AiServiceImageApiService) DetectClassifyImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) FaceAttrImage

func (a *AiServiceImageApiService) FaceAttrImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) FaceBeautyImage

func (a *AiServiceImageApiService) FaceBeautyImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) FaceDetectImage

func (a *AiServiceImageApiService) FaceDetectImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) FaceRecognitionImage

func (a *AiServiceImageApiService) FaceRecognitionImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) ImageQA

func (a *AiServiceImageApiService) ImageQA(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) MultiLabelImage

func (a *AiServiceImageApiService) MultiLabelImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) MultiLabelImageV2

func (a *AiServiceImageApiService) MultiLabelImageV2(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) OCRImage

func (a *AiServiceImageApiService) OCRImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) ProductDetectImage

func (a *AiServiceImageApiService) ProductDetectImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceImageApiService) ScanImage

func (a *AiServiceImageApiService) ScanImage(image, modelName string, config map[string]interface{}) (*model.Response, error)

type AiServiceImageTextApiService

type AiServiceImageTextApiService service

func (*AiServiceImageTextApiService) AiModelImageWithText

AiServiceImageTextApiService 图片检测接口

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body 图文检测body

@return Response

func (AiServiceImageTextApiService) ImageTextTag

func (a AiServiceImageTextApiService) ImageTextTag(images []string, text string, modelName string, config map[string]interface{}) (*model.Response, error)

type AiServiceJobApiService

type AiServiceJobApiService service

func (*AiServiceJobApiService) GetAsyncJob

AiServiceJobApiService 根据 jobid 查询异步任务

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param jobId job id

@return Response

func (*AiServiceJobApiService) GetAsyncJobWithId

func (a *AiServiceJobApiService) GetAsyncJobWithId(jobId int32) (*model.AsyncJobResponse, error)

func (*AiServiceJobApiService) GetBatchJob

func (a *AiServiceJobApiService) GetBatchJob(batchId int32) (*model.Response, *http.Response, error)

AiServiceJobApiService 根据 batch id 查询异步任务

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param batchId batch id

@return Response

func (*AiServiceJobApiService) GetBatchJobWithId

func (a *AiServiceJobApiService) GetBatchJobWithId(batchId int32) (*model.Response, error)

type AiServiceLlmApiService

type AiServiceLlmApiService service

func (*AiServiceLlmApiService) LlmEvalJudger

func (a *AiServiceLlmApiService) LlmEvalJudger(request ChatCompletionRequest, modelName string) (*model.LLMEvalJudgerResponse, error)

func (*AiServiceLlmApiService) LlmEvalJudgerPost

AiServiceLlmApiService 裁判员模型服务

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body llm eval judger body

@return Response

type AiServiceTextApiService

type AiServiceTextApiService service

func (*AiServiceTextApiService) AiModelText

AiServiceTextApiService 文本检测接口

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body 文本检测body

@return Response

func (*AiServiceTextApiService) AntiSpamText

func (a *AiServiceTextApiService) AntiSpamText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) EcomerceReviewSentimentAnalysisText

func (a *AiServiceTextApiService) EcomerceReviewSentimentAnalysisText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) FineGrainedLabelText

func (a *AiServiceTextApiService) FineGrainedLabelText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) KeyWordText

func (a *AiServiceTextApiService) KeyWordText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) NERText

func (a *AiServiceTextApiService) NERText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) SentimentAnalysisText

func (a *AiServiceTextApiService) SentimentAnalysisText(text, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceTextApiService) VectorizationText

func (a *AiServiceTextApiService) VectorizationText(text, modelName string, config map[string]interface{}) (*model.Response, error)

type AiServiceVideoApiService

type AiServiceVideoApiService service

func (*AiServiceVideoApiService) AiModelBatchVideo

func (*AiServiceVideoApiService) AiModelVideo

AiServiceVideoApiService 视频检测接口

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body 视频检测body

@return Response

func (*AiServiceVideoApiService) BatchClassifyLabelVideo

func (a *AiServiceVideoApiService) BatchClassifyLabelVideo(videos []model.VideoMeta, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceVideoApiService) BatchVideoQA

func (a *AiServiceVideoApiService) BatchVideoQA(videos []model.VideoMeta, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceVideoApiService) ClassifyLabelVideo

func (a *AiServiceVideoApiService) ClassifyLabelVideo(videoUrl, videoTitle, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceVideoApiService) MultiModalClassify

func (a *AiServiceVideoApiService) MultiModalClassify(videoUrl string, images []string, text string, modelName string, config map[string]interface{}) (*model.Response, error)

func (*AiServiceVideoApiService) VideoQA

func (a *AiServiceVideoApiService) VideoQA(videoUrl, videoTitle, modelName string, config map[string]interface{}) (*model.Response, error)

type AigcImagesApiService

type AigcImagesApiService service

func (*AigcImagesApiService) AigcImageCheck

func (a *AigcImagesApiService) AigcImageCheck(images []string, modelName string, config map[string]interface{}) (*model.AIGCImageCheckResponse, error)

func (*AigcImagesApiService) AigcImagesCheckPost

AigcImagesApiService aigc图像检测

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body aigc检测body

@return Response

func (*AigcImagesApiService) AigcImagesCreate

func (a *AigcImagesApiService) AigcImagesCreate(modelId, templateImage, modelName string, config map[string]interface{}) (*model.AIGCImageCreateResponse, error)

func (*AigcImagesApiService) AigcImagesCreateByMultiModelIds

func (a *AigcImagesApiService) AigcImagesCreateByMultiModelIds(modelIds []string, templateImage, modelName string, config map[string]interface{}) (*model.AIGCImageCreateResponse, error)

func (*AigcImagesApiService) AigcImagesCreatePost

AigcImagesApiService aigc预测

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body aigc预测body

@return AIGCImageCreateResponse

func (*AigcImagesApiService) AigcImagesTrain

func (a *AigcImagesApiService) AigcImagesTrain(images []string, modelName string, config map[string]interface{}) (*model.AIGCImageTrainResponse, error)

func (*AigcImagesApiService) AigcImagesTrainPost

AigcImagesApiService aigc图像

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body aigc图像body

@return AIGCImageTrainResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type ChatCompletionMessage

type ChatCompletionMessage struct {
	Role    string
	Content string
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model    string
	Messages []ChatCompletionMessage
}

type Configuration

type Configuration struct {
	AppID         string            `json:"app_id,omitempty"`
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client

	HostAddress string `json:"-"`
	// contains filtered or unexported fields
}

func NewConfiguration

func NewConfiguration(host, appid, token string) *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

type GenericSwaggerError

type GenericSwaggerError struct {
	// contains filtered or unexported fields
}

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

Directories

Path Synopsis
* AI model Service Restful API * * This is an ai model service * * API version: 1.0.0 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
* AI model Service Restful API * * This is an ai model service * * API version: 1.0.0 * 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