Skip to content

Commit

Permalink
feat: Use AutoSDK. Fix issues with OpenAPI spec. Added new tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 26, 2024
1 parent a4d01bb commit 66d71b2
Show file tree
Hide file tree
Showing 217 changed files with 3,637 additions and 1,487 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,37 @@
- Support all DeepInfra API endpoints including Object Detection, Token Classification, Image Classification, Fill Mask and more.

## Usage

To interact with the OpenAI like API, you need to use `tryAGI.OpenAI` library:
```
<PackageReference Include="tryAGI.OpenAI" Version="3.7.0" />
```
```csharp
using var api = new DeepInfraApi("API_KEY");
string response = await api.Chat.CreateChatCompletionAsync(
messages: ["Generate five random words."],
model: CreateChatCompletionRequestModel.Gpt4oMini);
Console.WriteLine(response); // "apple, banana, cherry, date, elderberry"
using OpenAI;

using var client = CustomProviders.DeepInfra(apiKey);
var enumerable = api.Chat.CreateChatCompletionAsStreamAsync(
messages: ["Generate five random words."],
model: CreateChatCompletionRequestModel.Gpt4oMini);
model: "meta-llama/Meta-Llama-3-8B-Instruct",
messages: ["What is the capital of the United States?"]);

await foreach (string response in enumerable)
await foreach (var response in enumerable)
{
Console.WriteLine(response);
Console.Write(response.Choices[0].Delta.Content);
}
```

## Support

Priority place for bugs: https://github.com/tryAGI/DeepInfra/issues
Priority place for ideas and general questions: https://github.com/tryAGI/DeepInfra/discussions
Discord: https://discord.gg/Ca2xhfBf3v
Discord: https://discord.gg/Ca2xhfBf3v

## Acknowledgments

![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png)

