forked from GraesonB/ChatGPT-Wrapper-For-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chat.cs
39 lines (34 loc) · 1.24 KB
/
Chat.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
namespace ChatGPTWrapper {
// Due to OpenAI's new chat completions api, this replaces the old "Prompt" class, but the prompt class is still used for the older models.
public class Chat
{
private string _initialPrompt;
private List<Message> _currentChat = new List<Message>();
public Chat(string initialPrompt) {
_initialPrompt = initialPrompt;
Message systemMessage = new Message("system", initialPrompt);
_currentChat.Add(systemMessage);
}
public List<Message> CurrentChat { get { return _currentChat; } }
public enum Speaker {
User,
ChatGPT
}
public void AppendMessage(Speaker speaker, string text)
{
switch (speaker)
{
case Speaker.User:
Message userMessage = new Message("user", text);
_currentChat.Add(userMessage);
break;
case Speaker.ChatGPT:
Message chatGPTMessage = new Message("assistant", text);
_currentChat.Add(chatGPTMessage);
break;
}
}
}
}