diff --git a/README.md b/README.md index 767aeff5..b32c29fb 100644 --- a/README.md +++ b/README.md @@ -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 . diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatRequest/GeminiChatRequest.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatRequest/GeminiChatRequest.cs index 731c72f7..6894320c 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatRequest/GeminiChatRequest.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatRequest/GeminiChatRequest.cs @@ -70,5 +70,14 @@ public class GeminiChatRequest /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] public GeminiGenerationConfiguration GenerationConfig = null; + + /// + /// The name of the cached content used as context to serve the prediction. Format: cachedContents/{cachedContent} + /// + /// + /// Note: only used in explicit caching, where users can have control over caching (e.g. what content to cache) and enjoy guaranteed cost savings. + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] + public string CachedContent = null; } } \ No newline at end of file diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatResponse/GeminiUsageMetadata.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatResponse/GeminiUsageMetadata.cs index 1fb03469..50bc030d 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatResponse/GeminiUsageMetadata.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/ChatResponse/GeminiUsageMetadata.cs @@ -17,6 +17,11 @@ public class GeminiUsageMetadata /// public int PromptTokenCount; + /// + /// Number of tokens in the cached part of the prompt, i.e. in the cached content. + /// + public int CachedContentTokenCount; + /// /// Total number of tokens across the generated candidates. /// diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs new file mode 100644 index 00000000..26aeae2f --- /dev/null +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; +using System.Runtime.Serialization; + +namespace Uralstech.UGemini +{ + /// + /// Extensions for type objects. + /// + public static class EnumExtensions + { + /// + /// Converts a to its MIME type. + /// + /// The value. + /// The MIME type as a string. + 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(); + } + } +} \ No newline at end of file diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs.meta b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs.meta new file mode 100644 index 00000000..2643b07f --- /dev/null +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/EnumExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c99a26b9d39a3e54484a1cc5dd2ed8da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContent.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContent.cs index d8b44172..54ab25f0 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContent.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContent.cs @@ -1,6 +1,5 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using System; using System.ComponentModel; using UnityEngine; using Uralstech.UGemini.Tools; diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentPart.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentPart.cs index 345ea0ef..29b7ac5d 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentPart.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentPart.cs @@ -40,5 +40,11 @@ public class GeminiContentPart /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] public GeminiFunctionResponse FunctionResponse = null; + + /// + /// URI based data. + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] + public GeminiFileData FileData = null; } } \ No newline at end of file diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentType.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentType.cs index 35547463..83322e3c 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentType.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiContentType.cs @@ -1,5 +1,4 @@ - -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.Runtime.Serialization; diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs new file mode 100644 index 00000000..80b4e526 --- /dev/null +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System.ComponentModel; + +namespace Uralstech.UGemini +{ + /// + /// URI based data. + /// + [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] + public class GeminiFileData + { + /// + /// The IANA standard MIME type of the source data. + /// + /// + /// You can use to convert + /// values to their MIME type, like: + /// GeminiContentType.ImagePNG.MimeType() + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] + public string MimeType = null; + + /// + /// URI. + /// + public string FileUri; + } +} \ No newline at end of file diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs.meta b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs.meta new file mode 100644 index 00000000..34d78e32 --- /dev/null +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Common/GeminiFileData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 36b59e7b3e82bef4db726e0dcef1ed05 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponse.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponse.cs index 242e1af4..ace9f2bb 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponse.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponse.cs @@ -17,7 +17,7 @@ public class GeminiFunctionResponse public string Name; /// - /// The function response in JSON object format. + /// The function response data. /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue(null)] public GeminiFunctionResponseContent Response = null; diff --git a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponseContent.cs b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponseContent.cs index 04b0193b..58056143 100644 --- a/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponseContent.cs +++ b/UGemini/Packages/com.uralstech.ugemini/Runtime/Scripts/Data/Tools/GeminiFunctionResponseContent.cs @@ -11,7 +11,7 @@ namespace Uralstech.UGemini.Tools public class GeminiFunctionResponseContent { /// - /// The name (of the response type?). + /// The name of the function. /// public string Name; diff --git a/UGemini/Packages/com.uralstech.ugemini/package.json b/UGemini/Packages/com.uralstech.ugemini/package.json index 1eb69b0f..f957f2d5 100644 --- a/UGemini/Packages/com.uralstech.ugemini/package.json +++ b/UGemini/Packages/com.uralstech.ugemini/package.json @@ -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", diff --git a/UGemini/Packages/manifest.json b/UGemini/Packages/manifest.json index a19be1b8..075cc252 100644 --- a/UGemini/Packages/manifest.json +++ b/UGemini/Packages/manifest.json @@ -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",