Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style:Run dotnet format #164

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Google/src/Extensions/GoogleGeminiExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using CSharpToJsonSchema;
using GenerativeAI;
Expand Down Expand Up @@ -26,7 +27,7 @@
})
.ToList();

if (declarations.Any())

Check warning on line 30 in src/Google/src/Extensions/GoogleGeminiExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1860)
{
return new List<GenerativeAI.Types.Tool?>
{
Expand All @@ -37,7 +38,7 @@
};
}

return null;

Check warning on line 41 in src/Google/src/Extensions/GoogleGeminiExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Possible null reference return.
}

public static string GetStringForFunctionArgs(this object? arguments)
Expand All @@ -48,10 +49,12 @@
return jsonElement.ToString();
else
{
return null;

Check warning on line 52 in src/Google/src/Extensions/GoogleGeminiExtensions.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Possible null reference return.
}
}

[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
[RequiresDynamicCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
public static Schema? ToFunctionParameters(this OpenApiSchema openApiSchema)
{
var text = JsonSerializer.Serialize(openApiSchema);
Expand Down
2 changes: 1 addition & 1 deletion src/Google/src/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Content AsFunctionResultContent(this string args, string functionN
},
Name = functionName
};
var content = new Content(){Role = Roles.Function};
var content = new Content() { Role = Roles.Function };
content.AddPart(new Part()
{
FunctionResponse = functionResponse
Expand Down
22 changes: 11 additions & 11 deletions src/Google/src/GoogleChatModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
private GenerativeModel Api { get; } = new(
provider.ApiKey,
id,
httpClient:provider.HttpClient)
httpClient: provider.HttpClient)
{
FunctionCallingBehaviour = new FunctionCallingBehaviour()
{
AutoCallFunction = false,
AutoReplyFunction = false,
AutoHandleBadFunctionCalls = false
}
FunctionCallingBehaviour = new FunctionCallingBehaviour()
{
AutoCallFunction = false,
AutoReplyFunction = false,
AutoHandleBadFunctionCalls = false
}
};

#endregion
Expand All @@ -65,7 +65,7 @@
{
var function = message.GetFunction();

return new Message( function?.Args.GetStringForFunctionArgs() ?? string.Empty,
return new Message(function?.Args.GetStringForFunctionArgs() ?? string.Empty,
MessageRole.ToolCall, function?.Name);
}

Expand All @@ -81,7 +81,7 @@
var request = new GenerateContentRequest
{
Contents = messages.Select(ToRequestMessage).ToList(),
Tools = GlobalTools.ToGenerativeAiTools()

Check warning on line 84 in src/Google/src/GoogleChatModel.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Nullability of reference types in value of type 'List<Tool?>' doesn't match target type 'List<Tool>'.
};


Expand Down Expand Up @@ -112,14 +112,14 @@
Temperature = provider.Configuration.Temperature
};
StringBuilder sb = new StringBuilder();
await foreach (var response in Api.StreamContentAsync(request, cancellationToken))
await foreach (var response in Api.StreamContentAsync(request, cancellationToken).ConfigureAwait(false))
{
var text = response.Text() ?? string.Empty;

sb.Append(text);
OnDeltaReceived(text);
}


return new Message(
sb.ToString(),
Expand Down
2 changes: 1 addition & 1 deletion src/Google/src/GoogleEmbeddingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
string id)
: Model<EmbeddingSettings>(id), IEmbeddingModel
{

public EmbeddingModel EmbeddingModel { get; } =

Check warning on line 15 in src/Google/src/GoogleEmbeddingModel.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Type of 'GoogleEmbeddingModel.EmbeddingModel' is not CLS-compliant
new EmbeddingModel(provider.ApiKey, id, httpClient: provider.HttpClient);


Expand Down Expand Up @@ -46,7 +46,7 @@

if (embedResponse.Embedding == null)
throw new GenerativeAIException("Failed to create embeddings.", "");
var values = embedResponse.Embedding.Values.ToList();

Check warning on line 49 in src/Google/src/GoogleEmbeddingModel.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Possible null reference argument for parameter 'source' in 'List<float> Enumerable.ToList<float>(IEnumerable<float> source)'.

return new EmbeddingResponse
{
Expand Down
4 changes: 2 additions & 2 deletions src/Google/src/GoogleEmbeddingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LangChain.Providers.Google;

public class GoogleEmbeddingSettings:EmbeddingSettings
public class GoogleEmbeddingSettings : EmbeddingSettings
{
/// <summary>
/// Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024 only. You cannot set this value if using the earlier model (models/embedding-001).
Expand All @@ -12,7 +12,7 @@
{
OutputDimensionality = null
};

/// <summary>
/// Calculate the settings to use for the request.
/// </summary>
Expand All @@ -21,7 +21,7 @@
/// <param name="providerSettings"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public new static GoogleEmbeddingSettings Calculate(

Check warning on line 24 in src/Google/src/GoogleEmbeddingSettings.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

The member 'GoogleEmbeddingSettings.Calculate(EmbeddingSettings?, EmbeddingSettings?, EmbeddingSettings?)' does not hide an accessible member. The new keyword is not required.
EmbeddingSettings? requestSettings,
EmbeddingSettings? modelSettings,
EmbeddingSettings? providerSettings)
Expand Down
2 changes: 1 addition & 1 deletion src/Google/src/GoogleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
/// <summary>
/// </summary>
public GoogleConfiguration? Configuration { get; set; }

public GoogleEmbeddingSettings? EmbeddingSettings { get; set; }

Check warning on line 35 in src/Google/src/GoogleProvider.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

'GoogleProvider.EmbeddingSettings' hides inherited member 'Provider.EmbeddingSettings'. Use the new keyword if hiding was intended.

#endregion

Expand Down
1 change: 0 additions & 1 deletion src/Google/src/Predefined/GoogleEmbeddingModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace LangChain.Providers.Google.Predefined;

/// <inheritdoc cref="GoogleAIModels.GeminiPro" />

Check warning on line 5 in src/Google/src/Predefined/GoogleEmbeddingModels.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

XML comment has cref attribute 'GeminiPro' that could not be resolved
public class GoogleTextEmbedding(GoogleProvider provider)
: GoogleEmbeddingModel(
provider, GoogleAIModels.TextEmbedding);

2 changes: 1 addition & 1 deletion src/IntegrationTests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public async Task Tools_Books(ProviderType providerType)
[Explicit]
public async Task GoogleEmbeddingTest()
{
var (llm,embeddingModel , _) = Helpers.GetModels(ProviderType.Google);
var (llm, embeddingModel, _) = Helpers.GetModels(ProviderType.Google);

var embeddings = await embeddingModel.CreateEmbeddingsAsync(new EmbeddingRequest()
{
Expand Down
2 changes: 1 addition & 1 deletion src/IntegrationTests/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static (IChatModel ChatModel, IEmbeddingModel EmbeddingModel, IProvider P
throw new InconclusiveException("GOOGLE_API_KEY is not set"),
httpClient: new HttpClient());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using HttpClientFactory for better resource management.

The inline creation of HttpClient instances can lead to socket exhaustion. Consider using IHttpClientFactory for better lifecycle management.

-                        httpClient: new HttpClient());
+                        httpClient: httpClientFactory.CreateClient("Google"));

Add IHttpClientFactory as a dependency:

public static class Helpers
{
    private static readonly IHttpClientFactory _httpClientFactory;

    static Helpers(IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory;
    }
    // ... rest of the code
}

var llm = new Gemini15FlashModel(provider);

var embeddings = new GoogleTextEmbedding(provider);

return (llm, embeddings, provider);
Expand Down
Loading