openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/customize-openairesponsescontext-attribute

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Assistants/Streaming/StreamingUpdateReason.Serialization.cs

63lines · modecode

1namespace OpenAI.Assistants;
2
3internal static class StreamingUpdateReasonExtensions
4{
5 internal static string ToSseEventLabel(this StreamingUpdateReason value) => value switch
6 {
7 StreamingUpdateReason.ThreadCreated => "thread.created",
8 StreamingUpdateReason.RunCreated => "thread.run.created",
9 StreamingUpdateReason.RunQueued => "thread.run.queued",
10 StreamingUpdateReason.RunInProgress => "thread.run.in_progress",
11 StreamingUpdateReason.RunRequiresAction => "thread.run.requires_action",
12 StreamingUpdateReason.RunCompleted => "thread.run.completed",
13 StreamingUpdateReason.RunFailed => "thread.run.failed",
14 StreamingUpdateReason.RunCancelling => "thread.run.cancelling",
15 StreamingUpdateReason.RunCancelled => "thread.run.cancelled",
16 StreamingUpdateReason.RunExpired => "thread.run.expired",
17 StreamingUpdateReason.RunStepCreated => "thread.run.step.created",
18 StreamingUpdateReason.RunStepInProgress => "thread.run.step.in_progress",
19 StreamingUpdateReason.RunStepUpdated => "thread.run.step.delta",
20 StreamingUpdateReason.RunStepCompleted => "thread.run.step.completed",
21 StreamingUpdateReason.RunStepFailed => "thread.run.step.failed",
22 StreamingUpdateReason.RunStepCancelled => "thread.run.step.cancelled",
23 StreamingUpdateReason.RunStepExpired => "thread.run.step.expired",
24 StreamingUpdateReason.MessageCreated => "thread.message.created",
25 StreamingUpdateReason.MessageInProgress => "thread.message.in_progress",
26 StreamingUpdateReason.MessageUpdated => "thread.message.delta",
27 StreamingUpdateReason.MessageCompleted => "thread.message.completed",
28 StreamingUpdateReason.MessageFailed => "thread.message.incomplete",
29 StreamingUpdateReason.Error => "error",
30 StreamingUpdateReason.Done => "done",
31 _ => string.Empty
32 };
33
34 internal static StreamingUpdateReason FromSseEventLabel(string label) => label switch
35 {
36 "thread.created" => StreamingUpdateReason.ThreadCreated,
37 "thread.run.created" => StreamingUpdateReason.RunCreated,
38 "thread.run.queued" => StreamingUpdateReason.RunQueued,
39 "thread.run.in_progress" => StreamingUpdateReason.RunInProgress,
40 "thread.run.requires_action" => StreamingUpdateReason.RunRequiresAction,
41 "thread.run.completed" => StreamingUpdateReason.RunCompleted,
42 "thread.run.incomplete" => StreamingUpdateReason.RunIncomplete,
43 "thread.run.failed" => StreamingUpdateReason.RunFailed,
44 "thread.run.cancelling" => StreamingUpdateReason.RunCancelling,
45 "thread.run.cancelled" => StreamingUpdateReason.RunCancelled,
46 "thread.run.expired" => StreamingUpdateReason.RunExpired,
47 "thread.run.step.created" => StreamingUpdateReason.RunStepCreated,
48 "thread.run.step.in_progress" => StreamingUpdateReason.RunStepInProgress,
49 "thread.run.step.delta" => StreamingUpdateReason.RunStepUpdated,
50 "thread.run.step.completed" => StreamingUpdateReason.RunStepCompleted,
51 "thread.run.step.failed" => StreamingUpdateReason.RunStepFailed,
52 "thread.run.step.cancelled" => StreamingUpdateReason.RunStepCancelled,
53 "thread.run.step.expired" => StreamingUpdateReason.RunStepExpired,
54 "thread.message.created" => StreamingUpdateReason.MessageCreated,
55 "thread.message.in_progress" => StreamingUpdateReason.MessageInProgress,
56 "thread.message.delta" => StreamingUpdateReason.MessageUpdated,
57 "thread.message.completed" => StreamingUpdateReason.MessageCompleted,
58 "thread.message.incomplete" => StreamingUpdateReason.MessageFailed,
59 "error" => StreamingUpdateReason.Error,
60 "done" => StreamingUpdateReason.Done,
61 _ => StreamingUpdateReason.Unknown,
62 };
63}