Skip to content

Commit

Permalink
UGemini v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Uralstech committed Jul 1, 2024
1 parent a69e702 commit fa571af
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 7 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ Follow the steps detailed in the OpenUPM installation method and only install th

*Optional, but required if you don't want to bother with encoding your AudioClips into Base64 strings manually.

### Gemini API Support

- [x] `models` endpoint :warning:
- [ ] `batchEmbedContents` method
- [x] `countTokens` method
- [ ] `embedContent` method
- [ ] `generateAnswer` method :test_tube:
- [x] `generateContent` method
- [x] JSON output :test_tube:
- [x] System instructions :test_tube:
- [x] Text generation
- [x] Vision
- [x] Function calling :test_tube:
- [x] Safety settings

- [ ] `get` method
- [ ] `list` method
- [ ] `streamGenerateContent` method

- [ ] `cachedContents` endpoint :test_tube:
- [ ] `corpora` endpoint :test_tube:
- [ ] `files` endpoint :test_tube:
- [ ] `media` endpoint :test_tube:
- [ ] `tunedModels` endpoint
- [ ] `operations` endpoint

:warning: - Not all methods/features of supported
:test_tube: - Using the v1beta API

### Documentation

See <https://github.com/Uralstech/UGemini/blob/master/UGemini/Packages/com.uralstech.ugemini/Documentation~/README.md>.
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,14 @@ public class GeminiChatRequest
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public GeminiGenerationConfiguration GenerationConfig = null;

/// <summary>
/// The name of the cached content used as context to serve the prediction. Format: cachedContents/{cachedContent}
/// </summary>
/// <remarks>
/// Note: only used in explicit caching, where users can have control over caching (e.g. what content to cache) and enjoy guaranteed cost savings.
/// </remarks>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public string CachedContent = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class GeminiUsageMetadata
/// </remarks>
public int PromptTokenCount;

/// <summary>
/// Number of tokens in the cached part of the prompt, i.e. in the cached content.
/// </summary>
public int CachedContentTokenCount;

/// <summary>
/// Total number of tokens across the generated candidates.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;

namespace Uralstech.UGemini
{
/// <summary>
/// Extensions for <see cref="Enum"/> type objects.
/// </summary>
public static class EnumExtensions
{
/// <summary>
/// Converts a <see cref="GeminiContentType"/> to its <see href="https://www.iana.org/assignments/media-types/media-types.xhtml">MIME type</see>.
/// </summary>
/// <param name="enumValue">The <see cref="GeminiContentType"/> value.</param>
/// <returns>The MIME type as a string.</returns>
public static string MimeType(this GeminiContentType enumValue)
{
Type type = enumValue.GetType();
MemberInfo[] memberInfo = type.GetMember(enumValue.ToString());

if (memberInfo != null && memberInfo.Length > 0)
{
object[] attributes = memberInfo[0].GetCustomAttributes(typeof(EnumMemberAttribute), false);

if (attributes != null && attributes.Length > 0)
return ((EnumMemberAttribute)attributes[0]).Value;
}

// Return the enum name if no EnumMember attribute is found
return enumValue.ToString();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.ComponentModel;
using UnityEngine;
using Uralstech.UGemini.Tools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ public class GeminiContentPart
/// </remarks>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public GeminiFunctionResponse FunctionResponse = null;

/// <summary>
/// URI based data.
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public GeminiFileData FileData = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.Serialization;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.ComponentModel;

namespace Uralstech.UGemini
{
/// <summary>
/// URI based data.
/// </summary>
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class GeminiFileData
{
/// <summary>
/// The IANA standard MIME type of the source data.
/// </summary>
/// <remarks>
/// You can use <see cref="EnumExtensions.MimeType(GeminiContentType)"/> to convert <see cref="GeminiContentType"/>
/// values to their <see cref="string"/> MIME type, like:
/// <c>GeminiContentType.ImagePNG.MimeType()</c>
/// </remarks>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public string MimeType = null;

/// <summary>
/// URI.
/// </summary>
public string FileUri;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class GeminiFunctionResponse
public string Name;

/// <summary>
/// The function response in JSON object format.
/// The function response data.
/// </summary>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)]
public GeminiFunctionResponseContent Response = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Uralstech.UGemini.Tools
public class GeminiFunctionResponseContent
{
/// <summary>
/// The name (of the response type?).
/// The name of the function.
/// </summary>
public string Name;

Expand Down
2 changes: 1 addition & 1 deletion UGemini/Packages/com.uralstech.ugemini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AI",
"Integration"
],
"version": "1.0.0",
"version": "1.0.1",
"unity": "2022.3",
"hideInEditor": false,
"documentationUrl": "https://github.com/Uralstech/UGemini/blob/master/UGemini/Packages/com.uralstech.ugemini/Documentation~/README.md",
Expand Down
2 changes: 1 addition & 1 deletion UGemini/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"com.unity.timeline": "1.7.6",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.9.4",
"com.uralstech.ugemini": "1.0.0",
"com.uralstech.ugemini": "1.0.1",
"com.utilities.encoder.wav": "1.2.1",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down

0 comments on commit fa571af

Please sign in to comment.