maas

package
v1.0.117 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ServiceName   = "ml_maas"
	APICert       = "cert"
	APIChat       = "chat"
	APIStreamChat = "stream_chat"

	ServiceTimeout = time.Minute

	ChatRoleOfUser      = "user"
	ChatRoleOfAssistant = "assistant"
	ChatRoleOfSystem    = "system"
)

Variables

This section is empty.

Functions

func AesGcmDecryptBase64String added in v1.0.113

func AesGcmDecryptBase64String(key, nonce []byte, ciphertext string) (string, error)

AesGcmDecryptBase64String decrypt message(base64.std.string) using AES-GCM

func AesGcmDecryptBytes added in v1.0.113

func AesGcmDecryptBytes(key, nonce, cipherBytes []byte) ([]byte, error)

AesGcmDecryptBytes Decrypt message using AES-GCM

func AesGcmEncryptBase64String added in v1.0.113

func AesGcmEncryptBase64String(key, nonce []byte, plaintext string) (string, error)

AesGcmEncryptBase64String Encrypt message from base64 string to string using AES-GCM

func AesGcmEncryptBytes added in v1.0.113

func AesGcmEncryptBytes(key, nonce, plain []byte) ([]byte, error)

AesGcmEncryptBytes encrypt message using AES-GCM

func GenerateKey added in v1.0.113

func GenerateKey(curve elliptic.Curve) (*ecdsa.PrivateKey, *ecdsa.PublicKey, error)

GenerateKey is the constructor for Private-Public key pair

func MarshalBinary added in v1.0.113

func MarshalBinary(pub *ecdsa.PublicKey) []byte

func ReadCertFromBytes added in v1.0.113

func ReadCertFromBytes(pemBytes []byte) (*x509.Certificate, error)

func ReadCertFromString added in v1.0.113

func ReadCertFromString(pemString string) (*x509.Certificate, error)

func ReadEcdsaPrivKeyFromBytes added in v1.0.113

func ReadEcdsaPrivKeyFromBytes(pemBytes []byte) (*ecdsa.PrivateKey, error)

func ReadEcdsaPrivKeyFromString added in v1.0.113

func ReadEcdsaPrivKeyFromString(key string) (*ecdsa.PrivateKey, error)

func UnmarshalBinary added in v1.0.113

func UnmarshalBinary(curve elliptic.Curve, data []byte) (*big.Int, *big.Int)

Types

type KeyAgreementClient added in v1.0.113

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

func NewP256KeyAgreementClient added in v1.0.113

func NewP256KeyAgreementClient(pemString string) (*KeyAgreementClient, error)

NewP256KeyAgreementClient Load cert and extract public key

func (*KeyAgreementClient) CheckChain added in v1.0.113

func (k *KeyAgreementClient) CheckChain(pemChainString string) error

CheckChain validate cert and cert chain

func (*KeyAgreementClient) GenerateECIESKeyPair added in v1.0.113

func (k *KeyAgreementClient) GenerateECIESKeyPair() ([]byte, []byte, string, error)

GenerateECIESKeyPair generate ECIES key pair and return the tuple (key, nonce, session token, error)

type KeyAgreementVendor added in v1.0.113

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

func NewP256KeyAgreementVendor added in v1.0.113

func NewP256KeyAgreementVendor(key string) (*KeyAgreementVendor, error)

NewP256KeyAgreementVendor Load private key

func (*KeyAgreementVendor) DecryptString added in v1.0.113

func (k *KeyAgreementVendor) DecryptString(sessionToken string, ciphertext string) ([]byte, []byte, string, error)

DecryptString decide ciphered text with ECIES DH protocol and return the tuple of (key, nonce, decrypted text)

func (*KeyAgreementVendor) ExtractECIESKeyPair added in v1.0.113

func (k *KeyAgreementVendor) ExtractECIESKeyPair(sessionToken string) ([]byte, []byte, error)

ExtractECIESKeyPair extract ECIES key pair from session token and return the tuple of (key, nonce)

type MaaS

type MaaS struct {
	*base.Client
}

MaaS ... use base client

func NewInstance

func NewInstance(host, region string) *MaaS

NewInstance ...

func (*MaaS) Chat

func (cli *MaaS) Chat(req *api.ChatReq) (*api.ChatResp, int, error)

POST method Chat ...

func (*MaaS) ChatWithCtx added in v1.0.108

func (cli *MaaS) ChatWithCtx(ctx context.Context, req *api.ChatReq) (*api.ChatResp, int, error)

POST method ChatWithCtx ...

func (*MaaS) SecretChat added in v1.0.113

func (cli *MaaS) SecretChat(req *api.ChatReq) (*api.ChatResp, int, error)

POST method SecretChat is like `Chat`, except its messages are encrypted to ensure that messages are not intercepted by receivers other than the model.

func (*MaaS) SecretChatWithCtx added in v1.0.113

func (cli *MaaS) SecretChatWithCtx(ctx context.Context, req *api.ChatReq) (*api.ChatResp, int, error)

POST method SecretChatWithCtx is like `ChatWithCtx`, except its messages are encrypted to ensure that messages are not intercepted by receivers other than the model.

func (*MaaS) SecretStreamChat added in v1.0.113

func (cli *MaaS) SecretStreamChat(req *api.ChatReq) (ch <-chan *api.ChatResp, err error)

POST method SecretStreamChat is like `StreamChat`, except its messages are encrypted to ensure that messages are not intercepted by receivers other than the model.

func (*MaaS) SecretStreamChatWithCtx added in v1.0.113

func (cli *MaaS) SecretStreamChatWithCtx(ctx context.Context, req *api.ChatReq) (ch <-chan *api.ChatResp, err error)

POST method SecretStreamChatWithCtx is like `StreamChatWithCtx`, except its messages are encrypted to ensure that messages are not intercepted by receivers other than the model.

func (*MaaS) StreamChat

func (cli *MaaS) StreamChat(req *api.ChatReq) (ch <-chan *api.ChatResp, err error)

POST method StreamChat make stream chat request

  1. if any error returned, a channel=`nil` is returned;
  2. if no error returned, the channel are closed after all responses processed.

func (*MaaS) StreamChatWithCtx added in v1.0.108

func (cli *MaaS) StreamChatWithCtx(ctx context.Context, req *api.ChatReq) (ch <-chan *api.ChatResp, err error)

POST method StreamChat make stream chat request

  1. if any error returned, a channel=`nil` is returned;
  2. if no error returned, the channel are closed after all responses processed.

Directories

Path Synopsis
models
api

Jump to

Keyboard shortcuts

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