Skip to content

Commit

Permalink
Merge pull request #416 from martindevans/IModelParams_better_exception
Browse files Browse the repository at this point in the history
Improved exceptions in IModelParams for unknown KV override types.
  • Loading branch information
martindevans authored Jan 6, 2024
2 parents d74e6c7 + 8416cb8 commit c696cda
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions LLama/Abstractions/IModelParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -272,11 +273,11 @@ internal void WriteValue(ref LLamaModelMetadataOverride dest)
dest.BoolValue = _valueBool ? -1L : 0;
break;
default:
throw new ArgumentOutOfRangeException();
throw new InvalidEnumArgumentException($"Unknown {nameof(LLamaModelKvOverrideType)} value: {Type}");
}
}

internal void WriteValue(Utf8JsonWriter writer, JsonSerializerOptions options)
internal void WriteValue(Utf8JsonWriter writer)
{
switch (Type)
{
Expand All @@ -290,7 +291,7 @@ internal void WriteValue(Utf8JsonWriter writer, JsonSerializerOptions options)
writer.WriteBooleanValue(_valueBool);
break;
default:
throw new ArgumentOutOfRangeException();
throw new InvalidEnumArgumentException($"Unknown {nameof(LLamaModelKvOverrideType)} value: {Type}");
}
}
}
Expand Down Expand Up @@ -323,7 +324,7 @@ public override void Write(Utf8JsonWriter writer, MetadataOverride value, JsonSe
writer.WriteNumber("Type", (int)value.Type);
writer.WriteString("Key", value.Key);
writer.WritePropertyName("Value");
value.WriteValue(writer, options);
value.WriteValue(writer);
}
writer.WriteEndObject();
}
Expand Down

0 comments on commit c696cda

Please sign in to comment.