Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt engineering; output to two text files #19

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,5 @@ Assets/WitConfig.asset.meta
ProjectSettings/wit.config
Assets/APIKey.txt
Assets/APIKey.txt.meta
Assets/Oculus
Assets/Oculus.meta
2 changes: 1 addition & 1 deletion Assets/Scenes/SpeechToText.unity
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
runtimeConfiguration:
witConfiguration: {fileID: 11400000, guid: c0ac5afd2a82046d485f7c2a16c7d372, type: 2}
witConfiguration: {fileID: 11400000, guid: 043eb99b154e3488eabb37b20b4ea923, type: 2}
minKeepAliveVolume: 50
minKeepAliveTimeInSeconds: 300
minTranscriptionKeepAliveTimeInSeconds: 300
Expand Down
100 changes: 81 additions & 19 deletions Assets/Scripts/ChatGPTManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,135 @@
public class ChatGPTManager : MonoBehaviour
{
public OnResponseEvent OnResponse;

[System.Serializable]
public class OnResponseEvent : UnityEvent<string> { }

private OpenAIApi openAI = new OpenAIApi();
private List<ChatMessage> messages = new List<ChatMessage>();

/// <summary>
/// Initiates an asynchronous interaction with the ChatGPT model based on the content of a specified text file.
/// Initiates an asynchronous interaction with the ChatGPT model based on the combined content of "Prompt.txt" and "SpeechLog.txt".
/// </summary>
/// <remarks>
/// Reads a user's input from "SpeechLog.txt" located within the Assets directory, logs the content for debugging purposes,
/// and checks for null or empty input. If valid, the text is sent as a request to the ChatGPT model. The model's response
/// is then captured and logged, and the associated event is triggered with the response data.
/// Reads the content from "Prompt.txt" and "SpeechLog.txt" located within the Assets/TextFiles directory,
/// combines the content, logs it for debugging purposes, and checks for null or empty input.
/// If valid, the combined text is sent as a request to the ChatGPT model. The model's response is then captured,
/// logged, and the associated event is triggered with the response data.
/// </remarks>
/// <exception cref="Exception">Throws an exception if there is an error reading from the text file.</exception>
/// <exception cref="Exception">Throws an exception if there is an error reading from the text files.</exception>
public async void AskChatGPT()
{
// Read the text from Assets/SpeechLog.txt
string filePath = Path.Combine(Application.dataPath, "SpeechLog.txt");
string newText;
// Read the text from Assets/TextFiles/Prompt.txt
string promptFilePath = Path.Combine(Application.dataPath, "TextFiles", "Prompt.txt");
string promptText = "";
try
{
promptText = File.ReadAllText(promptFilePath);
}
catch (Exception e)
{
Debug.LogError("Error reading from the Prompt.txt file: " + e.Message);
return;
}

// Read the text from Assets/TextFiles/SpeechLog.txt
string speechLogFilePath = Path.Combine(Application.dataPath, "TextFiles", "SpeechLog.txt");
string speechLogText = "";
try
{
newText = File.ReadAllText(filePath);
speechLogText = File.ReadAllText(speechLogFilePath);
}
catch (Exception e)
{
Debug.LogError("Error reading from the SpeechLog.txt file: " + e.Message);
return;
}

// Log the text content for debugging
Debug.Log("Text read from SpeechLog.txt: " + newText);
// Combine the content of Prompt.txt and SpeechLog.txt
string combinedText = promptText + "\n" + speechLogText;

// Check if the file content is empty
if (string.IsNullOrEmpty(newText))
// Log the combined text content for debugging
Debug.Log("Combined text from Prompt.txt and SpeechLog.txt: " + combinedText);

// Check if the combined content is empty
if (string.IsNullOrEmpty(combinedText))
{
Debug.LogError("The SpeechLog.txt file is empty or text is null.");
Debug.LogError("The combined content is empty or null.");
return;
}

// Ask ChatGPT
ChatMessage newMessage = new ChatMessage();
newMessage.Content = newText;
newMessage.Content = combinedText;
newMessage.Role = "user";

messages.Add(newMessage);

CreateChatCompletionRequest request = new CreateChatCompletionRequest();
request.Messages = messages;
// request.Model = "gpt-3.5-turbo";
request.Model = "gpt-4-turbo";

var response = await openAI.CreateChatCompletion(request);
// var response = await openAI.CreateChatCompletion(request);
// if (response.Choices != null && response.Choices.Count > 0)
// {
// var chatResponse = response.Choices[0].Message;
// messages.Add(chatResponse);

// // Log the response for debugging
// Debug.Log(chatResponse.Content);
// OnResponse.Invoke(chatResponse.Content);
// }
var response = await openAI.CreateChatCompletion(request);
if (response.Choices != null && response.Choices.Count > 0)
{
var chatResponse = response.Choices[0].Message;
messages.Add(chatResponse);

// Log the response for debugging
Debug.Log(chatResponse.Content);

OnResponse.Invoke(chatResponse.Content);

// Separate professional and novice content
string professionalContent = ExtractContent(chatResponse.Content, "Professional:");
string noviceContent = ExtractContent(chatResponse.Content, "Novice:");

// Save professional content to Response1.txt
string response1FilePath = Path.Combine(Application.dataPath, "TextFiles", "Response1.txt");
File.WriteAllText(response1FilePath, professionalContent);

// Save novice content to Response2.txt
string response2FilePath = Path.Combine(Application.dataPath, "TextFiles", "Response2.txt");
File.WriteAllText(response2FilePath, noviceContent);
}
}

/// <summary>
/// Extracts the content between the specified keyword and the next keyword or end of string.
/// </summary>
/// <param name="content">The input string to extract from.</param>
/// <param name="keyword">The keyword to search for.</param>
/// <returns>The extracted content.</returns>
private string ExtractContent(string content, string keyword)
{
int startIndex = content.IndexOf(keyword);
if (startIndex != -1)
{
startIndex += keyword.Length;
int endIndex = content.IndexOf("Professional:", startIndex);
if (endIndex == -1)
endIndex = content.IndexOf("Novice:", startIndex);
if (endIndex == -1)
endIndex = content.Length;

return content.Substring(startIndex, endIndex - startIndex).Trim();
}

return string.Empty;
}

void Start()
{
AskChatGPT();
}
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/TranscriptionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private void Start()
_textComponent = GetComponent<TextMeshProUGUI>();
_previousText = string.Empty;
// Assets/SpeechLog.txt
_filePath = Path.Combine(Application.dataPath, "SpeechLog.txt");
_filePath = Path.Combine(Application.dataPath, "TextFiles", "SpeechLog.txt");
// opens the file in truncate mode to clear the content
_streamWriter = new StreamWriter(_filePath, false);
_streamWriter.Close();
Expand Down
1 change: 0 additions & 1 deletion Assets/SpeechLog.txt

This file was deleted.

8 changes: 8 additions & 0 deletions Assets/TextFiles.meta

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

34 changes: 34 additions & 0 deletions Assets/TextFiles/Prompt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Prompt:
Given the full transcription for a presentation, do the following:
1. Read the full transcript and divide it into separate sections (e.g., motivation, overview, related work).
2. Pretend you are a professional well-versed in the topic.
3. Ask questions targeted for each section. Make sure to include at least one question for each section. Make sure the questions fit your character. Make sure each question is no more than two sentences. Do not contain the word 'Novice' in the question.
4. List at least two areas of improvement in the presentation. Make sure the suggestions fit your character. Make sure each suggestion is no more than two sentences. Do not contain the word 'Novice' in the suggestion.
5. Pretend you are a novice who is not well-versed in the topic.
6. Ask questions targeted for each section. Make sure to include at least one question for each section. Make sure the questions fit your character. Make sure each question is no more than two sentences. Do not contain the word 'Professional' in the question.
7. List at least two areas of improvement in the presentation. Make sure the suggestions fit your character. Make sure each suggestion is no more than two sentences. Do not contain the word 'Professional' in the suggestion.
8. Output your answer in the following format:
'''
Professional:
Questions:
Section <section name>
1. ...
2. ...
Section <section name>
1. ...
2. ...
Suggestions:
1. ...
2. ...
Novice:
Questions:
Section <section name>
1. ...
2. ...
Section <section name>
1. ...
2. ...
Suggestions:
1. ...
2. ...
'''
7 changes: 7 additions & 0 deletions Assets/TextFiles/Prompt.txt.meta

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

16 changes: 16 additions & 0 deletions Assets/TextFiles/Response1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Questions:
Section Motivation
1. Can you elaborate on the specific limitations encountered when practicing presentations in front of a wall or mirror that Deck Talk aims to overcome?
2. How does the inclusion of AI-powered audiences in virtual reality fundamentally enhance the effectiveness of practice sessions compared to traditional methods?

Section Overview
1. You mentioned three core concepts of Deck Talk; could you discuss how each concept individually contributes to improving presentation skills?
2. Regarding interactivity with the audience, what types of feedback can the presenter expect to receive from the AI?

Section Related Work
1. How does Deck Talk's feature set compare to Virtual Speech with regard to real-time interactivity and feedback accuracy?
2. Given the competitive landscape, what are the commercial viability and sustainability plans for Deck Talk considering it will be offered free?

Suggestions:
1. Consider conducting a side-by-side comparative study detailing user improvement using Deck Talk versus traditional practice methods to underline the app's effectiveness.
2. Include testimonials from early users to add authenticity and real-world applicability in your next presentation.
7 changes: 7 additions & 0 deletions Assets/TextFiles/Response1.txt.meta

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

17 changes: 17 additions & 0 deletions Assets/TextFiles/Response2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Questions:
Section Motivation
1. Why do people practice talks in front of a mirror and what issues do they face?
2. How might practicing in a virtual environment be different from practicing in front of a mirror?

Section Overview
1. What exactly do you mean by ‘virtual avatars’?
2. Could you explain a little more about how interacting with the AI audience works?

Section Related Work
1. What is the main difference between Deck Talk and other similar apps like Virtual Speech?
2. Why is it important that Deck Talk is free?

Suggestions:
1. Could you include more simple examples or comparisons to help understand how the virtual reality environment works?
2. Maybe add some pictures or screenshots of the app in action, so it's easier to visualize what you are talking about.
```
7 changes: 7 additions & 0 deletions Assets/TextFiles/Response2.txt.meta

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

20 changes: 20 additions & 0 deletions Assets/TextFiles/SpeechLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Full transcription:
We present deck talk a virtual reality app that enables users to practice giving talks in virtualized environments to an interactable AI powered audience.
Presentation it's common in both academic and professional settings
To refine the presentation people often practice giving talks in front of a wall or mirror
Where are limited amount of feedback can be obtained
How can we make practice talks more effective and closer to real life?
We designed deck talk based on three core concepts.
First the user should be able to choose from a diverse set of environments to give toxin
Second
We are just taking virtual avatars should be present in the scene.
To mimic real audiences.
Third the user should be able to interact with the audience via question answering and receive feedback about the presentation
The company virtual speech has developed a similar application with virtual reality and AI.
Including varied Workplace settings
Virtual Interactable avatars. And AI generated ratings.
However, virtual speech requires the conversion of presentation sites into PDFs
And it costs $400 a year
In contrast we allow users to bring the presentation into the virtual environment
The web browser and are planning to offer the app for free by open sourcing the code.
In addition our app enables users to improve their general presentation skills by practicing against AI generated presentation sides.
File renamed without changes.