From 3c786eda251b606d63e5b1197a33255853a4f06a Mon Sep 17 00:00:00 2001
From: Milkey Tan <24996957+mili-tan@users.noreply.github.com>
Date: Sun, 28 Jul 2024 19:50:48 +0800
Subject: [PATCH 1/2] Add ToolCalls
---
src/Models/Chat/ChatResponseStream.cs | 9 +++++++++
src/Models/Chat/Message.cs | 22 ++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/Models/Chat/ChatResponseStream.cs b/src/Models/Chat/ChatResponseStream.cs
index b8e3715..8f81538 100644
--- a/src/Models/Chat/ChatResponseStream.cs
+++ b/src/Models/Chat/ChatResponseStream.cs
@@ -27,4 +27,13 @@ public class ChatResponseStream
///
[JsonPropertyName("done")]
public bool Done { get; set; }
+
+
+ ///
+ /// The reason the response is complete
+ ///
+ [JsonPropertyName("done_reason")]
+ public bool DoneReason { get; set; }
+
+
}
\ No newline at end of file
diff --git a/src/Models/Chat/Message.cs b/src/Models/Chat/Message.cs
index d6751e7..00cb82c 100644
--- a/src/Models/Chat/Message.cs
+++ b/src/Models/Chat/Message.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json.Serialization;
@@ -50,4 +51,25 @@ public Message()
///
[JsonPropertyName("images")]
public string[]? Images { get; set; }
+
+ ///
+ /// The tool calls made by the model (for models that support function calls, such as llama3.1)
+ ///
+ [JsonPropertyName("tool_calls")]
+ public List? ToolCalls { get; set; }
+
+ public class ToolCall
+ {
+ [JsonPropertyName("function")]
+ public Function? Function { get; set; }
+ }
+
+ public class Function
+ {
+ [JsonPropertyName("name")]
+ public string? Name { get; set; }
+
+ [JsonPropertyName("arguments")]
+ public Dictionary? Arguments { get; set; }
+ }
}
\ No newline at end of file
From a58f33ce449068e984df85f763306b89337d0262 Mon Sep 17 00:00:00 2001
From: Milkey Tan <24996957+mili-tan@users.noreply.github.com>
Date: Sun, 28 Jul 2024 20:04:43 +0800
Subject: [PATCH 2/2] Add Tools
---
src/Models/Chat/ChatRequest.cs | 42 ++++++++++++++++++++++++++-
src/Models/Chat/ChatResponseStream.cs | 9 ------
src/Models/Chat/Message.cs | 2 +-
3 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/src/Models/Chat/ChatRequest.cs b/src/Models/Chat/ChatRequest.cs
index 9e75bd1..fbadf5e 100644
--- a/src/Models/Chat/ChatRequest.cs
+++ b/src/Models/Chat/ChatRequest.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
+using static OllamaSharp.Models.Chat.Message;
namespace OllamaSharp.Models.Chat;
@@ -53,4 +54,43 @@ public class ChatRequest
///
[JsonPropertyName("stream")]
public bool Stream { get; set; } = true;
-}
\ No newline at end of file
+
+ ///
+ /// Tools for the model to use if supported. Requires stream to be set to false.
+ ///
+ [JsonPropertyName("tools")]
+ public List? Tools { get; set; }
+}
+
+public class Tool
+{
+ [JsonPropertyName("type")]
+ public string? Type { get; set; }
+
+ [JsonPropertyName("function")]
+ public Function? Function { get; set; }
+}
+
+public class Function
+{
+ [JsonPropertyName("name")]
+ public string? Name { get; set; }
+
+ [JsonPropertyName("description")]
+ public string? Description { get; set; }
+
+ [JsonPropertyName("parameters")]
+ public Dictionary? Parameters { get; set; }
+}
+
+public class Parameter
+{
+ [JsonPropertyName("type")]
+ public string? Type { get; set; }
+
+ [JsonPropertyName("description")]
+ public string? Description { get; set; }
+
+ [JsonPropertyName("enum")]
+ public List? Enum { get; set; }
+}
diff --git a/src/Models/Chat/ChatResponseStream.cs b/src/Models/Chat/ChatResponseStream.cs
index 8f81538..b8e3715 100644
--- a/src/Models/Chat/ChatResponseStream.cs
+++ b/src/Models/Chat/ChatResponseStream.cs
@@ -27,13 +27,4 @@ public class ChatResponseStream
///
[JsonPropertyName("done")]
public bool Done { get; set; }
-
-
- ///
- /// The reason the response is complete
- ///
- [JsonPropertyName("done_reason")]
- public bool DoneReason { get; set; }
-
-
}
\ No newline at end of file
diff --git a/src/Models/Chat/Message.cs b/src/Models/Chat/Message.cs
index 00cb82c..7703392 100644
--- a/src/Models/Chat/Message.cs
+++ b/src/Models/Chat/Message.cs
@@ -53,7 +53,7 @@ public Message()
public string[]? Images { get; set; }
///
- /// The tool calls made by the model (for models that support function calls, such as llama3.1)
+ /// A list of tools the model wants to use (for models that support function calls, such as llama3.1)
///
[JsonPropertyName("tool_calls")]
public List? ToolCalls { get; set; }