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
/// Creates an ongoing chat which can easily encapsulate the conversation. This is the simplest way to use the Chat endpoint.
34
34
/// </summary>
35
+
/// <param name="defaultChatRequestArgs">Allows setting the parameters to use when calling the ChatGPT API. Can be useful for setting temperature, presence_penalty, and more. See <see href="https://platform.openai.com/docs/api-reference/chat/create">OpenAI documentation for a list of possible parameters to tweak.</see></param>
Copy file name to clipboardExpand all lines: OpenAI_API/Chat/Conversation.cs
+29-4Lines changed: 29 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ public OpenAI_API.Models.Model Model
49
49
/// </summary>
50
50
/// <param name="endpoint">A reference to the API endpoint, needed for API requests. Generally should be <see cref="OpenAIAPI.Chat"/>.</param>
51
51
/// <param name="model">Optionally specify the model to use for ChatGPT requests. If not specified, used <paramref name="defaultChatRequestArgs"/>.Model or falls back to <see cref="OpenAI_API.Models.Model.ChatGPTTurbo"/></param>
52
-
/// <param name="defaultChatRequestArgs">Allows setting the parameters to use when calling the ChatGPT API. Can be useful for setting temperature, presence_penalty, and more. <see href="https://platform.openai.com/docs/api-reference/chat/create">Se OpenAI documentation for a list of possible parameters to tweak.</see></param>
52
+
/// <param name="defaultChatRequestArgs">Allows setting the parameters to use when calling the ChatGPT API. Can be useful for setting temperature, presence_penalty, and more. See <see href="https://platform.openai.com/docs/api-reference/chat/create">OpenAI documentation for a list of possible parameters to tweak.</see></param>
/// Calls the API to get a response, which is appended to the current chat's <see cref="Messages"/> as an <see cref="ChatMessageRole.Assistant"/> <see cref="ChatMessage"/>.
107
109
/// </summary>
@@ -117,12 +119,16 @@ public async Task<string> GetResponseFromChatbot()
117
119
if(res.Choices.Count>0)
118
120
{
119
121
varnewMsg=res.Choices[0].Message;
120
-
AppendMessage(res.Choices[0].Message);
121
-
returnres.Choices[0].Message.Content;
122
+
AppendMessage(newMsg);
123
+
returnnewMsg.Content;
122
124
}
123
125
returnnull;
124
126
}
125
127
128
+
#endregion
129
+
130
+
#region Streaming
131
+
126
132
/// <summary>
127
133
/// Calls the API to get a response, which is appended to the current chat's <see cref="Messages"/> as an <see cref="ChatMessageRole.Assistant"/> <see cref="ChatMessage"/>, and streams the results to the <paramref name="resultHandler"/> as they come in. <br/>
128
134
/// If you are on the latest C# supporting async enumerables, you may prefer the cleaner syntax of <see cref="StreamResponseEnumerableFromChatbotAsync"/> instead.
@@ -136,6 +142,20 @@ public async Task StreamResponseFromChatbotAsync(Action<string> resultHandler)
136
142
}
137
143
}
138
144
145
+
/// <summary>
146
+
/// Calls the API to get a response, which is appended to the current chat's <see cref="Messages"/> as an <see cref="ChatMessageRole.Assistant"/> <see cref="ChatMessage"/>, and streams the results to the <paramref name="resultHandler"/> as they come in. <br/>
147
+
/// If you are on the latest C# supporting async enumerables, you may prefer the cleaner syntax of <see cref="StreamResponseEnumerableFromChatbotAsync"/> instead.
148
+
/// </summary>
149
+
/// <param name="resultHandler">An action to be called as each new result arrives, which includes the index of the result in the overall result set.</param>
/// Calls the API to get a response, which is appended to the current chat's <see cref="Messages"/> as an <see cref="ChatMessageRole.Assistant"/> <see cref="ChatMessage"/>, and streams the results as they come in. <br/>
141
161
/// If you are not using C# 8 supporting async enumerables or if you are using the .NET Framework, you may need to use <see cref="StreamResponseFromChatbotAsync"/> instead.
@@ -153,7 +173,9 @@ public async IAsyncEnumerable<string> StreamResponseEnumerableFromChatbotAsync()
0 commit comments