Skip to content

Commit

Permalink
Update documentation #121
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva committed Oct 16, 2023
1 parent d9eabc0 commit 2478d6b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/ChatGptNet/ChatGptClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<ChatGptResponse> AskAsync(Guid conversationId, string message,
var messages = await CreateMessageListAsync(conversationId, message, cancellationToken);
var request = CreateChatGptRequest(messages, functionParameters, false, parameters, model);

var requestUri = options.ServiceConfiguration.GetServiceEndpoint(model ?? options.DefaultModel);
var requestUri = options.ServiceConfiguration.GetChatCompletionEndpoint(model ?? options.DefaultModel);
using var httpResponse = await httpClient.PostAsJsonAsync(requestUri, request, jsonSerializerOptions, cancellationToken);

var response = await httpResponse.Content.ReadFromJsonAsync<ChatGptResponse>(jsonSerializerOptions, cancellationToken: cancellationToken);
Expand Down Expand Up @@ -97,7 +97,7 @@ public async IAsyncEnumerable<ChatGptResponse> AskStreamAsync(Guid conversationI
var messages = await CreateMessageListAsync(conversationId, message, cancellationToken);
var request = CreateChatGptRequest(messages, null, true, parameters, model);

var requestUri = options.ServiceConfiguration.GetServiceEndpoint(model ?? options.DefaultModel);
var requestUri = options.ServiceConfiguration.GetChatCompletionEndpoint(model ?? options.DefaultModel);
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri)
{
Content = new StringContent(JsonSerializer.Serialize(request, jsonSerializerOptions), Encoding.UTF8, MediaTypeNames.Application.Json)
Expand Down Expand Up @@ -294,7 +294,7 @@ public async Task<EmbeddingResponse> GenerateEmbeddingAsync(IEnumerable<string>

var request = CreateEmbeddingRequest(messages, model);

var requestUri = options.ServiceConfiguration.GetEmbeddingsEndpoint(model ?? options.DefaultEmbeddingModel);
var requestUri = options.ServiceConfiguration.GetEmbeddingEndpoint(model ?? options.DefaultEmbeddingModel);
using var httpResponse = await httpClient.PostAsJsonAsync(requestUri, request, jsonSerializerOptions, cancellationToken);

var response = await httpResponse.Content.ReadFromJsonAsync<EmbeddingResponse>(jsonSerializerOptions, cancellationToken: cancellationToken);
Expand Down
26 changes: 13 additions & 13 deletions src/ChatGptNet/IChatGptClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Task<Guid> SetupAsync(string message, CancellationToken cancellationToken = defa
/// </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="model">The chat completion model to use. If <paramref name="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 @@ -57,7 +57,7 @@ Task<ChatGptResponse> AskAsync(string message, ChatGptParameters? parameters = n
/// <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="model">The chat completion model to use. If <paramref name="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 @@ -81,7 +81,7 @@ Task<ChatGptResponse> AskAsync(string message, ChatGptFunctionParameters? functi
/// <param name="conversationId">The unique identifier of the conversation, used to automatically retrieve previous messages in the chat history.</param>
/// <param name="message">The message.</param>
/// <param name="parameters">A <seealso 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="model">The chat completion model to use. If <paramref name="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 @@ -100,7 +100,7 @@ Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptParam
/// <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 <seealso 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="model">The chat completion model to use. If <paramref name="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 @@ -120,7 +120,7 @@ Task<ChatGptResponse> AskAsync(Guid conversationId, string message, ChatGptParam
/// </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="model">The chat completion model to use. If <paramref name="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 @@ -142,7 +142,7 @@ IAsyncEnumerable<ChatGptResponse> AskStreamAsync(string message, ChatGptParamete
/// <param name="conversationId">The unique identifier of the conversation, used to automatically retrieve previous messages in the chat history.</param>
/// <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="model">The chat completion model to use. If <paramref name="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 Down Expand Up @@ -205,7 +205,7 @@ Task<Guid> LoadConversationAsync(IEnumerable<ChatGptMessage> messages, Cancellat
Task<Guid> LoadConversationAsync(Guid conversationId, IEnumerable<ChatGptMessage> messages, bool replaceHistory = true, CancellationToken cancellationToken = default);

/// <summary>
/// Determines if a chat conversation exists.
/// Checks if a chat conversation exists.
/// </summary>
/// <param name="conversationId">The unique identifier of the conversation.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
Expand Down Expand Up @@ -238,21 +238,21 @@ Task<Guid> LoadConversationAsync(IEnumerable<ChatGptMessage> messages, Cancellat
Task AddFunctionResponseAsync(Guid conversationId, string functionName, string content, CancellationToken cancellationToken = default);

/// <summary>
/// Creates embeddings for a message.
/// Generates embeddings for a message.
/// </summary>
/// <param name="message">The message to use for creating embeddings.</param>
/// <param name="model">The name of the embedding model. If not provided, the default model will be used.</param>
/// <param name="message">The message to use for generating embeddings.</param>
/// <param name="model">The name of the embedding model. If <paramref name="model"/> is <see langword="null"/>, then the one specified in the <see cref="ChatGptOptions.DefaultEmbeddingModel"/> property will be used.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The embeddings for the provided message.</returns>
/// <exception cref="EmbeddingException">An error occurred while calling the API and the <see cref="ChatGptOptions.ThrowExceptionOnError"/> is <see langword="true"/>.</exception>
Task<EmbeddingResponse> GenerateEmbeddingAsync(string message, string? model = null, CancellationToken cancellationToken = default)
=> GenerateEmbeddingAsync(new[] { message }, model, cancellationToken);

/// <summary>
/// Creates embeddings for a list of messages.
/// Generates embeddings for a list of messages.
/// </summary>
/// <param name="messages">The messages to use for creating embeddings.</param>
/// <param name="model">The name of the embedding model. If not provided, the default model will be used.</param>
/// <param name="messages">The messages to use for generating embeddings.</param>
/// <param name="model">The name of the embedding model. If <paramref name="model"/> is <see langword="null"/>, then the one specified in the <see cref="ChatGptOptions.DefaultEmbeddingModel"/> property will be used.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The embeddings for the provided messages.</returns>
/// <exception cref="EmbeddingException">An error occurred while calling the API and the <see cref="ChatGptOptions.ThrowExceptionOnError"/> is <see langword="true"/>.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public AzureChatGptServiceConfiguration(IConfiguration configuration)
}

/// <inheritdoc />
public override Uri GetServiceEndpoint(string? modelName)
public override Uri GetChatCompletionEndpoint(string? modelName)
{
ArgumentNullException.ThrowIfNull(nameof(modelName));

Expand All @@ -85,7 +85,7 @@ public override Uri GetServiceEndpoint(string? modelName)
}

/// <inheritdoc />
public override Uri GetEmbeddingsEndpoint(string? modelName = null)
public override Uri GetEmbeddingEndpoint(string? modelName = null)
{
ArgumentNullException.ThrowIfNull(nameof(modelName));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ internal abstract class ChatGptServiceConfiguration
/// Returns the <see cref="Uri"/> that provides chat completion responses.
/// </summary>
/// <param name="modelName">The name of the model for chat completion.</param>
/// <returns>The <see cref="Uri"/> of the service.</returns>
public abstract Uri GetServiceEndpoint(string? modelName = null);
/// <returns>The <see cref="Uri"/> for chat completion.</returns>
public abstract Uri GetChatCompletionEndpoint(string? modelName = null);

/// <summary>
/// Returns the <see cref="Uri"/> that creates embeddings.
/// Returns the <see cref="Uri"/> that generates embeddings.
/// </summary>
/// <param name="modelName">The name of the model for embeddings.</param>
/// <returns>The <see cref="Uri"/> of the service.</returns>
public abstract Uri GetEmbeddingsEndpoint(string? modelName = null);
/// <returns>The <see cref="Uri"/> for generating embeddings.</returns>
public abstract Uri GetEmbeddingEndpoint(string? modelName = null);

/// <summary>
/// Returns the headers that are required by the service to complete the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public OpenAIChatGptServiceConfiguration(IConfiguration configuration)
}

/// <inheritdoc />
public override Uri GetServiceEndpoint(string? _) => new("https://api.openai.com/v1/chat/completions");
public override Uri GetChatCompletionEndpoint(string? _) => new("https://api.openai.com/v1/chat/completions");

/// <inheritdoc />
public override Uri GetEmbeddingsEndpoint(string? _) => new("https://api.openai.com/v1/embeddings");
public override Uri GetEmbeddingEndpoint(string? _) => new("https://api.openai.com/v1/embeddings");

/// <inheritdoc />
public override IDictionary<string, string?> GetRequestHeaders()
Expand Down

0 comments on commit 2478d6b

Please sign in to comment.