Zero-shot prompt works - now what?

Now how do I get this prompt to start a conversation in a chatbot webapp?

This prompt works as intended on ChatGPT-4 and Playground/Chat/gpt-4 but none of ChatGPT’s code offerings (Python, html, via Flask) have worked correctly.

It either fails to start the conversation or messes up something else if it does.
I just want it to behave like in the Playground, is that so wrong? :face_with_diagonal_mouth:

(Yes I’m using my API key, Yes it’s cleared for GPT-4)

Can you share your code snippet and a screenshot of Playground working as you intend?

1 Like

Happy to but not sure how much is too much since html is involved, but I think this is a Python thing so here’s that:

from flask import Flask, render_template, request, jsonify
import openai
import os

app = Flask(__name__)

openai.api_key = "{MyKey}"

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/send_message", methods=["POST"])
def send_message():
    message = request.form["message"]
    response = generate_response(message)
    return jsonify({"message": response})

def generate_response(message):
    prompt = f"""
    {MyPrompt}
    """
    
    response = openai.ChatCompletion.create(
        engine="gpt-4",
        prompt=prompt,
        max_tokens=256,
        n=1,
        stop=None,
        temperature=0.598,
    )

    chat_response = response.choices[0].text.strip()
    return chat_response

if __name__ == "__main__":
    app.run(debug=True)

Attached is the Playground output (the first few exchanges).

Hi @InspectorUX
The following part of your code is incorrect and will lead to a 400 aka invalid request.

Please look at the boilerplate reference for chat completion and fix your code.

Thank you @sps. I’m not getting the 400 error, but am wondering if I need all that code since it’s a zero-shot prompt (read: no previous messages required for training).

I do feel like I might need this set as a ‘system’ message though…

These two parameters don’t exist on the chat completions endpoint.

If you do that, make sure to rephrase it in second person.

  These two parameters don’t exist on the chat completions endpoint.

I think you’re onto something because ChatGPT kept trying to give me Completion code instead of ChatCompletion. (plus ‘engine’ was deprecated for ‘model’ so that’s been updated).

  If you do that, make sure to rephrase it in second person.

How would a system message in second person look?

Here’s another version where I was trying to set as ‘initial prompt’

initial_prompt = {
    'role': 'system',
    'content': "You are a career counselor/coach for high schoolers..."
}

messages = [initial_prompt]

def append_user_message(user_input):
    messages.append({
        'role': 'user',
        'content': user_input
    })

def generate_response():
    response = openai.ChatCompletion.create(
        model="gpt-4",
        messages=messages,
        max_tokens=256,
        temperature=0.598,
    )
    return response.choices[0].message['content']

Yes, it has to be in this form - although I hope you’ll not be leaving that at …

Also make sure to remove any ambiguities or the use of ‘/’ or or from the message. e.g counselor/coach unless it has to be part of the reasoning that the model must engage in. Ambiguity reduces control over the model, you don’t know which one the model picks.
Keep the prompt clear and concise without compromising on detail.

Thanks again, good inputs. :slight_smile:

Also make sure to remove any ambiguities or the use of ‘/’ or or from the message. e.g counselor/coach unless it has to be part of the reasoning that the model must engage in.

The prompt would be in an f string so that the /s are, like you said, interpreted as reasoning.

Again, the prompt works as-is in ChatGPT-4 and Playground/Chat/gpt-4 but I’m missing the code to get it to initiate the conversation with the user (as opposed to waiting for the user to say something first).

(And yes, that’s just the first truncated line of the prompt, which is about 375 tokens long.)

You don’t need the model to send the first message. You can send the first message using your code and your own greeting. Once you do that, simply push the message into the list of message objects, with the role “assistant” to maintain context.