This project is supported by JetBrains through the [Open Source Support Program](https://jb.gg/OpenSourceSupport).

![CodeRabbit logo](https://opengraph.githubassets.com/1c51002d7d0bbe0c4fd72ff8f2e58192702f73a7037102f77e4dbb98ac00ea8f/marketplace/coderabbitai)

This project is supported by CodeRabbit through the [Open Source Support Program](https://github.com/marketplace/coderabbitai).
14 changes: 10 additions & 4 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
Expand All @@ -7,16 +8,21 @@
var path = args[0];
var text = await File.ReadAllTextAsync(path);

text = text.Replace("\"exclusiveMaximum\":1000.0", "\"exclusiveMinimum\":false");
text = text.Replace("\"exclusiveMinimum\": 0.0", "\"exclusiveMinimum\": false");
text = text.Replace("\"exclusiveMinimum\":0.0", "\"exclusiveMinimum\":false");
text = text.Replace("\"type\":\"String\"", "\"type\":\"string\"");

// Replace string like this `,"exclusiveMaximum":9.223372036854776e+18` to `,"maximum":9.223372036854776e+18, "exclusiveMaximum":true`
// and this `,"exclusiveMaximum":1000.0` to `,"maximum":1000.0, "exclusiveMaximum":true`
// only maximum
Regex exclusiveMaximumRegex = new(@",\s*""exclusiveMaximum"":(?<value>\d+(\.\d+)?(e\+\d+)?)", RegexOptions.Compiled);
text = exclusiveMaximumRegex.Replace(text, @", ""maximum"":${value}, ""exclusiveMaximum"":true");
Regex exclusiveMinimumRegex = new(@",\s*""exclusiveMinimum"":(?<value>\d+(\.\d+)?(e\+\d+)?)", RegexOptions.Compiled);
text = exclusiveMinimumRegex.Replace(text, @", ""minimum"":${value}, ""exclusiveMinimum"":true");

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);

openApiDocument.Servers.Add(new OpenApiServer
{
Url = "https://api.deepinfra.com/v1/",
Url = "https://api.deepinfra.com/",
});

openApiDocument.Components.SecuritySchemes.Add("Bearer", new OpenApiSecurityScheme
Expand Down
114 changes: 0 additions & 114 deletions src/libs/DeepInfra/Generated/AllOf.1.g.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/libs/DeepInfra/Generated/AnyOf.2.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable enable

namespace System
namespace DeepInfra
{
/// <summary>
///
Expand Down
2 changes: 1 addition & 1 deletion src/libs/DeepInfra/Generated/AnyOf.4.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable enable

namespace System
namespace DeepInfra
{
/// <summary>
///
Expand Down
2 changes: 1 addition & 1 deletion src/libs/DeepInfra/Generated/AnyOf.7.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#nullable enable

namespace System
namespace DeepInfra
{
/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace DeepInfra
{
public partial class DeepInfraApi
{
partial void PrepareAccountEmailValuesV1MeEmailsGetArguments(
partial void PrepareAccountEmailValuesArguments(
global::System.Net.Http.HttpClient httpClient);
partial void PrepareAccountEmailValuesV1MeEmailsGetRequest(
partial void PrepareAccountEmailValuesRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage);
partial void ProcessAccountEmailValuesV1MeEmailsGetResponse(
partial void ProcessAccountEmailValuesResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
partial void ProcessAccountEmailValuesResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);
Expand All @@ -24,22 +24,26 @@ partial void ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::DeepInfra.EmailsOut> AccountEmailValuesV1MeEmailsGetAsync(
public async global::System.Threading.Tasks.Task<global::DeepInfra.EmailsOut> AccountEmailValuesAsync(
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: _httpClient);
PrepareAccountEmailValuesV1MeEmailsGetArguments(
PrepareAccountEmailValuesArguments(
httpClient: _httpClient);

var __pathBuilder = new PathBuilder(
path: "/v1/me/emails",
baseUri: _httpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + "/v1/me/emails", global::System.UriKind.RelativeOrAbsolute));
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));

PrepareRequest(
client: _httpClient,
request: httpRequest);
PrepareAccountEmailValuesV1MeEmailsGetRequest(
PrepareAccountEmailValuesRequest(
httpClient: _httpClient,
httpRequestMessage: httpRequest);

Expand All @@ -51,7 +55,7 @@ partial void ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
ProcessResponse(
client: _httpClient,
response: response);
ProcessAccountEmailValuesV1MeEmailsGetResponse(
ProcessAccountEmailValuesResponse(
httpClient: _httpClient,
httpResponseMessage: response);

Expand All @@ -61,7 +65,7 @@ partial void ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
ProcessAccountEmailValuesResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);
Expand All @@ -76,7 +80,7 @@ partial void ProcessAccountEmailValuesV1MeEmailsGetResponseContent(
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, global::DeepInfra.SourceGenerationContext.Default.EmailsOut) ??
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::DeepInfra.EmailsOut), JsonSerializerContext) as global::DeepInfra.EmailsOut ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace DeepInfra
{
public partial class DeepInfraApi
{
partial void PrepareAccountRateLimitV1MeRateLimitGetArguments(
partial void PrepareAccountRateLimitArguments(
global::System.Net.Http.HttpClient httpClient);
partial void PrepareAccountRateLimitV1MeRateLimitGetRequest(
partial void PrepareAccountRateLimitRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage);
partial void ProcessAccountRateLimitV1MeRateLimitGetResponse(
partial void ProcessAccountRateLimitResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
partial void ProcessAccountRateLimitResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);
Expand All @@ -24,22 +24,26 @@ partial void ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
/// </summary>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<global::DeepInfra.RateLimitOut> AccountRateLimitV1MeRateLimitGetAsync(
public async global::System.Threading.Tasks.Task<global::DeepInfra.RateLimitOut> AccountRateLimitAsync(
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: _httpClient);
PrepareAccountRateLimitV1MeRateLimitGetArguments(
PrepareAccountRateLimitArguments(
httpClient: _httpClient);

var __pathBuilder = new PathBuilder(
path: "/v1/me/rate_limit",
baseUri: _httpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
requestUri: new global::System.Uri(_httpClient.BaseAddress?.AbsoluteUri.TrimEnd('/') + "/v1/me/rate_limit", global::System.UriKind.RelativeOrAbsolute));
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));

PrepareRequest(
client: _httpClient,
request: httpRequest);
PrepareAccountRateLimitV1MeRateLimitGetRequest(
PrepareAccountRateLimitRequest(
httpClient: _httpClient,
httpRequestMessage: httpRequest);

Expand All @@ -51,7 +55,7 @@ partial void ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
ProcessResponse(
client: _httpClient,
response: response);
ProcessAccountRateLimitV1MeRateLimitGetResponse(
ProcessAccountRateLimitResponse(
httpClient: _httpClient,
httpResponseMessage: response);

Expand All @@ -61,7 +65,7 @@ partial void ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
client: _httpClient,
response: response,
content: ref __content);
ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
ProcessAccountRateLimitResponseContent(
httpClient: _httpClient,
httpResponseMessage: response,
content: ref __content);
Expand All @@ -76,7 +80,7 @@ partial void ProcessAccountRateLimitV1MeRateLimitGetResponseContent(
}

return
global::System.Text.Json.JsonSerializer.Deserialize(__content, global::DeepInfra.SourceGenerationContext.Default.RateLimitOut) ??
global::System.Text.Json.JsonSerializer.Deserialize(__content, typeof(global::DeepInfra.RateLimitOut), JsonSerializerContext) as global::DeepInfra.RateLimitOut ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
}
Expand Down
Loading

0 comments on commit 66d71b2

Please sign in to comment.