Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tools & ToolCalls #56

Merged
merged 3 commits into from
Jul 28, 2024
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
42 changes: 41 additions & 1 deletion src/Models/Chat/ChatRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using static OllamaSharp.Models.Chat.Message;

namespace OllamaSharp.Models.Chat;

Expand Down Expand Up @@ -53,4 +54,43 @@ public class ChatRequest
/// </summary>
[JsonPropertyName("stream")]
public bool Stream { get; set; } = true;
}

/// <summary>
/// Tools for the model to use if supported. Requires stream to be set to false.
/// </summary>
[JsonPropertyName("tools")]
public List<Tool>? 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<string, Parameter>? Parameters { get; set; }
}

public class Parameter
{
[JsonPropertyName("type")]
public string? Type { get; set; }

[JsonPropertyName("description")]
public string? Description { get; set; }

[JsonPropertyName("enum")]
public List<string>? Enum { get; set; }
}
22 changes: 22 additions & 0 deletions src/Models/Chat/Message.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -50,4 +51,25 @@ public Message()
/// </summary>
[JsonPropertyName("images")]
public string[]? Images { get; set; }

/// <summary>
/// A list of tools the model wants to use (for models that support function calls, such as llama3.1)
/// </summary>
[JsonPropertyName("tool_calls")]
public List<ToolCall>? 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<string, string>? Arguments { get; set; }
}
}
Loading