Skip to content

Commit

Permalink
safe apis: include content of the request
Browse files Browse the repository at this point in the history
  • Loading branch information
lofcz committed Nov 22, 2024
1 parent bf9d18d commit f56e02e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LlmTornado/Chat/ChatEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ await handler.HttpExceptionHandler(new HttpFailedRequest
Exception = tornadoStreamRequest.Exception,
Result = tornadoStreamRequest.CallResponse,
Request = tornadoStreamRequest.CallRequest,
RawMessage = tornadoStreamRequest.Response
RawMessage = tornadoStreamRequest.Response ?? new HttpResponseMessage()
});

await tornadoStreamRequest.DisposeAsync();
Expand Down
18 changes: 18 additions & 0 deletions LlmTornado/Common/HttpCallResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;

namespace LlmTornado.Common;

Expand Down Expand Up @@ -33,9 +34,26 @@ public interface IHttpCallResult
/// </summary>
public class HttpCallRequest
{
/// <summary>
/// URL of the request.
/// </summary>
public string Url { get; set; }

/// <summary>
/// Method used to perform the request.
/// </summary>
public HttpMethod Method { get; set; }

/// <summary>
/// Outbound headers.
/// </summary>
public Dictionary<string, IEnumerable<string>> Headers { get; set; } = [];

/// <summary>
/// Content of the request.
/// </summary>
[JsonIgnore]
public HttpContent? Content { get; set; }
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion LlmTornado/Common/RestDataOrException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal void ParseRawRequest(HttpRequestMessage httpRequest)
{
Method = httpRequest.Method,
Url = httpRequest.RequestUri?.AbsoluteUri ?? string.Empty,
Headers = httpRequest.Headers.ToDictionary()
Headers = httpRequest.Headers.ToDictionary(),
Content = httpRequest.Content
};
}

Expand Down
13 changes: 12 additions & 1 deletion LlmTornado/EndpointBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ private async Task<HttpResponseMessage> HttpRequestRaw(IEndpointProvider provide
{
Method = req.Method,
Url = req.RequestUri?.AbsolutePath ?? string.Empty,
Headers = req.Headers.ToDictionary()
Headers = req.Headers.ToDictionary(),
Content = req.Content
};

throw response.StatusCode switch
Expand Down Expand Up @@ -588,6 +589,16 @@ protected async IAsyncEnumerable<T> HttpStreamingRequest<T>(IEndpointProvider pr
}
}

/// <summary>
/// Gets data as a series of server sent events (SSE).
/// </summary>
/// <param name="provider"></param>
/// <param name="endpoint"></param>
/// <param name="url"></param>
/// <param name="verb"></param>
/// <param name="postData"></param>
/// <param name="token"></param>
/// <returns></returns>
protected async Task<TornadoStreamRequest> HttpStreamingRequestData(IEndpointProvider provider, CapabilityEndpoints endpoint, string? url = null, HttpMethod? verb = null, object? postData = null, CancellationToken token = default)
{
RestDataOrException<HttpResponseMessage> response = await HttpRequestRawWithAllCodes(provider, endpoint, url, verb, postData, true, token).ConfigureAwait(ConfigureAwaitOptions.None);
Expand Down
4 changes: 2 additions & 2 deletions LlmTornado/LlmTornado.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<RepositoryUrl>https://github.com/lofcz/LlmTornado</RepositoryUrl>
<PackageTags>OpenAI, Cohere, Anthropic, Azure, LLM, GPT-4O, GPT-4, GPT-Turbo, DALL-E, Coral, Claude3, Command-R-Plus</PackageTags>
<Title>OpenAI NextGeneration</Title>
<PackageReleaseNotes>openai: gpt-4o-2024-11-20</PackageReleaseNotes>
<PackageReleaseNotes>safe apis: include content of the request</PackageReleaseNotes>
<PackageId>LlmTornado</PackageId>
<Version>3.1.24</Version>
<Version>3.1.25</Version>
<AssemblyVersion>3.0.5</AssemblyVersion>
<FileVersion>3.0.5</FileVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down

0 comments on commit f56e02e

Please sign in to comment.