eas

package
v0.0.0-...-1cbd840 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Default endpoint is the gateway mode
	EndpointTypeDefault = "DEFAULT"
	// Vipserver endpoint is only used for services which registered
	// vipsever domains in alibaba internal clusters
	EndpointTypeVipserver = "VIPSERVER"
	// Direct endpoint is used for direct accessing to the services' instances
	// both inside a eas service and in user's client ecs
	EndpointTypeDirect = "DIRECT"
)
View Source
const (
	CompressTypeGzip = "Gzip"
	CompressTypeZlib = "Zlib"
)
View Source
const (
	ErrorCodeServiceDiscovery = 510
	ErrorCodeCreateRequest    = 511
	ErrorCodePerformRequest   = 512
	ErrorCodeReadResponse     = 513
)
View Source
const (
	HeaderRequestId     = "X-Eas-Queueservice-Request-Id"
	HeaderAccessRear    = "X-EAS-QueueService-Access-Rear"
	HeaderAuthorization = "Authorization"

	DefaultBasePath = "/api/predict"

	DefaultGroupName = "eas"
)

TfType_DT_INVALID and listed types use ALL_CAPS names here to consist with other language's sdk.

Variables

This section is empty.

Functions

func DisableHttpRedirect

func DisableHttpRedirect() func(client *http.Client)

Types

type Endpoint

type Endpoint interface {
	Sync()
	TryNext(addr string) string
}

type HttpOption

type HttpOption func(client *http.Client)

type PredictClient

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

PredictClient for accessing prediction service by creating a fixed size connection pool to perform the request through established persistent connections.

func NewPredictClient

func NewPredictClient(endpointName string, serviceName string, options ...HttpOption) *PredictClient

NewPredictClient returns an instance of PredictClient

func (*PredictClient) AddHeader

func (p *PredictClient) AddHeader(headerName, headerValue string)

func (*PredictClient) BytesPredict

func (p *PredictClient) BytesPredict(requestData []byte) ([]byte, error)

BytesPredict send the raw request data in byte array through http connections, retry the request automatically when an error occurs

func (*PredictClient) Init

func (p *PredictClient) Init() error

Init initializes the predict client to create and enable endpoint discovery

func (*PredictClient) Predict

func (p *PredictClient) Predict(request Request) (Response, error)

Predict for request

func (*PredictClient) RawRequest

func (p *PredictClient) RawRequest(req RawRequest) (*RawResponse, error)

RawRequest sends the raw request in raw http Request, retry the request automatically when an error occurs

func (*PredictClient) SetCompressType

func (p *PredictClient) SetCompressType(compressType string)

SetCompressType sets compressor type for client

func (*PredictClient) SetEndpoint

func (p *PredictClient) SetEndpoint(endpointName string)

SetEndpoint sets service's endpoint for client

func (*PredictClient) SetEndpointType

func (p *PredictClient) SetEndpointType(endpointType string)

SetEndpointType sets endpoint type for client

func (*PredictClient) SetHost

func (p *PredictClient) SetHost(host string)

func (*PredictClient) SetHttpTransport

func (p *PredictClient) SetHttpTransport(transport *http.Transport)

SetHttpTransport sets http transport argument for go http client

func (*PredictClient) SetRetryCount

func (p *PredictClient) SetRetryCount(cnt int)

SetRetryCount sets max retry count for client

func (*PredictClient) SetServiceName

func (p *PredictClient) SetServiceName(serviceName string)

SetServiceName sets target service name for client

func (*PredictClient) SetTimeout

func (p *PredictClient) SetTimeout(timeout int)

SetTimeout set the request timeout for client, 5000ms by default

func (*PredictClient) SetToken

func (p *PredictClient) SetToken(token string)

SetToken function sets service's access token for client

func (*PredictClient) Shutdown

func (p *PredictClient) Shutdown()

Shutdown after called this client instance should not be used again

func (*PredictClient) StringPredict

func (p *PredictClient) StringPredict(str string) (string, error)

StringPredict function send input data and return predicted result

func (*PredictClient) TFPredict

func (p *PredictClient) TFPredict(request TFRequest) (*TFResponse, error)

TFPredict function send input data and return TensorFlow predicted result

func (*PredictClient) TorchPredict

func (p *PredictClient) TorchPredict(request TorchRequest) (*TorchResponse, error)

TorchPredict function send input data and return PyTorch predicted result

type PredictError

type PredictError struct {
	Code       int
	Message    string
	RequestURL string
}

PredictError is a custom err type

func NewPredictError

func NewPredictError(code int, url string, msg string) *PredictError

NewPredictError constructs an error

func (*PredictError) Error

func (err *PredictError) Error() string

Error for error interface

type QueueClient

type QueueClient struct {
	WebsocketWatch bool

	// codecs for data frame and attributes.
	DCodec types.DataFrameCodec
	ACodec types.AttributesCodec
	// contains filtered or unexported fields
}

QueueClient is client of queue server, which also implements queue service interface

func NewQueueClient

