You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create the initial prompt, we will reuse it later.
15
-
StringinitialPrompt = "You are a customer support chat-bot. Write brief summaries of the user's questions so that agents can easily find the answer in a database.";
// Create the initial prompt, we will reuse it later.
16
-
StringinitialPrompt = "You are a customer support chat-bot. Write brief summaries of the user's questions so that agents can easily find the answer in a database.";
// This is the prompt that the bot will refer back to for every message.
16
+
ChatMessageprompt = ChatMessage.toSystemMessage("You are a customer support chat-bot. Write brief summaries of the user's questions so that agents can easily find the answer in a database.");
17
+
18
+
// Use a mutable (modifiable) list! Always! You should be reusing the
19
+
// ChatRequest variable, so in order for a conversation to continue
// Create the initial prompt, we will reuse it later.
13
-
val initialPrompt ="You are a customer support chat-bot. Write brief summaries of the user's questions so that agents can easily find the answer in a database."
14
-
val messages =mutableListOf(initialPrompt.toSystemMessage())
15
-
val request =ChatRequest("gpt-3.5-turbo", messages)
16
-
val bot =ChatBot(key)
11
+
// This is the prompt that the bot will refer back to for every message.
12
+
val prompt ="You are a customer support chat-bot. Write brief summaries of the user's questions so that agents can easily find the answer in a database."
13
+
14
+
// Use a mutable (modifiable) list! Always! You should be reusing the
15
+
// ChatRequest variable, so in order for a conversation to continue you
16
+
// need to be able to modify the list.
17
+
val messages =mutableListOf(prompt.toSystemMessage())
17
18
19
+
// ChatRequest is the request we send to OpenAI API. You can modify the
20
+
// model, temperature, maxTokens, etc. This should be saved, so you can
21
+
// reuse it for a conversation.
22
+
val request =ChatRequest(model="gpt-3.5-turbo", messages=messages)
23
+
24
+
// Loads the API key from the .env file in the root directory.
25
+
val key = dotenv()["OPENAI_TOKEN"]
26
+
val openai =OpenAI(key)
27
+
28
+
// The conversation lasts until the user quits the program
18
29
while (true) {
30
+
31
+
// Prompt the user to enter a response
19
32
println("Enter text below:\n")
20
33
val input = scan.nextLine()
21
34
22
-
//Generate a response, and print it to the user.
35
+
//Add the newest user message to the conversation
23
36
messages.add(input.toUserMessage())
24
-
val response = bot.generateResponse(request)
37
+
38
+
// Use the OpenAI API to generate a response to the current
39
+
// conversation. Print the resulting message.
40
+
val response = openai.createChatCompletion(request)
25
41
println("\n${response[0].message.content}\n")
26
42
27
-
// Save the generated message to the bot's conversational memory
43
+
// Save the generated message to the conversational memory. It is
44
+
// crucial to save this message, otherwise future requests will be
0 commit comments