local

package
v0.0.0-...-95f5f5d Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatService_Completion_FullMethodName = "/local.ChatService/Completion"
	ChatService_Chat_FullMethodName       = "/local.ChatService/Chat"
	ChatService_Embedings_FullMethodName  = "/local.ChatService/Embedings"
)

Variables

View Source
var (
	ErrorCode_name = map[int32]string{
		0: "Zero",
		1: "OutOfMemory",
		2: "Internal",
	}
	ErrorCode_value = map[string]int32{
		"Zero":        0,
		"OutOfMemory": 1,
		"Internal":    2,
	}
)

Enum value maps for ErrorCode.

View Source
var ChatService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "local.ChatService",
	HandlerType: (*ChatServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Completion",
			Handler:    _ChatService_Completion_Handler,
		},
		{
			MethodName: "Embedings",
			Handler:    _ChatService_Embedings_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Chat",
			Handler:       _ChatService_Chat_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "llms/local/chat.proto",
}

ChatService_ServiceDesc is the grpc.ServiceDesc for ChatService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var File_llms_local_chat_proto protoreflect.FileDescriptor

Functions

func PromptMessage

func PromptMessage(model string, messages []schema.Message) string

func RegisterChatServiceServer

func RegisterChatServiceServer(s grpc.ServiceRegistrar, srv ChatServiceServer)

Types

type ChatServiceClient

type ChatServiceClient interface {
	Completion(ctx context.Context, in *GenerationRequest, opts ...grpc.CallOption) (*GenerationReply, error)
	Chat(ctx context.Context, in *GenerationRequest, opts ...grpc.CallOption) (ChatService_ChatClient, error)
	Embedings(ctx context.Context, in *EmbedingsMessage, opts ...grpc.CallOption) (*EmbedingsResp, error)
}

ChatServiceClient is the client API for ChatService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type ChatServiceServer

type ChatServiceServer interface {
	Completion(context.Context, *GenerationRequest) (*GenerationReply, error)
	Chat(*GenerationRequest, ChatService_ChatServer) error
	Embedings(context.Context, *EmbedingsMessage) (*EmbedingsResp, error)
	// contains filtered or unexported methods
}

ChatServiceServer is the server API for ChatService service. All implementations must embed UnimplementedChatServiceServer for forward compatibility

type ChatService_ChatClient

type ChatService_ChatClient interface {
	Recv() (*GenerationReply, error)
	grpc.ClientStream
}

type ChatService_ChatServer

type ChatService_ChatServer interface {
	Send(*GenerationReply) error
	grpc.ServerStream
}

type EmbeddingData

type EmbeddingData struct {
	Embedding []float32 `protobuf:"fixed32,1,rep,packed,name=embedding,proto3" json:"embedding,omitempty"`
	// contains filtered or unexported fields
}

func (*EmbeddingData) Descriptor deprecated

func (*EmbeddingData) Descriptor() ([]byte, []int)

Deprecated: Use EmbeddingData.ProtoReflect.Descriptor instead.

func (*EmbeddingData) GetEmbedding

func (x *EmbeddingData) GetEmbedding() []float32

func (*EmbeddingData) ProtoMessage

func (*EmbeddingData) ProtoMessage()

func (*EmbeddingData) ProtoReflect

func (x *EmbeddingData) ProtoReflect() protoreflect.Message

func (*EmbeddingData) Reset

func (x *EmbeddingData) Reset()

func (*EmbeddingData) String

func (x *EmbeddingData) String() string

type EmbedingsMessage

type EmbedingsMessage struct {
	Prompt []string `protobuf:"bytes,1,rep,name=prompt,proto3" json:"prompt,omitempty"`
	// contains filtered or unexported fields
}

func NewEmbeddingsRequest

func NewEmbeddingsRequest(req *schema.EmbeddingsRequest) *EmbedingsMessage

func (*EmbedingsMessage) Descriptor deprecated

func (*EmbedingsMessage) Descriptor() ([]byte, []int)

Deprecated: Use EmbedingsMessage.ProtoReflect.Descriptor instead.

func (*EmbedingsMessage) GetPrompt

func (x *EmbedingsMessage) GetPrompt() []string

func (*EmbedingsMessage) ProtoMessage

func (*EmbedingsMessage) ProtoMessage()

func (*EmbedingsMessage) ProtoReflect

func (x *EmbedingsMessage) ProtoReflect() protoreflect.Message

func (*EmbedingsMessage) Reset

func (x *EmbedingsMessage) Reset()

func (*EmbedingsMessage) String

func (x *EmbedingsMessage) String() string

type EmbedingsResp

type EmbedingsResp struct {
	ErrorCode  ErrorCode        `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3,enum=local.ErrorCode" json:"error_code,omitempty"`
	Embeddings []*EmbeddingData `protobuf:"bytes,2,rep,name=Embeddings,proto3" json:"Embeddings,omitempty"`
	TokenNum   int32            `protobuf:"varint,3,opt,name=token_num,json=tokenNum,proto3" json:"token_num,omitempty"`
	// contains filtered or unexported fields
}

