You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: OpenAI_API/Chat/ChatEndpoint.cs
+31-14Lines changed: 31 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
usingOpenAI_API.Models;
2
2
usingSystem;
3
3
usingSystem.Collections.Generic;
4
+
usingSystem.Linq;
4
5
usingSystem.Net.Http;
5
6
usingSystem.Text;
6
7
usingSystem.Threading.Tasks;
@@ -10,8 +11,8 @@ namespace OpenAI_API.Chat
10
11
/// <summary>
11
12
/// ChatGPT API endpoint. Use this endpoint to send multiple messages and carry on a conversation.
12
13
/// </summary>
13
-
publicclassChatEndpoint:EndpointBase
14
-
{
14
+
publicclassChatEndpoint:EndpointBase
15
+
{
15
16
/// <summary>
16
17
/// This allows you to set default parameters for every request, for example to set a default temperature or max tokens. For every request, if you do not have a parameter set on the request but do have it set here as a default, the request will automatically pick up the default value.
17
18
/// </summary>
@@ -28,14 +29,23 @@ public class ChatEndpoint : EndpointBase
28
29
/// <param name="api"></param>
29
30
internalChatEndpoint(OpenAIAPIapi):base(api){}
30
31
32
+
/// <summary>
33
+
/// Creates an ongoing chat which can easily encapsulate the conversation. This is the simplest way to use the Chat endpoint.
/// Ask the API to complete the request using the specified parameters. This is non-streaming, so it will wait until the API returns the full result. Any non-specified parameters will fall back to default values specified in <see cref="DefaultChatRequestArgs"/> if present.
35
45
/// </summary>
36
46
/// <param name="request">The request to send to the API.</param>
37
47
/// <returns>Asynchronously returns the completion result. Look in its <see cref="ChatResult.Choices"/> property for the results.</returns>
@@ -66,15 +76,15 @@ public Task<ChatResult> CreateChatAsync(ChatRequest request, int numOutputs = 5)
66
76
/// <param name="logitBias">Maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.</param>
67
77
/// <param name="stopSequences">One or more sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.</param>
68
78
/// <returns>Asynchronously returns the completion result. Look in its <see cref="ChatResult.Choices"/> property for the results.</returns>
/// Ask the API to complete the request using the specified parameters. This is non-streaming, so it will wait until the API returns the full result. Any non-specified parameters will fall back to default values specified in <see cref="DefaultChatRequestArgs"/> if present.
107
+
/// Ask the API to complete the request using the specified message(s). Any parameters will fall back to default values specified in <see cref="DefaultChatRequestArgs"/> if present.
98
108
/// </summary>
99
109
/// <param name="messages">The messages to use in the generation.</param>
/// Ask the API to complete the request using the specified message(s). Any parameters will fall back to default values specified in <see cref="DefaultChatRequestArgs"/> if present.
122
+
/// </summary>
123
+
/// <param name="userMessages">The user message or messages to use in the generation. All strings are assumed to be of Role <see cref="ChatMessageRole.User"/></param>
124
+
/// <returns>The <see cref="ChatResult"/> with the API response.</returns>
@@ -168,15 +185,15 @@ public IAsyncEnumerable<ChatResult> StreamChatEnumerableAsync(ChatRequest reques
168
185
/// <param name="logitBias">Maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.</param>
169
186
/// <param name="stopSequences">One or more sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.</param>
170
187
/// <returns>An async enumerable with each of the results as they come in. See <see href="https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#asynchronous-streams">the C# docs</see> for more details on how to consume an async enumerable.</returns>
/// Represents the Role of a <see cref="ChatMessage"/>. Typically, a conversation is formatted with a system message first, followed by alternating user and assistant messages. See <see href="https://platform.openai.com/docs/guides/chat/introduction">the OpenAI docs</see> for more details about usage.
/// Gets the string value for this role to pass to the API
57
+
/// </summary>
58
+
/// <returns>The size as a string</returns>
59
+
publicoverridestringToString()
60
+
{
61
+
returnValue;
62
+
}
63
+
64
+
/// <summary>
65
+
/// Determines whether this instance and a specified object have the same value.
66
+
/// </summary>
67
+
/// <param name="obj">The ChatMessageRole to compare to this instance</param>
68
+
/// <returns>true if obj is a ChatMessageRole and its value is the same as this instance; otherwise, false. If obj is null, the method returns false</returns>
69
+
publicoverrideboolEquals(objectobj)
70
+
{
71
+
returnValue.Equals((objasChatMessageRole).Value);
72
+
}
73
+
74
+
/// <summary>
75
+
/// Returns the hash code for this object
76
+
/// </summary>
77
+
/// <returns>A 32-bit signed integer hash code</returns>
78
+
publicoverrideintGetHashCode()
79
+
{
80
+
returnValue.GetHashCode();
81
+
}
82
+
83
+
/// <summary>
84
+
/// Determines whether this instance and a specified object have the same value.
85
+
/// </summary>
86
+
/// <param name="other">The ChatMessageRole to compare to this instance</param>
87
+
/// <returns>true if other's value is the same as this instance; otherwise, false. If other is null, the method returns false</returns>
88
+
publicboolEquals(ChatMessageRoleother)
89
+
{
90
+
returnValue.Equals(other.Value);
91
+
}
92
+
93
+
/// <summary>
94
+
/// Gets the string value for this role to pass to the API
95
+
/// </summary>
96
+
/// <param name="value">The ChatMessageRole to convert</param>
Copy file name to clipboardExpand all lines: OpenAI_API/Chat/ChatRequest.cs
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ public class ChatRequest
22
22
/// The messages to send with this Chat Request
23
23
/// </summary>
24
24
[JsonProperty("messages")]
25
-
publicIEnumerable<ChatMessage>Messages{get;set;}
25
+
publicIList<ChatMessage>Messages{get;set;}
26
26
27
27
/// <summary>
28
28
/// What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. It is generally recommend to use this or <see cref="TopP"/> but not both.
@@ -52,7 +52,7 @@ public class ChatRequest
52
52
/// This is only used for serializing the request into JSON, do not use it directly.
53
53
/// </summary>
54
54
[JsonProperty("stop")]
55
-
publicobjectCompiledStop
55
+
internalobjectCompiledStop
56
56
{
57
57
get
58
58
{
@@ -109,9 +109,9 @@ public string StopSequence
109
109
/// Accepts a json object that maps tokens(specified by their token ID in the tokenizer) to an associated bias value from -100 to 100.
110
110
/// Mathematically, the bias is added to the logits generated by the model prior to sampling.
111
111
/// The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
0 commit comments