openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.12

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Chat/Streaming/StreamingChatToolCallUpdate.cs

76lines · modecode

1namespace OpenAI.Chat;
2
3using System;
4using System.Text.Json;
5
6/// <summary>
7/// A base representation of an incremental update to a streaming tool call that is part of a streaming chat completion
8/// request.
9/// </summary>
10/// <remarks>
11/// <para>
12/// This type encapsulates the payload located in e.g. <c>$.choices[0].delta.tool_calls[]</c> in the REST API schema.
13/// </para>
14/// <para>
15/// To differentiate between parallel streaming tool calls within a single streaming choice, use the value of the
16/// <see cref="Index"/> property.
17/// </para>
18/// <para>
19/// <see cref="StreamingChatToolCallUpdate"/> is the streaming, base class counterpart to <see cref="ChatToolCall"/>.
20/// </para>
21/// </remarks>
22[CodeGenModel("ChatCompletionMessageToolCallChunk")]
23[CodeGenSuppress("StreamingChatToolCallUpdate", typeof(int))]
24public partial class StreamingChatToolCallUpdate
25{
26 [CodeGenMember("Function")]
27 internal InternalChatCompletionMessageToolCallChunkFunction Function { get; }
28
29 internal StreamingChatToolCallUpdate(int index, string id, InternalChatCompletionMessageToolCallChunkFunction function)
30 {
31 Argument.AssertNotNull(id, nameof(id));
32 Argument.AssertNotNull(function, nameof(function));
33
34 Kind = ChatToolCallKind.Function;
35
36 Index = index;
37 Id = id;
38 Function = function;
39 }
40
41 // CUSTOM:
42 // - Renamed.
43 // - Changed type from string.
44 /// <summary> The kind of tool.Currently, only<see cref="ChatToolCallKind.Function"/> is supported. </summary>
45 [CodeGenMember("Type")]
46 public ChatToolCallKind Kind { get; } = ChatToolCallKind.Function;
47
48 /// <summary>
49 /// The name of the function requested by the tool call.
50 /// </summary>
51 /// <remarks>
52 /// <para>
53 /// Corresponds to e.g. <c>$.choices[0].delta.tool_calls[0].function.name</c> in the REST API schema.
54 /// </para>
55 /// <para>
56 /// For a streaming function tool call, this name will appear in a single streaming update payload, typically the
57 /// first. Use the <see cref="Index"/> property to differentiate between multiple,
58 /// parallel tool calls when streaming.
59 /// </para>
60 /// </remarks>
61 public string FunctionName => Function?.Name;
62
63 /// <summary>
64 /// The next new segment of the function arguments for the function tool called by a streaming tool call.
65 /// These must be accumulated for the complete contents of the function arguments.
66 /// </summary>
67 /// <remarks>
68 /// <para>
69 /// Corresponds to e.g. <c>$.choices[0].delta.tool_calls[0].function.arguments</c> in the REST API schema.
70 /// </para>
71 /// Note that the model does not always generate valid JSON and may hallucinate parameters
72 /// not defined by your function schema. Validate the arguments in your code before calling
73 /// your function.
74 /// </remarks>
75 public string FunctionArgumentsUpdate => Function?.Arguments;
76}
77