Skip to content

Commit 6b477e2

Browse files
authored
Merge pull request #159 from Joy-less/fix-155
Add support for Json Schema in Chat
2 parents 2771cb0 + b70ecdc commit 6b477e2

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Chat.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ public IAsyncEnumerable<string> SendAsync(string message, IEnumerable<string>? i
163163
/// <param name="message">The message to send</param>
164164
/// <param name="tools">Tools that the model can make use of, see https://ollama.com/blog/tool-support. By using tools, response streaming is automatically turned off</param>
165165
/// <param name="imagesAsBase64">Base64 encoded images to send to the model</param>
166+
/// <param name="format">Currently accepts "json" or JsonSchema or null.</param>
166167
/// <param name="cancellationToken">The token to cancel the operation with</param>
167-
public IAsyncEnumerable<string> SendAsync(string message, IReadOnlyCollection<Tool>? tools, IEnumerable<string>? imagesAsBase64 = default, CancellationToken cancellationToken = default)
168-
=> SendAsAsync(ChatRole.User, message, tools, imagesAsBase64, cancellationToken);
168+
public IAsyncEnumerable<string> SendAsync(string message, IEnumerable<Tool>? tools, IEnumerable<string>? imagesAsBase64 = null, object? format = null, CancellationToken cancellationToken = default)
169+
=> SendAsAsync(ChatRole.User, message, tools, imagesAsBase64, format, cancellationToken);
169170

170171
/// <summary>
171172
/// Sends a message in a given role to the currently selected model and streams its response
@@ -203,8 +204,9 @@ public IAsyncEnumerable<string> SendAsAsync(ChatRole role, string message, IEnum
203204
/// <param name="message">The message to send</param>
204205
/// <param name="tools">Tools that the model can make use of, see https://ollama.com/blog/tool-support. By using tools, response streaming is automatically turned off</param>
205206
/// <param name="imagesAsBase64">Base64 encoded images to send to the model</param>
207+
/// <param name="format">Currently accepts "json" or JsonSchema or null.</param>
206208
/// <param name="cancellationToken">The token to cancel the operation with</param>
207-
public async IAsyncEnumerable<string> SendAsAsync(ChatRole role, string message, IReadOnlyCollection<Tool>? tools, IEnumerable<string>? imagesAsBase64 = default, [EnumeratorCancellation] CancellationToken cancellationToken = default)
209+
public async IAsyncEnumerable<string> SendAsAsync(ChatRole role, string message, IEnumerable<Tool>? tools, IEnumerable<string>? imagesAsBase64 = null, object? format = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
208210
{
209211
Messages.Add(new Message(role, message, imagesAsBase64?.ToArray()));
210212

@@ -216,6 +218,7 @@ public async IAsyncEnumerable<string> SendAsAsync(ChatRole role, string message,
216218
Model = Model,
217219
Stream = !hasTools, // cannot stream if tools should be used
218220
Tools = tools,
221+
Format = format,
219222
Options = Options
220223
};
221224

src/Models/Chat/ChatRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class ChatRequest : OllamaRequest
4343
public string? KeepAlive { get; set; }
4444

4545
/// <summary>
46-
/// Gets or sets the format to return a response in. Currently accepts "json" and JsonSchema or null.
46+
/// Gets or sets the format to return a response in. Currently accepts "json" or JsonSchema or null.
4747
/// </summary>
4848
[JsonPropertyName("format")]
4949
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

src/Models/Generate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class GenerateRequest : OllamaRequest
7676
public string? KeepAlive { get; set; }
7777

7878
/// <summary>
79-
/// Gets or sets the format to return a response in. Currently accepts "json" and JsonSchema or null.
79+
/// Gets or sets the format to return a response in. Currently accepts "json" or JsonSchema or null.
8080
/// </summary>
8181
[JsonPropertyName("format")]
8282
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

0 commit comments

Comments
 (0)