Skip to content

Commit

Permalink
Documentation update #100
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva committed Aug 11, 2023
1 parent 010b1da commit 2299cc6
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 10 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,23 @@ var message = response.GetMessage();
The **AskAsync** and **AskStreamAsync** (see below) methods provides overloads that require a *conversationId* parameter. If we pass an empty value, a random one is generated and returned.
We can pass this value in subsequent invocations of **AskAsync** or **AskStreamAsync**, so that the library automatically retrieves previous messages of the current conversation (according to *MessageLimit* and *MessageExpiration* settings) and send them to chat completion API.

This is the default behavior for all the chat interactions. If you want to exlude a particular interaction from the conversation history, you can set the *addToChatHistory* argument to *false*:
This is the default behavior for all the chat interactions. If you want to exlude a particular interaction from the conversation history, you can set the *addToConversationHistory* argument to *false*:

```csharp
var response = await chatGptClient.AskAsync(conversationId, message, addToChatHistory: false);
var response = await chatGptClient.AskAsync(conversationId, message, addToConversationHistory: false);
```

In this way, the message will be sent to the chat completion API, but it and the corresponding answer from ChatGPT will not be added to the conversation history.

On the other hand, in some scenarios, it could be useful to manually add a chat interaction (i.e., a question followed by an answer) to the conversation history. For example, we may want to add a message that was generated by a bot. In this case, we can use the **AddInteractionAsync** method:

```csharp
await chatGptClient.AskInteractionAsync(conversationId, question: "What is the weather like in Taggia?",
answer: "It's Always Sunny in Taggia");
```

The question will be added as *user* message and the answer will be added as *assistant* message in the conversation history. As always, these new messages (respecting the *MessageLimit* option) will be used in subsequent invocations of **AskAsync** or **AskStreamAsync**.

### Response streaming

