mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
fix: use bytes in gRPC proto instead of strings (#813)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
0af0df7423
commit
b96e30e66c
8 changed files with 20 additions and 16 deletions
|
@ -42,7 +42,7 @@ func (c *Client) HealthCheck(ctx context.Context) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if res.Message == "OK" {
|
||||
if string(res.Message) == "OK" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -80,7 +80,7 @@ func (c *Client) LoadModel(ctx context.Context, in *pb.ModelOptions, opts ...grp
|
|||
return client.LoadModel(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (c *Client) PredictStream(ctx context.Context, in *pb.PredictOptions, f func(s string), opts ...grpc.CallOption) error {
|
||||
func (c *Client) PredictStream(ctx context.Context, in *pb.PredictOptions, f func(s []byte), opts ...grpc.CallOption) error {
|
||||
conn, err := grpc.Dial(c.address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -14,3 +14,7 @@ type LLM interface {
|
|||
AudioTranscription(*pb.TranscriptRequest) (api.Result, error)
|
||||
TTS(*pb.TTSRequest) error
|
||||
}
|
||||
|
||||
func newReply(s string) *pb.Reply {
|
||||
return &pb.Reply{Message: []byte(s)}
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ type Reply struct {
|
|||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
Message []byte `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Reply) Reset() {
|
||||
|
@ -451,11 +451,11 @@ func (*Reply) Descriptor() ([]byte, []int) {
|
|||
return file_pkg_grpc_proto_backend_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *Reply) GetMessage() string {
|
||||
func (x *Reply) GetMessage() []byte {
|
||||
if x != nil {
|
||||
return x.Message
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
type ModelOptions struct {
|
||||
|
@ -1174,7 +1174,7 @@ var file_pkg_grpc_proto_backend_proto_rawDesc = []byte{
|
|||
0x69, 0x76, 0x65, 0x50, 0x72, 0x6f, 0x6d, 0x70, 0x74, 0x18, 0x28, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x0e, 0x4e, 0x65, 0x67, 0x61, 0x74, 0x69, 0x76, 0x65, 0x50, 0x72, 0x6f, 0x6d, 0x70, 0x74, 0x22,
|
||||
0x21, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73,
|
||||
0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
|
||||
0x67, 0x65, 0x22, 0xca, 0x03, 0x0a, 0x0c, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x4f, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x05, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x6f, 0x6e,
|
||||
|
|
|
@ -65,7 +65,7 @@ message PredictOptions {
|
|||
|
||||
// The response message containing the result
|
||||
message Reply {
|
||||
string message = 1;
|
||||
bytes message = 1;
|
||||
}
|
||||
|
||||
message ModelOptions {
|
||||
|
|
|
@ -26,7 +26,7 @@ type server struct {
|
|||
}
|
||||
|
||||
func (s *server) Health(ctx context.Context, in *pb.HealthMessage) (*pb.Reply, error) {
|
||||
return &pb.Reply{Message: "OK"}, nil
|
||||
return newReply("OK"), nil
|
||||
}
|
||||
|
||||
func (s *server) Embedding(ctx context.Context, in *pb.PredictOptions) (*pb.EmbeddingResult, error) {
|
||||
|
@ -48,7 +48,7 @@ func (s *server) LoadModel(ctx context.Context, in *pb.ModelOptions) (*pb.Result
|
|||
|
||||
func (s *server) Predict(ctx context.Context, in *pb.PredictOptions) (*pb.Reply, error) {
|
||||
result, err := s.llm.Predict(in)
|
||||
return &pb.Reply{Message: result}, err
|
||||
return newReply(result), err
|
||||
}
|
||||
|
||||
func (s *server) GenerateImage(ctx context.Context, in *pb.GenerateImageRequest) (*pb.Result, error) {
|
||||
|
@ -99,7 +99,7 @@ func (s *server) PredictStream(in *pb.PredictOptions, stream pb.Backend_PredictS
|
|||
done := make(chan bool)
|
||||
go func() {
|
||||
for result := range resultChan {
|
||||
stream.Send(&pb.Reply{Message: result})
|
||||
stream.Send(newReply(result))
|
||||
}
|
||||
done <- true
|
||||
}()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue