Skip to content

Commit

Permalink
com.openai.unity 5.0.6 (#101)
Browse files Browse the repository at this point in the history
- fixed embedding response deserialization
  • Loading branch information
StephenHodgson authored Aug 10, 2023
1 parent 9cc3c0b commit f8188bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Runtime/Common/Usage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public sealed class Usage
{
[JsonConstructor]
public Usage(
int? promptTokens,
int? completionTokens,
int? totalTokens)
[JsonProperty("prompt_tokens")] int? promptTokens,
[JsonProperty("completion_tokens")] int? completionTokens,
[JsonProperty("total_tokens")] int? totalTokens)
{
PromptTokens = promptTokens;
CompletionTokens = completionTokens;
Expand Down
11 changes: 7 additions & 4 deletions Runtime/Embeddings/Datum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ namespace OpenAI.Embeddings
public sealed class Datum
{
[JsonConstructor]
public Datum(string @object, IReadOnlyList<double> embedding, int index)
public Datum(
[JsonProperty("object")] string @object,
[JsonProperty("embedding")] IReadOnlyList<double> embedding,
[JsonProperty("index")] int index)
{
Object = @object;
Embedding = embedding;
Index = index;
}

[JsonProperty("object")]
public string Object { get; }
public string Object { get; private set; }

[JsonProperty("embedding")]
public IReadOnlyList<double> Embedding { get; }
public IReadOnlyList<double> Embedding { get; private set; }

[JsonProperty("index")]
public int Index { get; }
public int Index { get; private set; }
}
}
14 changes: 9 additions & 5 deletions Runtime/Embeddings/EmbeddingsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace OpenAI.Embeddings
public sealed class EmbeddingsResponse : BaseResponse
{
[JsonConstructor]
public EmbeddingsResponse(string @object, IReadOnlyList<Datum> data, string model, Usage usage)
public EmbeddingsResponse(
[JsonProperty("object")] string @object,
[JsonProperty("data")] IReadOnlyList<Datum> data,
[JsonProperty("model")] string model,
[JsonProperty("usage")] Usage usage)
{
Object = @object;
Data = data;
Expand All @@ -17,15 +21,15 @@ public EmbeddingsResponse(string @object, IReadOnlyList<Datum> data, string mode
}

[JsonProperty("object")]
public string Object { get; }
public string Object { get; private set; }

[JsonProperty("data")]
public IReadOnlyList<Datum> Data { get; }
public IReadOnlyList<Datum> Data { get; private set; }

[JsonProperty("model")]
public string Model { get; }
public string Model { get; private set; }

[JsonProperty("usage")]
public Usage Usage { get; }
public Usage Usage { get; private set; }
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "OpenAI",
"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.",
"keywords": [],
"version": "5.0.5",
"version": "5.0.6",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.openai.unity#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.openai.unity/releases",
Expand Down

0 comments on commit f8188bd

Please sign in to comment.