Skip to content

Commit

Permalink
feat: add ChatGPT test and secrets template
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Nov 19, 2023
1 parent 62b7e51 commit f58db73
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.idea/

# Secrets
/Assets/Secrets.cs
/Assets/Secrets.cs.meta


# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
Expand Down
25 changes: 16 additions & 9 deletions Assets/ChatGPTTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenAI;
using OpenAI.Managers;
Expand All @@ -14,18 +15,25 @@ async void Start()
Debug.Log("Init OpenAI");
var openAiService = new OpenAIService(new OpenAiOptions()
{
// ApiKey = Environment.GetEnvironmentVariable("MY_OPEN_AI_API_KEY")!,
// Organization = Environment.GetEnvironmentVariable("MY_OPEN_ORGANIZATION_ID") //optional
ApiKey = Secrets.OPENAI_API_KEY
});
Debug.Log("Request completion");
var completionResult = await openAiService.Completions.CreateCompletion(new CompletionCreateRequest()
// TODO: get liquid request from Voice SDK speech-to-text
const string liquid = "vinegar";
var completionResult = await openAiService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
{
Prompt = "What is the pH value of vinegar?",
Model = Models.TextDavinciV3
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are a helpful assistant. You only answer with single float numbers," +
" no extra explanations. The number must the parsable, so no characters other" +
" than digits and decimal separator. If you want to answer with a range," +
" give the average value of the range"),
ChatMessage.FromUser($"What is the pH value of {liquid}?"),
},
Model = Models.Gpt_3_5_Turbo
});
if (completionResult.Successful)
{
Debug.Log(completionResult.Choices.First().Text);
Debug.Log(completionResult.Choices.First().Message.Content);
}
else
{
Expand All @@ -41,6 +49,5 @@ async void Start()
// Update is called once per frame
void Update()
{

}
}
}
5 changes: 5 additions & 0 deletions Assets/Scenes/RedoxReality.unity

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

7 changes: 7 additions & 0 deletions Assets/SecretsTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copy below, rename to `Secrets` (class and file name) and populate secret fields
*/
public static class SecretsTemplate
{
public static string OPENAI_API_KEY = "XXXXXXXXXXXXXXXXX";
}
3 changes: 3 additions & 0 deletions Assets/SecretsTemplate.cs.meta

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

5 changes: 1 addition & 4 deletions ProjectSettings/ProjectSettings.asset

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

0 comments on commit f58db73

Please sign in to comment.