Table of Contents

Class Message

Namespace
OllamaSharp.Models.Chat
Assembly
OllamaSharp.dll

Represents a message in a chat.

public class Message
Inheritance
Message
Inherited Members

Constructors

Message()

Initializes a new instance of the Message class. Required for JSON deserialization.

public Message()

Message(ChatRole, string, string[]?)

Initializes a new instance of the Message class with the specified role, content, and images.

public Message(ChatRole role, string content, string[]? images)

Parameters

role ChatRole

The role of the message, either system, user, or assistant.

content string

The content of the message.

images string[]

An array of base64-encoded images.

Message(ChatRole, string[])

Initializes a new instance of the Message class with the specified role and images.

public Message(ChatRole role, string[] images)

Parameters

role ChatRole

The role of the message, either system, user, or assistant.

images string[]

An array of base64-encoded images.

Message(ChatRole?, string)

Initializes a new instance of the Message class with the specified role and content.

public Message(ChatRole? role, string content)

Parameters

role ChatRole?

The role of the message, either system, user, or assistant.

content string

The content of the message.

Properties

Content

Gets or sets the content of the message.

[JsonPropertyName("content")]
public string? Content { get; set; }

Property Value

string

Images

Gets or sets an array of base64-encoded images (for multimodal models such as llava).

[JsonPropertyName("images")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string[]? Images { get; set; }

Property Value

string[]

Role

Gets or sets the role of the message, either system, user, or assistant.

[JsonPropertyName("role")]
public ChatRole? Role { get; set; }

Property Value

ChatRole?

Thinking

Gets or sets the parsed content of the thinking and reasoning. To make this work, enable Think.

[JsonPropertyName("thinking")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Thinking { get; set; }

Property Value

string

ToolCalls

Gets or sets a list of tools the model wants to use (for models that support function calls, such as llama3.1).

[JsonPropertyName("tool_calls")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IEnumerable<Message.ToolCall>? ToolCalls { get; set; }

Property Value

IEnumerable<Message.ToolCall>

ToolName

Gets or sets the name of the tool that was executed to inform the model of the result.

[JsonPropertyName("tool_name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ToolName { get; set; }

Property Value

string