Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
gsilvamartin committed Feb 18, 2024
2 parents 86dcfd1 + a4f88f0 commit e1462af
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 0 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Build and Publish NuGet Package

on:
push:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest

outputs:
package_version: ${{ steps.pack.outputs.package_version }}

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'

- name: Get latest NuGet package version
run: |
nuget_response=$(curl -s "https://api.nuget.org/v3-flatcontainer/DotnetGeminiSDK/index.json")
echo "NuGet API Response:"
echo "$nuget_response"
latest_version=$(echo "$nuget_response" | python -c "import sys, json; data = json.load(sys.stdin); versions = data.get('versions', []); versions = [v for v in versions if v is not None]; print(max(versions, key=lambda s: list(map(int, s.split('.')))) if versions else '')")
echo "Latest version after parsing:"
echo "$latest_version"
if [ -z "$latest_version" ]; then
echo "Error: Unable to determine the latest version from the NuGet API response."
exit 1
fi
IFS='.' read -r -a version_parts <<< "$latest_version"
echo "Version parts array: ${version_parts[@]}"
if [ "${#version_parts[@]}" -lt 3 ]; then
echo "Error: Insufficient version parts."
exit 1
fi
set -x
((version_parts[2]++))
set -x
echo "Incremented version parts array: ${version_parts[@]}"
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
echo "Latest version: $latest_version"
echo "New version: $new_version"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: Show environment variable
run: |
echo "NEW_VERSION: $NEW_VERSION"
- name: Install nuget CLI
run: |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
alias nuget="mono /usr/local/bin/nuget.exe"
- name: Update Nuspec file
run: |
nuspec_path="nuget/dotnet-gemini.nuspec"
sed -i "s/<version>.*<\/version>/<version>${NEW_VERSION}<\/version>/" "$nuspec_path"
cat "$nuspec_path"
- name: Pack NuGet package
id: pack
run: |
nuspec_path="nuget/dotnet-gemini.nuspec"
nuget pack $nuspec_path
echo "::set-output name=package_version::$NEW_VERSION"
echo "Packaged NuGet package version: $NEW_VERSION"
- name: Push NuGet Package
run: nuget push **/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
136 changes: 136 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# DotnetGeminiSDK 🚀

Welcome to DotnetGeminiSDK, a .NET SDK for interacting with the Google Gemini API. This SDK empowers developers to harness the capabilities of machine learning models to generate creative content effortlessly.

## Table of Contents
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Text Prompt](#text-prompt)
- [Multiple Text Prompt](#multiple-text-prompt)
- [Image Prompt](#image-prompt)
- [Exception Handling](#exception-handling)
- [Contributing](#contributing)
- [License](#license)

# What is Google Gemini?
Google Gemini is an advanced AI platform that offers various interfaces for commands tailored to different use cases. It allows users to interact with machine learning models for generating content and responses to instructions. The platform supports free-form commands, structured commands, and chat-based requests. Additionally, Gemini provides the ability to adjust models for specific tasks, enhancing their performance for particular use cases.

## Installation 📦
Get started by installing the DotnetGeminiSDK NuGet package. Run the following command in the NuGet Package Manager Console:

```sh
Install-Package DotnetGeminiSDK
```

Or, if you prefer using the .NET CLI:

```sh
dotnet add package DotnetGeminiSDK
```

## Configuration ⚙️
To use the Gemini SDK, configure the `GoogleGeminiConfig` object. Add the Gemini client to your service collection using `GeminiServiceExtensions`:

```csharp
using DotnetGeminiSDK;
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGeminiClient(config =>
{
config.ApiKey = "YOUR_GOOGLE_GEMINI_API_KEY";
config.ImageBaseUrl = "CURRENTLY_IMAGE_BASE_URL";
config.TextBaseUrl = "CURRENTLY_IMAGE_BASE_URL";
});
}
}
```

## How to use? 🔎
### Dependency Injection

When you incorporate the Gemini client, you can seamlessly inject it into your code for immediate use.

```csharp
using DotnetGeminiSDK.Client.Interfaces;
using Microsoft.Extensions.DependencyInjection;

public class YourClass
{
private readonly IGeminiClient _geminiClient;

public YourClass(IGeminiClient geminiClient)
{
_geminiClient = geminiClient;
}

public async Task Example()
{
var response = await _geminiClient.TextPrompt("Text for processing");
// Process the response as needed
}
}
```

## Usage 🚀
### Text Prompt 📝
Prompt the Gemini API with a text message using the `TextPrompt` method:

```csharp
var geminiClient = serviceProvider.GetRequiredService<IGeminiClient>();
var response = await geminiClient.TextPrompt("Write a story about a magic backpack");
```

### Multiple Text Prompt 📚
Prompt the Gemini API with multiple text messages using the `TextPrompt` method with a list of `Content` objects:

```csharp
var geminiClient = serviceProvider.GetRequiredService<IGeminiClient>();

var messages = new List<Content>
{
new Content
{
Parts = new List<Part>
{
new Part
{
Text = "Write a story about a magic backpack"
}
}
},
// Add more Content objects as needed
};

var response = await geminiClient.TextPrompt(messages);
```

### Image Prompt 🖼️
#### Using file
Prompt the Gemini API with an image and a text message using the `ImagePrompt` method:

```csharp
var geminiClient = serviceProvider.GetRequiredService<IGeminiClient>();
var image = File.ReadAllBytes("path/to/your/image.jpg");
var response = await geminiClient.ImagePrompt("Describe this image", image, ImageMimeType.Jpeg);
```

#### Using Base64 String
Prompt the Gemini API with an base64 string and a text message using the `ImagePrompt` method:

```csharp
var geminiClient = serviceProvider.GetRequiredService<IGeminiClient>();
var base64Image = "image-as-base64";
var response = await geminiClient.ImagePrompt("Describe this image", base64Image, ImageMimeType.Jpeg);
```


## Contributing 🤝
Contributions are welcome! Feel free to open issues or pull requests to enhance the SDK.

## License 📜
This project is licensed under the MIT License.
15 changes: 15 additions & 0 deletions nuget/dotnet-gemini.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>DotnetGeminiSDK</id>
<version>1.0.0</version>
<title>Dotnet Gemini SDK</title>
<authors>Guilherme Martin</authors>
<owners>Guilherme Martin</owners>
<description>Interact effortlessly with the Google Gemini API using this .NET SDK. It provides a comprehensive set of functionalities for text and image prompt generation, making it simple to integrate Gemini AI capabilities into your applications.</description>
<dependencies>
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.0"/>
<dependency id="Newtonsoft.Json" version="13.0.3"/>
</dependencies>
</metadata>
</package>

0 comments on commit e1462af

Please sign in to comment.