rpc

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResponseTimeout = time.Minute * 10 // 10 minutes timeout for requests
)

Functions

func ChatCompletion

func ChatCompletion(rpcMgr *GuestRPCManager, model string, msgs []payload.ChatMessageV2, tsId string) ([]payload.ChatMessageV2, error)

func Embeddings

func Embeddings(rpcMgr *GuestRPCManager, model, input string) ([]float64, error)

func RPCManagerSendRequest

func RPCManagerSendRequest[T any](rpcMgr *GuestRPCManager, method string, params interface{}) (*T, error)

func TextToImage

func TextToImage(rpcMgr *GuestRPCManager, model, prompt, format string) (*transform.ImageGenerationResponse, error)

func TextToSpeech

func TextToSpeech(rpcMgr *GuestRPCManager, model, voice, input, format string) (*transform.TextToSpeechResponse, error)

Types

type GuestRPCManager

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

func NewGuestRPCManager

func NewGuestRPCManager(reqHandler JsonRPCRequestHandler, respHandler JsonRPCResponseHandler) *GuestRPCManager

func (*GuestRPCManager) ClearRequestCallback

func (g *GuestRPCManager) ClearRequestCallback(id json.Number)

func (*GuestRPCManager) RegisterIncomingHandler

func (g *GuestRPCManager) RegisterIncomingHandler(method string, handler RequestHandler) error

func (*GuestRPCManager) Run

func (g *GuestRPCManager) Run()

func (*GuestRPCManager) SendJsonRequest

func (g *GuestRPCManager) SendJsonRequest(req *JsonRPCRequest) (*JsonRPCResponse, error)

low level function to send a json request

func (*GuestRPCManager) SendRequest

func (g *GuestRPCManager) SendRequest(method string, params interface{}) (interface{}, error)

high level function to send a request

func (*GuestRPCManager) SetInput

func (g *GuestRPCManager) SetInput(i io.Reader)

func (*GuestRPCManager) SetOutput

func (g *GuestRPCManager) SetOutput(o io.Writer)

func (*GuestRPCManager) SetRequestCallback

func (g *GuestRPCManager) SetRequestCallback(id json.Number, callback ResquestCallback, autoClear bool)

type JsonRPCError

type JsonRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type JsonRPCNotification

type JsonRPCNotification struct {
	Version string      `json:"jsonrpc"`
	Method  *string     `json:"method"`
	Params  interface{} `json:"params"`
}

func (*JsonRPCNotification) Marshal

func (r *JsonRPCNotification) Marshal() ([]byte, error)

func (*JsonRPCNotification) Unmarshal

func (r *JsonRPCNotification) Unmarshal(data []byte) error

type JsonRPCRequest

type JsonRPCRequest struct {
	Version string       `json:"jsonrpc"`
	Method  *string      `json:"method"`
	Params  interface{}  `json:"params,omitempty"`
	ID      *json.Number `json:"id"`
}

func NewJsonRPCRequest

func NewJsonRPCRequest(method string, params interface{}) *JsonRPCRequest

create request

func (*JsonRPCRequest) CreateErrorResponse

func (r *JsonRPCRequest) CreateErrorResponse(code int, message string, data interface{}) *JsonRPCResponse

func (*JsonRPCRequest) CreateSuccessResponse

func (r *JsonRPCRequest) CreateSuccessResponse(result interface{}) *JsonRPCResponse

func (*JsonRPCRequest) Marshal

func (r *JsonRPCRequest) Marshal() ([]byte, error)

func (*JsonRPCRequest) Send

func (r *JsonRPCRequest) Send(out io.Writer) error

func (*JsonRPCRequest) Unmarshal

func (r *JsonRPCRequest) Unmarshal(data []byte) error

type JsonRPCRequestHandler

type JsonRPCRequestHandler func(req *JsonRPCRequest) (*JsonRPCResponse, error)

type JsonRPCResponse

type JsonRPCResponse struct {
	Version string        `json:"jsonrpc"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JsonRPCError `json:"error,omitempty"`
	ID      *json.Number  `json:"id"`
}

func NewJsonRPCErrorResponse

func NewJsonRPCErrorResponse(id json.Number, code int, message string, data interface{}) *JsonRPCResponse

func NewJsonRPCResponse

func NewJsonRPCResponse(id json.Number, result interface{}) *JsonRPCResponse

func (*JsonRPCResponse) Marshal

func (r *JsonRPCResponse) Marshal() ([]byte, error)

func (*JsonRPCResponse) Send

func (r *JsonRPCResponse) Send(out io.Writer) error

func (*JsonRPCResponse) Unmarshal

func (r *JsonRPCResponse) Unmarshal(data []byte) error

type JsonRPCResponseHandler

type JsonRPCResponseHandler func(resp *JsonRPCResponse) error

type RequestHandler

type RequestHandler func(args interface{}) (interface{}, error)

type ResquestCallback

type ResquestCallback func(resp *JsonRPCResponse) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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