Skip to content

Commit d393b05

Browse files
com.openai.unity 5.0.8 (#104)
- Fixed AudioTranscriptionRequest.Temperature type. int? -> float? - Updated Moderations Categories and Scores with new metrics
1 parent af51aea commit d393b05

File tree

8 files changed

+74
-21
lines changed

8 files changed

+74
-21
lines changed

OpenAI/Packages/com.openai.unity/Runtime/Audio/AudioTranscriptionRequest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AudioTranscriptionRequest(
4646
string model = null,
4747
string prompt = null,
4848
AudioResponseFormat responseFormat = AudioResponseFormat.Json,
49-
int? temperature = null,
49+
float? temperature = null,
5050
string language = null)
5151
: this(File.OpenRead(audioPath), Path.GetFileName(audioPath), model, prompt, responseFormat, temperature, language)
5252
{
@@ -89,7 +89,7 @@ public AudioTranscriptionRequest(
8989
string model = null,
9090
string prompt = null,
9191
AudioResponseFormat responseFormat = AudioResponseFormat.Json,
92-
int? temperature = null,
92+
float? temperature = null,
9393
string language = null)
9494
: this(new MemoryStream(audio.EncodeToWav()), $"{audio.name}.wav", model, prompt, responseFormat, temperature, language)
9595
{
@@ -136,7 +136,7 @@ public AudioTranscriptionRequest(
136136
string model = null,
137137
string prompt = null,
138138
AudioResponseFormat responseFormat = AudioResponseFormat.Json,
139-
int? temperature = null,
139+
float? temperature = null,
140140
string language = null)
141141
{
142142
Audio = audio;
@@ -196,7 +196,7 @@ public AudioTranscriptionRequest(
196196
/// the model will use log probability to automatically increase the temperature until certain thresholds are hit.<br/>
197197
/// Defaults to 0
198198
/// </summary>
199-
public int? Temperature { get; }
199+
public float? Temperature { get; }
200200

201201
/// <summary>
202202
/// Optional, The language of the input audio.

OpenAI/Packages/com.openai.unity/Runtime/Moderations/Categories.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ namespace OpenAI.Moderations
77
public sealed class Categories
88
{
99
[JsonConstructor]
10-
public Categories(bool hate, bool hateThreatening, bool selfHarm, bool sexual, bool sexualMinors, bool violence, bool violenceGraphic)
10+
public Categories(
11+
[JsonProperty("hate")] bool hate,
12+
[JsonProperty("hate/threatening")] bool hateThreatening,
13+
[JsonProperty("harassment")] bool harassment,
14+
[JsonProperty("harassment/threatening")] bool harassmentThreatening,
15+
[JsonProperty("self-harm")] bool selfHarm,
16+
[JsonProperty("self-harm/intent")] bool selfHarmIntent,
17+
[JsonProperty("self-harm/instructions")] bool selfHarmInstructions,
18+
[JsonProperty("sexual")] bool sexual,
19+
[JsonProperty("sexual/minors")] bool sexualMinors,
20+
[JsonProperty("violence")] bool violence,
21+
[JsonProperty("violence/graphic")] bool violenceGraphic)
1122
{
1223
Hate = hate;
1324
HateThreatening = hateThreatening;
25+
Harassment = harassment;
26+
HarassmentThreatening = harassmentThreatening;
1427
SelfHarm = selfHarm;
28+
SelfHarmIntent = selfHarmIntent;
29+
SelfHarmInstructions = selfHarmInstructions;
1530
Sexual = sexual;
1631
SexualMinors = sexualMinors;
1732
Violence = violence;
@@ -24,9 +39,21 @@ public Categories(bool hate, bool hateThreatening, bool selfHarm, bool sexual, b
2439
[JsonProperty("hate/threatening")]
2540
public bool HateThreatening { get; }
2641

42+
[JsonProperty("harassment")]
43+
public bool Harassment { get; }
44+
45+
[JsonProperty("harassment/threatening")]
46+
public bool HarassmentThreatening { get; }
47+
2748
[JsonProperty("self-harm")]
2849
public bool SelfHarm { get; }
2950

51+
[JsonProperty("self-harm/intent")]
52+
public bool SelfHarmIntent { get; }
53+
54+
[JsonProperty("self-harm/instructions")]
55+
public bool SelfHarmInstructions { get; }
56+
3057
[JsonProperty("sexual")]
3158
public bool Sexual { get; }
3259

OpenAI/Packages/com.openai.unity/Runtime/Moderations/ModerationResult.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ namespace OpenAI.Moderations
77
public sealed class ModerationResult
88
{
99
[JsonConstructor]
10-
public ModerationResult(Categories categories, Scores scores, bool flagged)
10+
public ModerationResult(
11+
[JsonProperty("categories")] Categories categories,
12+
[JsonProperty("category_scores")] Scores scores,
13+
[JsonProperty("flagged")] bool flagged)
1114
{
1215
Categories = categories;
1316
Scores = scores;

OpenAI/Packages/com.openai.unity/Runtime/Moderations/Scores.cs

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed under the MIT License. See LICENSE in the project root for license information.
22

33
using Newtonsoft.Json;
4-
using System;
54

65
namespace OpenAI.Moderations
76
{
@@ -11,15 +10,23 @@ public sealed class Scores
1110
public Scores(
1211
[JsonProperty("hate")] double hate,
1312
[JsonProperty("hate/threatening")] double hateThreatening,
13+
[JsonProperty("harassment")] double harassment,
14+
[JsonProperty("harassment/threatening")] double harassmentThreatening,
1415
[JsonProperty("self-harm")] double selfHarm,
16+
[JsonProperty("self-harm/intent")] double selfHarmIntent,
17+
[JsonProperty("self-harm/instructions")] double selfHarmInstructions,
1518
[JsonProperty("sexual")] double sexual,
1619
[JsonProperty("sexual/minors")] double sexualMinors,
1720
[JsonProperty("violence")] double violence,
1821
[JsonProperty("violence/graphic")] double violenceGraphic)
1922
{
2023
Hate = hate;
2124
HateThreatening = hateThreatening;
25+
Harassment = harassment;
26+
HarassmentThreatening = harassmentThreatening;
2227
SelfHarm = selfHarm;
28+
SelfHarmIntent = selfHarmIntent;
29+
SelfHarmInstructions = selfHarmInstructions;
2330
Sexual = sexual;
2431
SexualMinors = sexualMinors;
2532
Violence = violence;
@@ -32,9 +39,21 @@ public Scores(
3239
[JsonProperty("hate/threatening")]
3340
public double HateThreatening { get; }
3441

42+
[JsonProperty("harassment")]
43+
public double Harassment { get; }
44+
45+
[JsonProperty("harassment/threatening")]
46+
public double HarassmentThreatening { get; }
47+
3548
[JsonProperty("self-harm")]
3649
public double SelfHarm { get; }
3750

51+
[JsonProperty("self-harm/intent")]
52+
public double SelfHarmIntent { get; }
53+
54+
[JsonProperty("self-harm/instructions")]
55+
public double SelfHarmInstructions { get; }
56+
3857
[JsonProperty("sexual")]
3958
public double Sexual { get; }
4059

@@ -48,13 +67,17 @@ public Scores(
4867
public double ViolenceGraphic { get; }
4968

5069
public override string ToString() =>
51-
$"{"Hate:",-10}{Hate:0.00 E+00}{Environment.NewLine}" +
52-
$"{"Threat:",-10}{HateThreatening:0.00 E+00}{Environment.NewLine}" +
53-
$"{"Violence:",-10}{Violence:0.00 E+00}{Environment.NewLine}" +
54-
$"{"Graphic:",-10}{ViolenceGraphic:0.00 E+00}{Environment.NewLine}" +
55-
$"{"SelfHarm:",-10}{SelfHarm:0.00 E+00}{Environment.NewLine}" +
56-
$"{"Sexual:",-10}{Sexual:0.00 E+00}{Environment.NewLine}" +
57-
$"{"Minors:",-10}{SexualMinors:0.00 E+00}{Environment.NewLine}";
70+
$"Hate: {Hate:0.00 e+00}\n" +
71+
$"Hate/Threatening: {HateThreatening:0.00 e+00}\n" +
72+
$"Harassment: {Harassment:0.00 e+00}\n" +
73+
$"Harassment/Threatening: {HarassmentThreatening:0.00 e+00}\n" +
74+
$"Self-Harm: {SelfHarm:0.00 e+00}\n" +
75+
$"Self-Harm/Intent: {SelfHarmIntent:0.00 e+00}\n" +
76+
$"Self-Harm/Instructions: {SelfHarmInstructions:0.00 e+00}\n" +
77+
$"Sexual: {Sexual:0.00 e+00}\n" +
78+
$"Sexual/Minors: {SexualMinors:0.00 e+00}\n" +
79+
$"Violence: {Violence:0.00 e+00}\n" +
80+
$"Violence/Graphic: {ViolenceGraphic:0.00 e+00}\n";
5881

5982
public static implicit operator string(Scores scores) => scores.ToString();
6083
}

OpenAI/Packages/com.openai.unity/Tests/TestFixture_07_Audio.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public async Task Test_1_Transcription_AudioClip()
1818
Assert.IsNotNull(api.AudioEndpoint);
1919
var audioPath = AssetDatabase.GUIDToAssetPath("259eaa73cab84284eac307d3134c3ade");
2020
var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(audioPath);
21-
using var request = new AudioTranscriptionRequest(audioClip, language: "en");
21+
using var request = new AudioTranscriptionRequest(audioClip, temperature: 0.1f, language: "en");
2222
var result = await api.AudioEndpoint.CreateTranscriptionAsync(request);
2323
Assert.IsNotNull(result);
2424
Debug.Log(result);
@@ -30,7 +30,7 @@ public async Task Test_1_Transcription_Path()
3030
var api = new OpenAIClient(OpenAIAuthentication.Default.LoadFromEnvironment());
3131
Assert.IsNotNull(api.AudioEndpoint);
3232
var audioPath = AssetDatabase.GUIDToAssetPath("259eaa73cab84284eac307d3134c3ade");
33-
using var request = new AudioTranscriptionRequest(Path.GetFullPath(audioPath), language: "en");
33+
using var request = new AudioTranscriptionRequest(Path.GetFullPath(audioPath), temperature: 0.1f, language: "en");
3434
var result = await api.AudioEndpoint.CreateTranscriptionAsync(request);
3535
Assert.IsNotNull(result);
3636
Debug.Log(result);

OpenAI/Packages/com.openai.unity/Tests/TestFixture_10_Moderations.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
using NUnit.Framework;
44
using OpenAI.Moderations;
5-
using System;
65
using System.Threading.Tasks;
6+
using UnityEngine;
77

88
namespace OpenAI.Tests
99
{
@@ -18,7 +18,7 @@ public async Task Test_1_Moderate()
1818

1919
var response = await api.ModerationsEndpoint.CreateModerationAsync(new ModerationsRequest("I love you"));
2020
Assert.IsNotNull(response);
21-
Console.WriteLine(response.Results?[0]?.Scores?.ToString());
21+
Debug.Log(response.Results?[0]?.Scores?.ToString());
2222
}
2323
}
2424
}

OpenAI/Packages/com.openai.unity/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "OpenAI",
44
"description": "A OpenAI package for the Unity Game Engine to use GPT-4, GPT-3.5, GPT-3 and Dall-E though their RESTful API (currently in beta).\n\nIndependently developed, this is not an official library and I am not affiliated with OpenAI.\n\nAn OpenAI API account is required.",
55
"keywords": [],
6-
"version": "5.0.7",
6+
"version": "5.0.8",
77
"unity": "2021.3",
88
"documentationUrl": "https://github.com/RageAgainstThePixel/com.openai.unity#documentation",
99
"changelogUrl": "https://github.com/RageAgainstThePixel/com.openai.unity/releases",
@@ -17,7 +17,7 @@
1717
"url": "https://github.com/StephenHodgson"
1818
},
1919
"dependencies": {
20-
"com.utilities.rest": "2.1.4",
20+
"com.utilities.rest": "2.1.6",
2121
"com.utilities.encoder.wav": "1.0.4"
2222
},
2323
"samples": [

OpenAI/Packages/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"com.unity.ide.rider": "3.0.24",
4-
"com.unity.ide.visualstudio": "2.0.18",
4+
"com.unity.ide.visualstudio": "2.0.20",
55
"com.unity.textmeshpro": "3.0.6",
66
"com.utilities.buildpipeline": "1.1.7"
77
},

0 commit comments

Comments
 (0)