Table of Contents

Class Part

Namespace
Google.GenAI.Types
Assembly
Google.GenAI.dll

A datatype containing media content. Exactly one field within a Part should be set, representing the specific type of content being conveyed. Using multiple fields within the same Part instance is considered invalid.

public record Part : IEquatable<Part>
Inheritance
Part
Implements
Inherited Members

Properties

CodeExecutionResult

Optional. The result of executing the ExecutableCode.

[JsonPropertyName("codeExecutionResult")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public CodeExecutionResult? CodeExecutionResult { get; set; }

Property Value

CodeExecutionResult

ExecutableCode

Optional. Code generated by the model that is intended to be executed.

[JsonPropertyName("executableCode")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ExecutableCode? ExecutableCode { get; set; }

Property Value

ExecutableCode

FileData

Optional. The URI-based data of the part. This can be used to include files from Google Cloud Storage.

[JsonPropertyName("fileData")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FileData? FileData { get; set; }

Property Value

FileData

FunctionCall

Optional. A predicted function call returned from the model. This contains the name of the function to call and the arguments to pass to the function.

[JsonPropertyName("functionCall")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FunctionCall? FunctionCall { get; set; }

Property Value

FunctionCall

FunctionResponse

Optional. The result of a function call. This is used to provide the model with the result of a function call that it predicted.

[JsonPropertyName("functionResponse")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public FunctionResponse? FunctionResponse { get; set; }

Property Value

FunctionResponse

InlineData

Optional. The inline data content of the part. This can be used to include images, audio, or video in a request.

[JsonPropertyName("inlineData")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Blob? InlineData { get; set; }

Property Value

Blob

MediaResolution

Media resolution for the input media.

[JsonPropertyName("mediaResolution")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public PartMediaResolution? MediaResolution { get; set; }

Property Value

PartMediaResolution

PartMetadata

Custom metadata associated with the Part. Agents using genai.Part as content representation may need to keep track of the additional information. For example it can be name of a file/source from which the Part originates or a way to multiplex multiple Part streams. This field is not supported in Vertex AI.

[JsonPropertyName("partMetadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public Dictionary<string, object>? PartMetadata { get; set; }

Property Value

Dictionary<string, object>

Text

Optional. The text content of the part. When sent from the VSCode Gemini Code Assist extension, references to @mentioned items will be converted to markdown boldface text. For example @my-repo will be converted to and sent as **my-repo** by the IDE agent.

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

Property Value

string

Thought

Optional. Indicates whether the part represents the model's thought process or reasoning.

[JsonPropertyName("thought")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? Thought { get; set; }

Property Value

bool?

ThoughtSignature

Optional. An opaque signature for the thought so it can be reused in subsequent requests.

[JsonPropertyName("thoughtSignature")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public byte[]? ThoughtSignature { get; set; }

Property Value

byte[]

ToolCall

Server-side tool call. This field is populated when the model predicts a tool invocation that should be executed on the server. The client is expected to echo this message back to the API.

[JsonPropertyName("toolCall")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ToolCall? ToolCall { get; set; }

Property Value

ToolCall

ToolResponse

The output from a server-side ToolCall execution. This field is populated by the client with the results of executing the corresponding ToolCall.

[JsonPropertyName("toolResponse")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ToolResponse? ToolResponse { get; set; }

Property Value

ToolResponse

VideoMetadata

Optional. Video metadata. The metadata should only be specified while the video data is presented in inline_data or file_data.

[JsonPropertyName("videoMetadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public VideoMetadata? VideoMetadata { get; set; }

Property Value

VideoMetadata

Methods

FromBytes(byte[], string, PartMediaResolution?)

Creates a Part with inline binary data. mimeType must be a valid IANA MIME type string (e.g. "image/jpeg").

public static Part FromBytes(byte[] data, string mimeType, PartMediaResolution? mediaResolution = null)

Parameters

data byte[]
mimeType string
mediaResolution PartMediaResolution

Returns

Part

FromCodeExecutionResult(Outcome, string)

Creates a Part containing a code execution result.

public static Part FromCodeExecutionResult(Outcome outcome, string output)

Parameters

outcome Outcome
output string

Returns

Part

FromExecutableCode(string, Language)

Creates a Part containing executable code.

public static Part FromExecutableCode(string code, Language language)

Parameters

code string
language Language

Returns

Part

FromFunctionCall(string, Dictionary<string, object>?)

Creates a Part containing a model-issued function call.

public static Part FromFunctionCall(string name, Dictionary<string, object>? args = null)

Parameters

name string
args Dictionary<string, object>

Returns

Part

FromFunctionResponse(string, Dictionary<string, object>?, List<FunctionResponsePart>?)

Creates a Part containing the result of a function call.

public static Part FromFunctionResponse(string name, Dictionary<string, object>? response = null, List<FunctionResponsePart>? parts = null)

Parameters

name string
response Dictionary<string, object>
parts List<FunctionResponsePart>

Returns

Part

FromJson(string, JsonSerializerOptions?)

Deserializes a JSON string to a Part object.

public static Part? FromJson(string jsonString, JsonSerializerOptions? options = null)

Parameters

jsonString string

The JSON string to deserialize.

options JsonSerializerOptions

Optional JsonSerializerOptions.

Returns

Part

The deserialized Part object, or null if deserialization fails.

FromText(string)

Creates a Part with text content.

public static Part FromText(string text)

Parameters

text string

Returns

Part

FromUri(string, string?, PartMediaResolution?)

Creates a Part from a file URI. If mimeType is not provided it is inferred from the URI's file extension. Throws ArgumentException if the MIME type cannot be determined.

public static Part FromUri(string fileUri, string? mimeType = null, PartMediaResolution? mediaResolution = null)

Parameters

fileUri string
mimeType string
mediaResolution PartMediaResolution

Returns

Part