func (*EmbedingsResp) Descriptor deprecated

func (*EmbedingsResp) Descriptor() ([]byte, []int)

Deprecated: Use EmbedingsResp.ProtoReflect.Descriptor instead.

func (*EmbedingsResp) GetEmbeddings

func (x *EmbedingsResp) GetEmbeddings() []*EmbeddingData

func (*EmbedingsResp) GetErrorCode

func (x *EmbedingsResp) GetErrorCode() ErrorCode

func (*EmbedingsResp) GetTokenNum

func (x *EmbedingsResp) GetTokenNum() int32

func (*EmbedingsResp) ProtoMessage

func (*EmbedingsResp) ProtoMessage()

func (*EmbedingsResp) ProtoReflect

func (x *EmbedingsResp) ProtoReflect() protoreflect.Message

func (*EmbedingsResp) Reset

func (x *EmbedingsResp) Reset()

func (*EmbedingsResp) String

func (x *EmbedingsResp) String() string

type ErrorCode

type ErrorCode int32
const (
	ErrorCode_Zero        ErrorCode = 0
	ErrorCode_OutOfMemory ErrorCode = 1
	ErrorCode_Internal    ErrorCode = 2
)

func (ErrorCode) Descriptor

func (ErrorCode) Descriptor() protoreflect.EnumDescriptor

func (ErrorCode) Enum

func (x ErrorCode) Enum() *ErrorCode

func (ErrorCode) EnumDescriptor deprecated

func (ErrorCode) EnumDescriptor() ([]byte, []int)

Deprecated: Use ErrorCode.Descriptor instead.

func (ErrorCode) Number

func (x ErrorCode) Number() protoreflect.EnumNumber

func (ErrorCode) String

func (x ErrorCode) String() string

func (ErrorCode) Type

type GenerationReply

type GenerationReply struct {
	ErrorCode    ErrorCode   `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3,enum=local.ErrorCode" json:"error_code,omitempty"`
	Text         string      `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"`
	Usage        *TokenUsage `protobuf:"bytes,3,opt,name=usage,proto3" json:"usage,omitempty"`
	FinishReason string      `protobuf:"bytes,4,opt,name=finish_reason,json=finishReason,proto3" json:"finish_reason,omitempty"`
	// contains filtered or unexported fields
}

func (*GenerationReply) Descriptor deprecated

func (*GenerationReply) Descriptor() ([]byte, []int)

Deprecated: Use GenerationReply.ProtoReflect.Descriptor instead.

func (*GenerationReply) GetErrorCode

func (x *GenerationReply) GetErrorCode() ErrorCode

func (*GenerationReply) GetFinishReason

func (x *GenerationReply) GetFinishReason() string

func (*GenerationReply) GetText

func (x *GenerationReply) GetText() string

func (*GenerationReply) GetUsage

func (x *GenerationReply) GetUsage() *TokenUsage

func (*GenerationReply) ProtoMessage

func (*GenerationReply) ProtoMessage()

func (*GenerationReply) ProtoReflect

func (x *GenerationReply) ProtoReflect() protoreflect.Message

func (*GenerationReply) Reset

func (x *GenerationReply) Reset()

func (*GenerationReply) String

func (x *GenerationReply) String() string

type GenerationRequest

type GenerationRequest struct {
	Prompt            string   `protobuf:"bytes,1,opt,name=prompt,proto3" json:"prompt,omitempty"`
	Temperature       float32  `protobuf:"fixed32,2,opt,name=temperature,proto3" json:"temperature,omitempty"`
	TopP              float32  `protobuf:"fixed32,3,opt,name=top_p,json=topP,proto3" json:"top_p,omitempty"`
	N                 int32    `protobuf:"varint,4,opt,name=n,proto3" json:"n,omitempty"`
	MaxNewTokens      int32    `protobuf:"varint,5,opt,name=max_new_tokens,json=maxNewTokens,proto3" json:"max_new_tokens,omitempty"`
	TopK              int32    `protobuf:"varint,6,opt,name=top_k,json=topK,proto3" json:"top_k,omitempty"`
	RepetitionPenalty float32  `protobuf:"fixed32,7,opt,name=repetition_penalty,json=repetitionPenalty,proto3" json:"repetition_penalty,omitempty"`
	Echo              bool     `protobuf:"varint,8,opt,name=echo,proto3" json:"echo,omitempty"`
	Stop              string   `protobuf:"bytes,9,opt,name=stop,proto3" json:"stop,omitempty"`
	StopTokenIds      []string `protobuf:"bytes,10,rep,name=stop_token_ids,json=stopTokenIds,proto3" json:"stop_token_ids,omitempty"`
	// contains filtered or unexported fields
}

func NewGenerationRequestByChatRequest

func NewGenerationRequestByChatRequest(model_name string, req *schema.ChatRequest) *GenerationRequest

func NewGenerationRequestByCompletionRequest

func NewGenerationRequestByCompletionRequest(req *schema.CompletionRequest) *GenerationRequest

func (*GenerationRequest) Descriptor deprecated

