-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature suggestion: Add logs with LogLevel using the Standard logging in .NET #6
Comments
Thanks, I will look into it. There should be an option to leverage dependency injection (DI) to provide access to the ILogger interface. However, that's usually bound to an application host or builder. Good idea, and a solid addition to the package. |
@jochenkirstaetter async Task Main()
{
var googleAI = new GoogleAI(apiKey: Util.GetPassword("GEMINI_API_KEY"));
var model = googleAI.GenerativeModel(model: Model.Embedding).Dump();
var response = await model.GetModel().Dump();
var embeddings = await model.EmbedContent(GetMarkdown());
embeddings.Dump();
} |
It looks like it is using the wrong model. Hmm, no then you would get a I'm going to check. What's the content of your markdown? Does it contain double quotes (")? |
Here is my markdown content: string GetMarkdown()
{
return """
Read more about [Mscc.GenerativeAI.Web](https://github.com/mscraftsman/generative-ai/blob/main/src/Mscc.GenerativeAI.Web) and how to add it to your ASP.NET (Core) web applications. Read more about [Mscc.GenerativeAI.Google](https://github.com/mscraftsman/generative-ai/blob/main/src/Mscc.GenerativeAI.Google).
## Install the package 🖥️
Install the package [Mscc.GenerativeAI](https://www.nuget.org/packages/Mscc.GenerativeAI/) from NuGet. You can install the package from the command line using either the command line or the NuGet Package Manager Console. Or you add it directly to your .NET project.
Add the package using the `dotnet` command line tool in your .NET project folder.
```
> dotnet add package Mscc.GenerativeAI
```
Working with Visual Studio use the NuGet Package Manager to install the package Mscc.GenerativeAI.
```
PM> Install-Package Mscc.GenerativeAI
```
Alternatively, add the following line to your `.csproj` file.
```
<ItemGroup>
<PackageReference Include="Mscc.GenerativeAI" Version="0.9.0" />
</ItemGroup>
```
You can then add this code to your sources whenever you need to access any Gemini API provided by Google. This package works for Google AI (Google AI Studio) and Google Cloud Vertex AI.
## Features (as per Gemini analysis) ✦
The provided code defines a C# library for interacting with Google's Generative AI models, specifically the Gemini models. It provides functionalities to:
- **List available models**: This allows users to see which models are available for use.
- **Get information about a specific model**: This provides details about a specific model, such as its capabilities and limitations.
- **Generate content**: This allows users to send prompts to a model and receive generated text in response.
- **Generate content stream**: This allows users to receive a stream of generated text from a model, which can be useful for real-time applications.
- **Generate a grounded answer**: This allows users to ask questions and receive answers that are grounded in provided context.
- **Generate embeddings**: This allows users to convert text into numerical representations that can be used for tasks like similarity search.
- **Count tokens**: This allows users to estimate the cost of using a model by counting the number of tokens in a prompt or response.
- **Start a chat session**: This allows users to have a back-and-forth conversation with a model.
- **Create tuned models**: This allows users to provide samples for tuning an existing model. Currently, only the `text-bison-001` and `gemini-1.0-pro-001` models are supported for tuning
The package also defines various helper classes and enums to represent different aspects of the Gemini API, such as model names, request parameters, and response data.
## Authentication use cases 👥
The package supports the following use cases to authenticate.
- Google AI: [Authentication with an API key](https://ai.google.dev/tutorials/setup)
- Google AI: [Authentication with OAuth](https://ai.google.dev/docs/oauth_quickstart)
- Vertex AI: [Authentication with Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev)
- Vertex AI: [Authentication with OAuth](https://github.com/mscraftsman/generative-ai/blob/main) (using [Mscc.GenerativeAI.Google](https://github.com/mscraftsman/generative-ai/blob/main/src/Mscc.GenerativeAI.Google))
- Vertex AI: [Authentication with Service Account](https://github.com/mscraftsman/generative-ai/blob/main) (using [Mscc.GenerativeAI.Google](https://github.com/mscraftsman/generative-ai/blob/main/src/Mscc.GenerativeAI.Google))
This applies mainly to the instantiation procedure.
""";
} |
The I think the main point is the payload format. Would you consider expose the full response body into the exception object? If I have that, the debugging experience will be much smoother. |
I tried using Postman to send request. Here is my request payload which is serialized from var request = new EmbedContentRequest("Hello");
request.TaskType = TaskType.RetrievalDocument;
request.Title = "Hello World";
request.Content.Role = "user"; The JSON is: {
"model": "models/embedding-001",
"content": {
"parts": [
{
"text": "Hello"
}
],
"role": "user",
"text": "Hello"
},
"taskType": "RETRIEVAL_DOCUMENT",
"title": "Hello World"
} The response body is: {
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"text\" at 'content': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "content",
"description": "Invalid JSON payload received. Unknown name \"text\" at 'content': Cannot find field."
}
]
}
]
}
} That's weird. I checked the API document: https://ai.google.dev/api/rest/v1beta/Content#Part Any idea? |
I found the bug here: I'll raise a new issue for this. See here: #14 |
That second key "text" is too much, and therefore a Bad Request. |
Yes, that should be fine now. Or? |
It works perfectly now. |
Great feedback, thanks. |
Work on .NET logging has started. Currently, there is a new branch Stay tuned, it's still WIP but an active task for now. Cheers, JoKi |
There is not logging support in your core library (the
Mscc.GenerativeAI
package).I wish there is a way to debug your library from the logs with proper
LogLevel
when something went wrong.The Standard .NET Logging should be a good idea.
The text was updated successfully, but these errors were encountered: