|
@@ -33,7 +33,7 @@ type LlamaServer interface {
|
|
Ping(ctx context.Context) error
|
|
Ping(ctx context.Context) error
|
|
WaitUntilRunning(ctx context.Context) error
|
|
WaitUntilRunning(ctx context.Context) error
|
|
Completion(ctx context.Context, req CompletionRequest, fn func(CompletionResponse)) error
|
|
Completion(ctx context.Context, req CompletionRequest, fn func(CompletionResponse)) error
|
|
- Embed(ctx context.Context, input []string) ([][]float32, error)
|
|
|
|
|
|
+ Embed(ctx context.Context, input []string, images []ImageData) ([][]float32, error)
|
|
Tokenize(ctx context.Context, content string) ([]int, error)
|
|
Tokenize(ctx context.Context, content string) ([]int, error)
|
|
Detokenize(ctx context.Context, tokens []int) (string, error)
|
|
Detokenize(ctx context.Context, tokens []int) (string, error)
|
|
Close() error
|
|
Close() error
|
|
@@ -860,14 +860,15 @@ func (s *llmServer) Completion(ctx context.Context, req CompletionRequest, fn fu
|
|
}
|
|
}
|
|
|
|
|
|
type EmbedRequest struct {
|
|
type EmbedRequest struct {
|
|
- Content []string `json:"content"`
|
|
|
|
|
|
+ Content []string `json:"content"`
|
|
|
|
+ Images []ImageData `json:"image_data"`
|
|
}
|
|
}
|
|
|
|
|
|
type EmbedResponse struct {
|
|
type EmbedResponse struct {
|
|
Embedding [][]float32 `json:"embedding"`
|
|
Embedding [][]float32 `json:"embedding"`
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *llmServer) Embed(ctx context.Context, input []string) ([][]float32, error) {
|
|
|
|
|
|
+func (s *llmServer) Embed(ctx context.Context, input []string, images []ImageData) ([][]float32, error) {
|
|
if err := s.sem.Acquire(ctx, 1); err != nil {
|
|
if err := s.sem.Acquire(ctx, 1); err != nil {
|
|
slog.Error("Failed to acquire semaphore", "error", err)
|
|
slog.Error("Failed to acquire semaphore", "error", err)
|
|
return nil, err
|
|
return nil, err
|
|
@@ -882,7 +883,7 @@ func (s *llmServer) Embed(ctx context.Context, input []string) ([][]float32, err
|
|
return nil, fmt.Errorf("unexpected server status: %s", status.ToString())
|
|
return nil, fmt.Errorf("unexpected server status: %s", status.ToString())
|
|
}
|
|
}
|
|
|
|
|
|
- data, err := json.Marshal(EmbedRequest{Content: input})
|
|
|
|
|
|
+ data, err := json.Marshal(EmbedRequest{Content: input, Images: images})
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error marshaling embed data: %w", err)
|
|
return nil, fmt.Errorf("error marshaling embed data: %w", err)
|
|
}
|
|
}
|