func (*GenerationRequest) Descriptor() ([]byte, []int)

Deprecated: Use GenerationRequest.ProtoReflect.Descriptor instead.

func (*GenerationRequest) GetEcho

func (x *GenerationRequest) GetEcho() bool

func (*GenerationRequest) GetMaxNewTokens

func (x *GenerationRequest) GetMaxNewTokens() int32

func (*GenerationRequest) GetN

func (x *GenerationRequest) GetN() int32

func (*GenerationRequest) GetPrompt

func (x *GenerationRequest) GetPrompt() string

func (*GenerationRequest) GetRepetitionPenalty

func (x *GenerationRequest) GetRepetitionPenalty() float32

func (*GenerationRequest) GetStop

func (x *GenerationRequest) GetStop() string

func (*GenerationRequest) GetStopTokenIds

func (x *GenerationRequest) GetStopTokenIds() []string

func (*GenerationRequest) GetTemperature

func (x *GenerationRequest) GetTemperature() float32

func (*GenerationRequest) GetTopK

func (x *GenerationRequest) GetTopK() int32

func (*GenerationRequest) GetTopP

func (x *GenerationRequest) GetTopP() float32

func (*GenerationRequest) ProtoMessage

func (*GenerationRequest) ProtoMessage()

func (*GenerationRequest) ProtoReflect

func (x *GenerationRequest) ProtoReflect() protoreflect.Message

func (*GenerationRequest) Reset

func (x *GenerationRequest) Reset()

func (*GenerationRequest) String

func (x *GenerationRequest) String() string

type LLaMA

type LLaMA struct {

	//Model the model name
	Model string `json:"model" yaml:"model"`

	// Hosts of server including the version.
	Hosts []string `json:"hosts" yaml:"hosts"`
	// contains filtered or unexported fields
}

func FromYaml

func FromYaml(opt llms.ModelOptions) (*LLaMA, error)

func New

func New(opts ...ModelOption) *LLaMA

New return OpenAI compatiable client

func (*LLaMA) Call

func (l *LLaMA) Call(ctx context.Context, prompt string) (string, error)

Call implements llms.LLM.

func (*LLaMA) Chat

func (l *LLaMA) Chat(ctx context.Context, req *schema.ChatRequest) (resp *schema.ChatResponse, err error)

Chat implements llms.LLM.

func (*LLaMA) Completion

func (l *LLaMA) Completion(ctx context.Context, req *schema.CompletionRequest) (resp *schema.CompletionResponse, err error)

Completion implements llms.LLM.

func (*LLaMA) Embeddings

func (l *LLaMA) Embeddings(ctx context.Context, req *schema.EmbeddingsRequest) (resp *schema.EmbeddingsResponse, err error)

Embeddings implements llms.LLM.

func (*LLaMA) Free

func (l *LLaMA) Free()

Free implements llms.LLM.

func (*LLaMA) Name

func (l *LLaMA) Name() string

Name implements llms.LLM.

type ModelOption

type ModelOption func(*LLaMA)

CallOption is a function that configures a LLM.

func WithHosts

func WithHosts(o []string) ModelOption

WithHosts sets the Host that for gRPC Server default is 127.0.0.1:50051

func WithModel

func WithModel(o string) ModelOption

WithModel sets the model for us.

type TokenUsage

type TokenUsage struct {
	PromptTokens     int32 `protobuf:"varint,1,opt,name=prompt_tokens,json=promptTokens,proto3" json:"prompt_tokens,omitempty"`
	CompletionTokens int32 `protobuf:"varint,2,opt,name=completion_tokens,json=completionTokens,proto3" json:"completion_tokens,omitempty"`
	TotalTokens      int32 `protobuf:"varint,3,opt,name=total_tokens,json=totalTokens,proto3" json:"total_tokens,omitempty"`
	// contains filtered or unexported fields
}

func (*TokenUsage) Descriptor deprecated

func (*TokenUsage) Descriptor() ([]byte, []int)

Deprecated: Use TokenUsage.ProtoReflect.Descriptor instead.

func (*TokenUsage) GetCompletionTokens

func (x *TokenUsage) GetCompletionTokens() int32

func (*TokenUsage) GetPromptTokens

func (x *TokenUsage) GetPromptTokens() int32

func (*TokenUsage) GetTotalTokens

func (x *TokenUsage) GetTotalTokens() int32

func (*TokenUsage) ProtoMessage

func (*TokenUsage) ProtoMessage()

func (*TokenUsage) ProtoReflect

func (x *TokenUsage) ProtoReflect() protoreflect.Message

func (*TokenUsage) Reset

func (x *TokenUsage) Reset()

func (*TokenUsage) String

func (x *TokenUsage) String() string

type UnimplementedChatServiceServer

type UnimplementedChatServiceServer struct {
}

UnimplementedChatServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedChatServiceServer) Chat

func (UnimplementedChatServiceServer) Completion

func (UnimplementedChatServiceServer) Embedings

type UnsafeChatServiceServer

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

UnsafeChatServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ChatServiceServer will result in compilation errors.

Jump to

Keyboard shortcuts

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