func NewQueueClient(endpoint, queueName, token string, opts ...QueueOption) (*QueueClient, error)

func (*QueueClient) AddExtraHeaders

func (q *QueueClient) AddExtraHeaders(header http.Header)

func (*QueueClient) Attributes

func (q *QueueClient) Attributes() (types.Attributes, error)

func (*QueueClient) Commit

func (q *QueueClient) Commit(ctx context.Context, indexes ...uint64) error

Commit commits the indexes to the queue, as the result, the data in queue will not be delivered again.

func (*QueueClient) Del

func (q *QueueClient) Del(ctx context.Context, indexes ...uint64) error

Del deletes the indexes from the queue, the content of the indexes will also be deleted.

func (*QueueClient) End

func (q *QueueClient) End(ctx context.Context, force bool) error

func (*QueueClient) Get

func (q *QueueClient) Get(ctx context.Context, index uint64, length int, timeout time.Duration, autoDelete bool, tags types.Tags) (dfs []types.DataFrame, err error)

Get gets data from queue, it returns the data frames and error. Parameters:

  • index: the start point to get data, if index is 0, it will search from the queue head.
  • length: the number of data frames to get.
  • timeout: the timeout duration to wait for data, if timeout is 0, it will return immediately.
  • autoDelete: if autoDelete is true, the data will be deleted from queue after it is read.
  • tags: the tags to filter data.

func (*QueueClient) GetByIndex

func (q *QueueClient) GetByIndex(ctx context.Context, index uint64) (dfs []types.DataFrame, err error)

GetByIndex gets data from queue by index, make convenience wrapper for Get.

func (*QueueClient) GetByRequestId

func (q *QueueClient) GetByRequestId(ctx context.Context, requestId string) (dfs []types.DataFrame, err error)

GetByRequestId gets data from queue by request id, make convenience wrapper for Get.

func (*QueueClient) Negative

func (q *QueueClient) Negative(ctx context.Context, code types.Code, reason string, indexes ...uint64) error

func (*QueueClient) Put

func (q *QueueClient) Put(ctx context.Context, data []byte, tags types.Tags) (uint64, string, error)

Put puts data into queue. It returns the index of the data in queue, and generated request id.

func (*QueueClient) PutWithPath

func (q *QueueClient) PutWithPath(ctx context.Context, data []byte, path string, tags types.Tags) (uint64, string, error)

func (*QueueClient) PutWithPathAndPriority

func (q *QueueClient) PutWithPathAndPriority(ctx context.Context, data []byte, customPath string, tags types.Tags, prio types.Priority) (index uint64, requestId string, err error)

PutWithPriority puts data into queue with path and priority. It returns the index of the data in queue, and generated request id. The prioritized data will be received by Watcher before normal data.

func (*QueueClient) PutWithPriority

func (q *QueueClient) PutWithPriority(ctx context.Context, data []byte, tags types.Tags, prio types.Priority) (index uint64, requestId string, err error)

func (*QueueClient) Truncate

func (q *QueueClient) Truncate(ctx context.Context, index uint64) error

Truncate truncates the queue to the given index, the specified index is not included.

func (*QueueClient) Watch

func (q *QueueClient) Watch(ctx context.Context, index, window uint64, indexOnly bool, autocommit bool) (types.Watcher, error)

func (*QueueClient) WatchByTag

func (q *QueueClient) WatchByTag(ctx context.Context, index, window uint64, indexOnly bool, autocommit bool, tags types.Tags) (types.Watcher, error)

WatchByTag returns a Watcher which can be used to receive data from the queue in streaming fashion. Parameters:

  • index: the index to start watching from.
  • window: the window size to watch.
  • indexOnly: if true, only the index will be returned, otherwise the whole data frame will be returned.
  • autocommit: if true, the index will be automatically committed after the data frame is received.
  • tags: the tags to watch.

type QueueOption

type QueueOption func(*queueOptions)

func WithBasePath

func WithBasePath(basePath string) QueueOption

func WithExtraHeaders

func WithExtraHeaders(extraHeaders map[string]string) QueueOption

func WithGroupId

func WithGroupId(gid string) QueueOption

func WithUserId

func WithUserId(uid string) QueueOption

type QueueUser

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

func NewQueueUser

func NewQueueUser(uid, gid, token string) QueueUser

func (QueueUser) Gid

func (c QueueUser) Gid() string

func (QueueUser) Token

func (c QueueUser) Token() string

func (QueueUser) Uid

func (c QueueUser) Uid() string

type RawRequest

type RawRequest struct {
	http.Request
}

func (RawRequest) ToString

func (r RawRequest) ToString() (string, error)

type RawResponse

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

func (RawResponse) ToBytes

func (r RawResponse) ToBytes() []byte

type Request

type Request interface {
	ToString() (string, error)
}

type Response

type Response interface {
	// contains filtered or unexported methods
}

type TFRequest

type TFRequest struct {
	RequestData tf_predict_protos.PredictRequest
}

TFRequest class for tensorflow data and requests

func (*TFRequest) AddFeedBool