Chat completion API supports response streaming. When using this feature, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available. **ChatGptNet** provides response streaming using the **AskStreamAsync** method:
Expand Down
4 changes: 4 additions & 0 deletions docs/ChatGptNet.Models/ChatGptResponse/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Gets or sets information about token usage.
public ChatGptUsage? Usage { get; set; }
```

## Remarks

The `Usage` property is always `null` when requesting response streaming with CancellationToken).

## See Also

* class [ChatGptUsage](../ChatGptUsage.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/ChatGptNet/IChatGptCache/GetAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Gets the list of messages for the given *conversationId*.

```csharp
public Task<List<ChatGptMessage>?> GetAsync(Guid conversationId,
public Task<IEnumerable<ChatGptMessage>?> GetAsync(Guid conversationId,
CancellationToken cancellationToken = default)
```

Expand Down
1 change: 1 addition & 0 deletions docs/ChatGptNet/IChatGptClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IChatGptClient
| name | description |
| --- | --- |
| [AddFunctionResponseAsync](IChatGptClient/AddFunctionResponseAsync.md)(…) | Adds a function response to the conversation history. |
| [AddInteractionAsync](IChatGptClient/AddInteractionAsync.md)(…) | Explicitly adds a new interaction (a question and the corresponding answer) to the conversation history. |
| [AskAsync](IChatGptClient/AskAsync.md)(…) | Requests a new chat interaction using the default completion model specified in the [`DefaultModel`](./ChatGptOptions/DefaultModel.md) property. (4 methods) |
| [AskStreamAsync](IChatGptClient/AskStreamAsync.md)(…) | Requests a new chat interaction (using the default completion model specified in the [`DefaultModel`](./ChatGptOptions/DefaultModel.md) property) with streaming response, like in ChatGPT. (2 methods) |
| [ConversationExistsAsync](IChatGptClient/ConversationExistsAsync.md)(…) | Determines if a chat conversation exists. |
Expand Down
1 change: 1 addition & 0 deletions docs/ChatGptNet/IChatGptClient/AddFunctionResponseAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The Task corresponding to the asynchronous operation.
## See Also

* method [AskAsync](./AskAsync.md)
* method [AskStreamAsync](./AskStreamAsync.md)
* class [ChatGptFunctionCall](../../ChatGptNet.Models/ChatGptFunctionCall.md)
* interface [IChatGptClient](../IChatGptClient.md)
* namespace [ChatGptNet](../../ChatGptNet.md)
Expand Down
32 changes: 32 additions & 0 deletions docs/ChatGptNet/IChatGptClient/AddInteractionAsync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# IChatGptClient.AddInteractionAsync method

Explicitly adds a new interaction (a question and the corresponding answer) to the conversation history.

```csharp
public Task AddInteractionAsync(Guid conversationId, string question, string answer,
CancellationToken cancellationToken = default)
```

| parameter | description |
| --- | --- |
| conversationId | The unique identifier of the conversation. |
| question | The question. |
| answer | The answer. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value

The Task corresponding to the asynchronous operation.

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | *question* or *answer* are `null`. |

## See Also

* interface [IChatGptClient](../IChatGptClient.md)
* namespace [ChatGptNet](../../ChatGptNet.md)

<!-- DO NOT EDIT: generated by xmldocmd for ChatGptNet.dll -->
13 changes: 9 additions & 4 deletions docs/ChatGptNet/IChatGptClient/AskAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Requests a new chat interaction using the default completion model specified in

```csharp
public Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = null,
CancellationToken cancellationToken = default)
bool addToConversationHistory = true, CancellationToken cancellationToken = default)
```

| parameter | description |
| --- | --- |
| message | The message. |
| parameters | A [`ChatGptParameters`](../../ChatGptNet.Models/ChatGptParameters.md) object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down Expand Up @@ -45,14 +46,15 @@ Requests a new chat interaction using the default completion model specified in
```csharp
public Task<ChatGptResponse> AskAsync(string message,
ChatGptFunctionParameters? functionParameters, ChatGptParameters? parameters = null,
CancellationToken cancellationToken = default)
bool addToConversationHistory = true, CancellationToken cancellationToken = default)
```

| parameter | description |
| --- | --- |
| message | The message. |
| functionParameters | A [`ChatGptFunctionParameters`](../../ChatGptNet.Models/ChatGptFunctionParameters.md) object that contains the list of available functions for calling. |
| parameters | A [`ChatGptParameters`](../../ChatGptNet.Models/ChatGptParameters.md) object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down Expand Up @@ -90,7 +92,7 @@ Requests a chat interaction.
```csharp
public Task<ChatGptResponse> AskAsync(Guid conversationId, string message,
ChatGptParameters? parameters = null, string? model = null,
CancellationToken cancellationToken = default)
bool addToConversationHistory = true, CancellationToken cancellationToken = default)
```

| parameter | description |
Expand All @@ -99,6 +101,7 @@ public Task<ChatGptResponse> AskAsync(Guid conversationId, string message,
| message | The message. |
| parameters | A object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| model | The chat completion model to use. If model is `null`, then the one specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property will be used. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down Expand Up @@ -128,7 +131,8 @@ Requests a chat interaction.
```csharp
public Task<ChatGptResponse> AskAsync(Guid conversationId, string message,
ChatGptFunctionParameters? functionParameters, ChatGptParameters? parameters = null,
string? model = null, CancellationToken cancellationToken = default)
string? model = null, bool addToConversationHistory = true,
CancellationToken cancellationToken = default)
```

| parameter | description |
Expand All @@ -138,6 +142,7 @@ public Task<ChatGptResponse> AskAsync(Guid conversationId, string message,
| functionParameters | A [`ChatGptFunctionParameters`](../../ChatGptNet.Models/ChatGptFunctionParameters.md) object that contains the list of available functions for calling. |
| parameters | A object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| model | The chat completion model to use. If model is `null`, then the one specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property will be used. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down
7 changes: 5 additions & 2 deletions docs/ChatGptNet/IChatGptClient/AskStreamAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Requests a new chat interaction (using the default completion model specified in

```csharp
public IAsyncEnumerable<ChatGptResponse> AskStreamAsync(string message,
ChatGptParameters? parameters = null, CancellationToken cancellationToken = default)
ChatGptParameters? parameters = null, bool addToConversationHistory = true,
CancellationToken cancellationToken = default)
```

| parameter | description |
| --- | --- |
| message | The message. |
| parameters | A [`ChatGptParameters`](../../ChatGptNet.Models/ChatGptParameters.md) object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down Expand Up @@ -44,7 +46,7 @@ Requests a chat interaction with streaming response, like in ChatGPT.
```csharp
public IAsyncEnumerable<ChatGptResponse> AskStreamAsync(Guid conversationId, string message,
ChatGptParameters? parameters = null, string? model = null,
CancellationToken cancellationToken = default)
bool addToConversationHistory = true, CancellationToken cancellationToken = default)
```

| parameter | description |
Expand All @@ -53,6 +55,7 @@ public IAsyncEnumerable<ChatGptResponse> AskStreamAsync(Guid conversationId, str
| message | The message. |
| parameters | A [`ChatGptParameters`](../../ChatGptNet.Models/ChatGptParameters.md) object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| model | The chat completion model to use. If model is `null`, then the one specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property will be used. |
| addToConversationHistory | Set to `true` to add the current chat interaction to the conversation history. |
| cancellationToken | The token to monitor for cancellation requests. |

## Return Value
Expand Down
3 changes: 2 additions & 1 deletion docs/ChatGptNet/IChatGptClient/LoadConversationAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ The unique identifier of the new conversation.

## Remarks

This method creates a new conversation with a random Conversation Id. Then, call [`AskAsync`](./AskAsync.md) with this Id to start the actual conversation.
This method creates a new conversation with a random Conversation Id. Then, call [`AskAsync`](./AskAsync.md) or [`AskStreamAsync`](./AskStreamAsync.md) with this Id to start the actual conversation.

The total number of messages never exceeds the message limit defined in [`MessageLimit`](../ChatGptOptions/MessageLimit.md). If *messages* contains more, only the latest ones are loaded.

## See Also

* property [MessageLimit](../ChatGptOptions/MessageLimit.md)
* method [AskAsync](./AskAsync.md)
* method [AskStreamAsync](./AskStreamAsync.md)
* class [ChatGptMessage](../../ChatGptNet.Models/ChatGptMessage.md)
* interface [IChatGptClient](../IChatGptClient.md)
Expand Down

0 comments on commit 2299cc6

Please sign in to comment.