Skip to content

Commit

Permalink
Add missing overloads (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva authored Sep 7, 2023
2 parents fefcecb + dac6251 commit 1ade3f7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ Check out the [Function calling sample](https://github.com/marcominerva/ChatGptN

When using Azure OpenAI Service, we automatically get content filtering for free. For details about how it works, check out the [documentation](https://learn.microsoft.com/azure/ai-services/openai/concepts/content-filter). This information is returned for all scenarios when using API version `2023-06-01-preview` or later. **ChatGptNet** fully supports this object model by providing the corresponding properties in the [ChatGptResponse](https://github.com/marcominerva/ChatGptNet/blob/master/src/ChatGptNet/Models/ChatGptResponse.cs#L57) and [ChatGptChoice](https://github.com/marcominerva/ChatGptNet/blob/master/src/ChatGptNet/Models/ChatGptChoice.cs#L26) classes.

## Documentation

The full technical documentation is available [here](https://github.com/marcominerva/ChatGptNet/tree/master/docs).

## Contribute

The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.
Expand Down
4 changes: 2 additions & 2 deletions docs/ChatGptNet/IChatGptClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public interface IChatGptClient
| --- | --- |
| [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) |
| [AskAsync](IChatGptClient/AskAsync.md)(…) | Requests a new chat interaction. (4 methods) |
| [AskStreamAsync](IChatGptClient/AskStreamAsync.md)(…) | Requests a new chat interaction with streaming response, like in ChatGPT. (2 methods) |
| [ConversationExistsAsync](IChatGptClient/ConversationExistsAsync.md)(…) | Determines if a chat conversation exists. |
| [DeleteConversationAsync](IChatGptClient/DeleteConversationAsync.md)(…) | Deletes a chat conversation, clearing all the history. |
| [GetConversationAsync](IChatGptClient/GetConversationAsync.md)(…) | Retrieves a chat conversation from the cache. |
Expand Down
46 changes: 25 additions & 21 deletions docs/ChatGptNet/IChatGptClient/AskAsync.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# IChatGptClient.AskAsync method (1 of 4)

Requests a new chat interaction using the default completion model specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property.
Requests a new chat interaction.

```csharp
public Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = null,
bool addToConversationHistory = true, CancellationToken cancellationToken = default)
string? model = 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. |
| 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. |

Expand Down Expand Up @@ -41,19 +43,20 @@ This method automatically starts a new conservation with a random Conversation I

# IChatGptClient.AskAsync method (2 of 4)

Requests a new chat interaction using the default completion model specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property.
Requests a chat interaction.

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

| parameter | description |
| --- | --- |
| conversationId | The unique identifier of the conversation, used to automatically retrieve previous messages in the chat history. |
| 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. |
| 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. |

Expand All @@ -68,17 +71,9 @@ The chat completion response.
| ArgumentNullException | *message* is `null`. |
| [ChatGptException](../../ChatGptNet.Exceptions/ChatGptException.md) | An error occurred while calling the API and the [`ThrowExceptionOnError`](../ChatGptOptions/ThrowExceptionOnError.md) is `true`. |

## Remarks

This method automatically starts a new conservation with a random Conversation Id, that will be returned in the [`ChatGptResponse`](../../ChatGptNet.Models/ChatGptResponse.md). Subsequent calls to this method must provide the same [`ConversationId`](../../ChatGptNet.Models/ChatGptResponse/ConversationId.md) value, so that previous messages will be automatically used to continue the conversation.

The Chat Completions API does not call the function; instead, the model generates JSON that you can use to call the function in your code.

## See Also

* class [ChatGptResponse](../../ChatGptNet.Models/ChatGptResponse.md)
* class [ChatGptOptions](../ChatGptOptions.md)
* class [ChatGptFunctionParameters](../../ChatGptNet.Models/ChatGptFunctionParameters.md)
* class [ChatGptParameters](../../ChatGptNet.Models/ChatGptParameters.md)
* interface [IChatGptClient](../IChatGptClient.md)
* namespace [ChatGptNet](../../ChatGptNet.md)
Expand All @@ -87,19 +82,20 @@ The Chat Completions API does not call the function; instead, the model generate

# IChatGptClient.AskAsync method (3 of 4)

Requests a chat interaction.
Requests a new chat interaction.

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

| parameter | description |
| --- | --- |
| conversationId | The unique identifier of the conversation, used to automatically retrieve previous messages in the chat history. |
| message | The message. |
| parameters | A object used to override the default completion parameters in the [`DefaultParameters`](../ChatGptOptions/DefaultParameters.md) property. |
| 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. |
| 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. |
Expand All @@ -115,9 +111,17 @@ The chat completion response.
| ArgumentNullException | *message* is `null`. |
| [ChatGptException](../../ChatGptNet.Exceptions/ChatGptException.md) | An error occurred while calling the API and the [`ThrowExceptionOnError`](../ChatGptOptions/ThrowExceptionOnError.md) is `true`. |

## Remarks

This method automatically starts a new conservation with a random Conversation Id, that will be returned in the [`ChatGptResponse`](../../ChatGptNet.Models/ChatGptResponse.md). Subsequent calls to this method must provide the same [`ConversationId`](../../ChatGptNet.Models/ChatGptResponse/ConversationId.md) value, so that previous messages will be automatically used to continue the conversation.

The Chat Completions API does not call the function; instead, the model generates JSON that you can use to call the function in your code.

## See Also

* class [ChatGptResponse](../../ChatGptNet.Models/ChatGptResponse.md)
* class [ChatGptOptions](../ChatGptOptions.md)
* class [ChatGptFunctionParameters](../../ChatGptNet.Models/ChatGptFunctionParameters.md)
* class [ChatGptParameters](../../ChatGptNet.Models/ChatGptParameters.md)
* interface [IChatGptClient](../IChatGptClient.md)
* namespace [ChatGptNet](../../ChatGptNet.md)
Expand Down
7 changes: 4 additions & 3 deletions docs/ChatGptNet/IChatGptClient/AskStreamAsync.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# IChatGptClient.AskStreamAsync method (1 of 2)

Requests a new chat interaction (using the default completion model specified in the [`DefaultModel`](../ChatGptOptions/DefaultModel.md) property) with streaming response, like in ChatGPT.
Requests a new chat interaction with streaming response, like in ChatGPT.

```csharp
public IAsyncEnumerable<ChatGptResponse> AskStreamAsync(string message,
ChatGptParameters? parameters = null, bool addToConversationHistory = true,
CancellationToken cancellationToken = default)
ChatGptParameters? parameters = null, string? model = 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. |
| 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. |

Expand Down
2 changes: 1 addition & 1 deletion src/ChatGptNet/ChatGptClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private async Task<IList<ChatGptMessage>> CreateMessageListAsync(Guid conversati
return messages;
}

private ChatGptRequest CreateRequest(IEnumerable<ChatGptMessage> messages, ChatGptFunctionParameters? functionParameters, bool stream, ChatGptParameters? parameters = null, string? model = null)
private ChatGptRequest CreateRequest(IEnumerable<ChatGptMessage> messages, ChatGptFunctionParameters? functionParameters, bool stream, ChatGptParameters? parameters, string? model)
=> new()
{
Model = model ?? options.DefaultModel,
Expand Down
23 changes: 13 additions & 10 deletions src/ChatGptNet/IChatGptClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ Task<Guid> SetupAsync(string message, CancellationToken cancellationToken = defa
Task<Guid> SetupAsync(Guid conversationId, string message, CancellationToken cancellationToken = default);

/// <summary>
/// Requests a new chat interaction using the default completion model specified in the <see cref="ChatGptOptions.DefaultModel"/> property.
/// Requests a new chat interaction.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="parameters">A <see cref="ChatGptParameters"/> object used to override the default completion parameters in the <see cref="ChatGptOptions.DefaultParameters"/> property.</param>
/// <param name="model">The chat completion model to use. If model is <see langword="null"/>, then the one specified in the <see cref="ChatGptOptions.DefaultModel"/> property will be used.</param>
/// <param name="addToConversationHistory">Set to <see langword="true"/> to add the current chat interaction to the conversation history.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The chat completion response.</returns>
Expand All @@ -46,15 +47,16 @@ Task<Guid> SetupAsync(string message, CancellationToken cancellationToken = defa
/// <seealso cref="ChatGptResponse"/>
/// <seealso cref="ChatGptOptions"/>
/// <seealso cref="ChatGptParameters"/>
Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskAsync(Guid.NewGuid(), message, null, parameters, null, addToConversationHistory, cancellationToken);
Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = null, string? model = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskAsync(Guid.NewGuid(), message, null, parameters, model, addToConversationHistory, cancellationToken);

/// <summary>
/// Requests a new chat interaction using the default completion model specified in the <see cref="ChatGptOptions.DefaultModel"/> property.
/// Requests a new chat interaction.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="functionParameters">A <see cref="ChatGptFunctionParameters"/> object that contains the list of available functions for calling.</param>
/// <param name="parameters">A <see cref="ChatGptParameters"/> object used to override the default completion parameters in the <see cref="ChatGptOptions.DefaultParameters"/> property.</param>
/// <param name="model">The chat completion model to use. If model is <see langword="null"/>, then the one specified in the <see cref="ChatGptOptions.DefaultModel"/> property will be used.</param>
/// <param name="addToConversationHistory">Set to <see langword="true"/> to add the current chat interaction to the conversation history.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The chat completion response.</returns>
Expand All @@ -69,8 +71,8 @@ Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = n
/// <seealso cref="ChatGptOptions"/>
/// <seealso cref="ChatGptFunctionParameters"/>
/// <seealso cref="ChatGptParameters"/>
Task<ChatGptResponse> AskAsync(string message, ChatGptFunctionParameters? functionParameters, ChatGptParameters? parameters = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskAsync(Guid.NewGuid(), message, functionParameters, parameters, null, addToConversationHistory, cancellationToken);
Task<ChatGptResponse> AskAsync(string message, ChatGptFunctionParameters? functionParameters, ChatGptParameters? parameters = null, string? model = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskAsync(Guid.NewGuid(), message, functionParameters, parameters, model, addToConversationHistory, cancellationToken);

/// <summary>
/// Requests a chat interaction.
Expand All @@ -88,7 +90,7 @@ Task<ChatGptResponse> AskAsync(string message, ChatGptFunctionParameters? functi
/// <seealso cref="ChatGptResponse"/>
/// <seealso cref="ChatGptParameters"/>
Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptParameters? parameters = null, string? model = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default)
=> AskAsync(conversationId, message, null, parameters, null, addToConversationHistory, cancellationToken);
=> AskAsync(conversationId, message, null, parameters, model, addToConversationHistory, cancellationToken);

/// <summary>
/// Requests a chat interaction.
Expand All @@ -113,10 +115,11 @@ Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptParam
Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptFunctionParameters? functionParameters, ChatGptParameters? parameters = null, string? model = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default);

/// <summary>
/// Requests a new chat interaction (using the default completion model specified in the <see cref="ChatGptOptions.DefaultModel"/> property) with streaming response, like in ChatGPT.
/// Requests a new chat interaction with streaming response, like in ChatGPT.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="parameters">A <see cref="ChatGptParameters"/> object used to override the default completion parameters in the <see cref="ChatGptOptions.DefaultParameters"/> property.</param>
/// <param name="model">The chat completion model to use. If model is <see langword="null"/>, then the one specified in the <see cref="ChatGptOptions.DefaultModel"/> property will be used.</param>
/// <param name="addToConversationHistory">Set to <see langword="true"/> to add the current chat interaction to the conversation history.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>An <see cref="IAsyncEnumerable{ChatGptResponse}"/> that allows to enumerate all the streaming responses, each of them containing a partial message delta.</returns>
Expand All @@ -129,8 +132,8 @@ Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptParam
/// <seealso cref="ChatGptRequest"/>
/// <seealso cref="ChatGptResponse"/>
/// <seealso cref="ChatGptParameters"/>
IAsyncEnumerable<ChatGptResponse> AskStreamAsync(string message, ChatGptParameters? parameters = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskStreamAsync(Guid.NewGuid(), message, parameters, null, addToConversationHistory, cancellationToken);
IAsyncEnumerable<ChatGptResponse> AskStreamAsync(string message, ChatGptParameters? parameters = null, string? model = null, bool addToConversationHistory = true, CancellationToken cancellationToken = default) =>
AskStreamAsync(Guid.NewGuid(), message, parameters, model, addToConversationHistory, cancellationToken);

/// <summary>
/// Requests a chat interaction with streaming response, like in ChatGPT.
Expand Down

0 comments on commit 1ade3f7

Please sign in to comment.