Browse Source

Revert "Simplifying image handling"

This reverts commit f264024666.
pull/689/head
Zoli Somogyi 2 years ago
parent
commit
6bd269da60
3 changed files with 46 additions and 4 deletions
  1. +1
    -1
      LLama.Examples/Examples/LlavaInteractiveModeExecute.cs
  2. +43
    -1
      LLama/Abstractions/ILLamaExecutor.cs
  3. +2
    -2
      LLama/LLamaStatelessExecutor.cs

+ 1
- 1
LLama.Examples/Examples/LlavaInteractiveModeExecute.cs View File

@@ -102,7 +102,7 @@ namespace LLama.Examples.Examples
//
foreach (var image in imagePaths)
{
ex.Images.Add(File.ReadAllBytes(image));
ex.Images.Add(new ImageData(ImageData.DataType.ImagePath, image));
}
}



+ 43
- 1
LLama/Abstractions/ILLamaExecutor.cs View File

@@ -27,7 +27,7 @@ namespace LLama.Abstractions
/// <summary>
/// List of images: Image filen path, uri or image byte array. See ImageData.
/// </summary>
public List<byte[]> Images { get; }
public List<ImageData> Images { get; }

/// <summary>
/// Asynchronously infers a response from the model.
@@ -38,4 +38,46 @@ namespace LLama.Abstractions
/// <returns></returns>
IAsyncEnumerable<string> InferAsync(string text, IInferenceParams? inferenceParams = null, CancellationToken token = default);
}

/// <summary>
/// Holds image data
/// </summary>
public class ImageData
{
/// <summary>
/// constructor
/// </summary>
/// <param name="type"></param>
/// <param name="data"></param>
public ImageData(DataType type, object data) { Type = type; Data = data; }

/// <summary>
/// the possible types of image data
/// </summary>
public enum DataType
{
/// <summary>
/// file path
/// </summary>
ImagePath,
/// <summary>
/// byte array
/// </summary>
ImageBytes,
/// <summary>
/// uri
/// </summary>
ImageURL
}

/// <summary>
/// the type of this image data
/// </summary>
public DataType Type { get; set; }

/// <summary>
/// the image data (string, byte array or uri)
/// </summary>
public object? Data { get; set; }
}
}

+ 2
- 2
LLama/LLamaStatelessExecutor.cs View File

@@ -34,7 +34,7 @@ namespace LLama
public LLavaWeights? ClipModel { get; }

/// <inheritdoc />
public List<byte[]> Images { get; set; }
public List<ImageData> Images { get; set; }

/// <summary>
/// The context used by the executor when running the inference.
@@ -49,7 +49,7 @@ namespace LLama
/// <param name="logger"></param>
public StatelessExecutor(LLamaWeights weights, IContextParams @params, ILogger? logger = null)
{
Images = new List<byte[]>();
Images = new List<ImageData>();
_weights = weights;
_params = @params;
_logger = logger;


Loading…
Cancel
Save