How to get API to "take" on certain rules (prompt engineering)

So here is my very first string in my prompt - where selectedTime is a cache essentially that chooses a response.

This type of response it might do what I want like 30-40% of the time

"The first message I send to the user is “${selectedTime} You’ve reported you’re feeling ${emotions}.”

Whereas this variation of the same prompt…

The first message I send is restricted to: “${selectedTime} You’ve reported you’re feeling ${emotions}.”

has a slightly higher efficiency rate.

Here are my params right now, this is for a chatbot that is supposed to feel as fluent as it possibly can (obviously learning how to do that as i go)


  const response = await openai.createChatCompletion({
    model: "gpt-4",
    messages: [
      {
        role: "system",
        content: message,
      },
    ],
    temperature: 1.1,
    max_tokens: 600,
    top_p: 1,
    frequency_penalty: 0.3,
    presence_penalty: 0.5,
  });

Could it be I should lower my temperature? I know temperature essentially loosens or tightens its “confidence” but from using it it seems like its almost a gateway from creativity to schizophrenia (i know thats not whats going on im just describing this from an experiential stand point.

  {
        role: "system",
        content: message,
      },

Do I have to add something like the assistant after? or change this object somehow to get certain rules to take?

Is there another prompt that helps the api “take” and always do that thing or is it that maybe my temperature is too high?

Another question sort of related,

So ${selectedTime} is a variable related to 4 different arrays that depending on the time of day, you get a response chosen at random of cached strings from one of the four arrays. Ex: if its between 12 and 5 am it will give you “hey its late night” responses chosen from an array. This is just to create an introduction. But given the frequency and presence penaltys - will it then take that chosen string and riff on it? I notice it does that sometimes. I’m wondering how it might be possible to get it to riff on several strings rather than just one, like creating an array of “Thoughts” that it can riff on.

But not through embeddings I actually want to see if its possible to create a caching system that sort of works like giving it a nudge, or giving it “thoughts” to work with. Let me know if this sounds cool to anyone. Sorry for this long post haha, there’s a lot to unpack!

The AI will create language that most looks like what it should generate from a given input. It will not make random choices or probabilities of something happening.

The first flaw with your code is that it is not a chatbot. That just sends one input and gets a response, then done. There is no loop or history.

The second is that “system” is a place for instructions. It can act on the instructions directly, however it must be a role separated from user input if you want to influence the environment the conversation operates in.

{
"role": "system",
"content": "You are ChatBot. Weather is a good topic. A sunny day outside. 22c. ",
},
{
"role": "user",
"content": "Was Einstein smart?",
},

My question will be answered in this properly-formatted example. We’re not talking about the weather.

Friendly chat might be influenced by injected text:

“It is 7:30pm.” - likely no impact.
“It is a pleasant evening” - might be reported
“In each reply, remind in differing contextual ways it is evening”

Temperature is quite high and will lead to very wandering word choices and ways of writing. The intent of the AI won’t change though, unless a poor word selection leads it in a new direction.

Nope. Works fine. so you must be confused. the “message” variable im passing is the long string that is the system prompt

can you reexplain this this isnt super clear

I appreciate you responding but your response as to what you were trying to say isn’t super clear to me.

what? It seems like you’re typing in short form assuming i’ll pick up on what you’re saying but im not

You only show one system prompt. That does not make a chatbot that can carry on an extended conversation about topics properly.

This however is one, using all the necessary roles for each of [system, user, assistant] and maintaining conversation history for 10 recent responses:

import openai
openai.api_key = "sk-xxxxx"
system = [{"role": "system", "content": "You are a helpful AI assistant."}]
user = [{"role": "user", "content": "Introduce yourself."}]
chat = []
while not user[0]['content'] == "exit":
    response = openai.ChatCompletion.create(
        messages = system + chat[-20:] + user,
        model="gpt-3.5-turbo", stream=True)
    reply = ""
    for delta in response:
        if not delta['choices'][0]['finish_reason']:
            word = delta['choices'][0]['delta']['content']
            reply += word  # appends the deltas to record the whole response
            print(word, end ="")
    chat += user + [{"role": "assistant", "content": reply}]
    user = [{"role": "user", "content": input("\nPrompt: ")}]

The initial user “introduction” request calls the API immediately when the program starts, both checking the connection, and the AI gets to introduce how you programmed it. Then you just keep talking to the AI, or say exit.

Take time to consider the operation of the code and messages. It also receives the words as the AI generates them.

In the last part of my prior response, because I asked directly about Einstein, the AI isn’t going to be making chat about the pleasant evening or its emotions that are part of its programming information. It’s just going to answer the question.

Okay. My bot is used all around the world and i get emails every other day about how much it helps people. I am telling you, it works, an it works better than any other bot on the market for its specific use case. You ARE confused. It carries on lengthy chats! Not trying to argue with you you’re just wrong.

you can easily edit this behavior our so it will only speak about certain topics

You’ve strayed from your own topic.

You ask about making some programming to have the AI talk about weather or its feelings 30% of the time (which it can’t compute or roll dice on)

I can ask questions that make the AI directly answer me 100% of the time (or get your off-topic denial 100%), giving no opportunity for the pleasantries.

You’d have to command the AI to always inject text into the start of its responses (and then maybe only give the injection command programming some of the time).

when designing a prompt, pretend youre working with a well behaved, but very dumb toddler with a photographic memory.

this is a method i like using that also alleviates frustration.