func (tr *TFRequest) AddFeedBool(inputName string, shape []int64, content []bool)

AddFeedBool function adds boolean values input data for TFRequest

func (*TFRequest) AddFeedFloat32

func (tr *TFRequest) AddFeedFloat32(inputName string, shape []int64, content []float32)

AddFeedFloat32 function adds float values input data for TFRequest

func (*TFRequest) AddFeedFloat64

func (tr *TFRequest) AddFeedFloat64(inputName string, shape []int64, content []float64)

AddFeedFloat64 function adds double values input data for TFRequest

func (*TFRequest) AddFeedInt32

func (tr *TFRequest) AddFeedInt32(inputName string, shape []int64, content []int32)

AddFeedInt32 function adds int values input data for TFRequest

func (*TFRequest) AddFeedInt64

func (tr *TFRequest) AddFeedInt64(inputName string, shape []int64, content []int64)

AddFeedInt64 function adds int64 values input data for TFRequest

func (*TFRequest) AddFeedString

func (tr *TFRequest) AddFeedString(inputName string, shape []int64, content [][]byte)

AddFeedString function adds string values input data for TFRequest

func (*TFRequest) AddFetch

func (tr *TFRequest) AddFetch(outName string)

AddFetch adds output filter (outname) for TensorFlow request

func (*TFRequest) SetSignatureName

func (tr *TFRequest) SetSignatureName(sigName string)

SetSignatureName set signature name for TensorFlow request

func (TFRequest) ToString

func (tr TFRequest) ToString() (string, error)

ToString for interface

type TFResponse

type TFResponse struct {
	Response tf_predict_protos.PredictResponse
}

TFResponse class for Pytf predicted results

func (*TFResponse) GetBoolVal

func (tresp *TFResponse) GetBoolVal(outputName string) []bool

GetBoolVal returns []bool slice as output data

func (*TFResponse) GetDoubleVal

func (tresp *TFResponse) GetDoubleVal(outputName string) []float64

GetDoubleVal returns []float64 slice as output data

func (*TFResponse) GetFloatVal

func (tresp *TFResponse) GetFloatVal(outputName string) []float32

GetFloatVal returns []float32 slice as output data

func (*TFResponse) GetInt64Val

func (tresp *TFResponse) GetInt64Val(outputName string) []int64

GetInt64Val returns []int64 slice as output data

func (*TFResponse) GetIntVal

func (tresp *TFResponse) GetIntVal(outputName string) []int32

GetIntVal returns []int32 slice as output data

func (*TFResponse) GetStringVal

func (tresp *TFResponse) GetStringVal(outputName string) [][]byte

GetStringVal returns []string slice as output data

func (*TFResponse) GetTensorShape

func (tresp *TFResponse) GetTensorShape(outputName string) []int64

GetTensorShape returns []int64 slice as shape of tensor outindexed

type TorchRequest

type TorchRequest struct {
	RequestData torch_predict_protos.PredictRequest
}

TorchRequest class for PyTorch data and requests

func (*TorchRequest) AddFeedFloat32

func (tr *TorchRequest) AddFeedFloat32(index int, shape []int64, content []float32)

AddFeedFloat32 function adds float values input data for torchrequest

func (*TorchRequest) AddFeedFloat64

func (tr *TorchRequest) AddFeedFloat64(index int, shape []int64, content []float64)

AddFeedFloat64 function adds double values input data for torchrequest

func (*TorchRequest) AddFeedInt32

func (tr *TorchRequest) AddFeedInt32(index int, shape []int64, content []int32)

AddFeedInt32 function adds int values input data for torchrequest

func (*TorchRequest) AddFeedInt64

func (tr *TorchRequest) AddFeedInt64(index int, shape []int64, content []int64)

AddFeedInt64 function adds int64 values input data for torchrequest

func (*TorchRequest) AddFetch

func (tr *TorchRequest) AddFetch(outIndex int32)

AddFetch add OutputFilter (outIndex) for response

func (TorchRequest) ToString

func (tr TorchRequest) ToString() (string, error)

ToString for interface

type TorchResponse

type TorchResponse struct {
	Response torch_predict_protos.PredictResponse
}

TorchResponse class for PyTorch predicted results

func (*TorchResponse) GetDoubleVal

func (resp *TorchResponse) GetDoubleVal(outIndex int) []float64

GetDoubleVal returns []float64 slice as output data

func (*TorchResponse) GetFloatVal

func (resp *TorchResponse) GetFloatVal(outIndex int) []float32

GetFloatVal returns []float32 slice as output data

func (*TorchResponse) GetInt64Val

func (resp *TorchResponse) GetInt64Val(outIndex int) []int64

GetInt64Val returns []int64 slice as output data

func (*TorchResponse) GetIntVal

func (resp *TorchResponse) GetIntVal(outIndex int) []int32

GetIntVal returns []int32 slice as output data

func (*TorchResponse) GetTensorShape

func (resp *TorchResponse) GetTensorShape(outIndex int) []int64

GetTensorShape returns []int64 slice as shape of tensor outindexed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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