Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions LLama/Extensions/LLamaExecutorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void Dispose() { }

/// <inheritdoc/>
public async Task<ChatResponse> GetResponseAsync(
IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
{
var result = _executor.InferAsync(CreatePrompt(chatMessages), CreateInferenceParams(options), cancellationToken);
var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken);

StringBuilder text = new();
await foreach (var token in _outputTransform.TransformAsync(result))
Expand All @@ -79,23 +79,21 @@ public async Task<ChatResponse> GetResponseAsync(

/// <inheritdoc/>
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
IList<ChatMessage> chatMessages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var result = _executor.InferAsync(CreatePrompt(chatMessages), CreateInferenceParams(options), cancellationToken);
var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken);

await foreach (var token in _outputTransform.TransformAsync(result))
{
yield return new()
yield return new(ChatRole.Assistant, token)
{
CreatedAt = DateTime.UtcNow,
Role = ChatRole.Assistant,
Text = token,
};
}
}

/// <summary>Format the chat messages into a string prompt.</summary>
private string CreatePrompt(IList<ChatMessage> messages)
private string CreatePrompt(IEnumerable<ChatMessage> messages)
{
if (messages is null)
{
Expand Down
2 changes: 1 addition & 1 deletion LLama/LLamaEmbedder.EmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class LLamaEmbedder
private EmbeddingGeneratorMetadata? _metadata;

/// <inheritdoc />
object? IEmbeddingGenerator<string, Embedding<float>>.GetService(Type serviceType, object? serviceKey)
object? IEmbeddingGenerator.GetService(Type serviceType, object? serviceKey)
{
if (serviceKey is null)
{
Expand Down
2 changes: 1 addition & 1 deletion LLama/LLamaSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="System.Numerics.Tensors" Version="9.0.2" />
</ItemGroup>
Expand Down