Combining user input in prompts using OpenAI API

I am building an application that asks the user questions that will help him get ready for his job interview, based on his role, the job requirements and his resume.

Right now I am converting the PDF resume to text (I understood from various forms that directly sending files to the API is much more complicated).

The problem is, I have no way to define a set place in the prompt text for these variables. If I use for example ‘\n’ separator, it can be a character in the job requirements variables.

So right now the prompt is something like:

prompt = "My CV is: " + resumeInText + "\n\n\n" + "Help me get ready for..."

const completion = await openai.chat.completions.create({
	messages: [
		{
			role: "system",
			content: prompt,
		},
	],
	model: "gpt-4o",
});

How can I change it for more safety and accurate results?

1 Like

Welcome to the community!

I think you’re on the right track. Common delimiters are

    --------------------------
    ##########################
    §§§§§§§§§§§§§§§§§§§§§§§§§§
    ////////BEGIN DATA\\\\\\\\
    \\\\\\\\ END DATA ////////
    <<<<<<<<<<<<<>>>>>>>>>>>>>
    %%%%%%%%%%%%%%%%%%%%%%%%%%
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

Then there’s also stuff the newer models have been trained with

    ```txt
    <your text here>
    ```

Which of these work best? Dunno, but I don’t think it matters that much.

But you might need to keep in mind that over very long text, these delimiters might be forgotten or mixed up. One thing that might help with that is to keep certain text indented or prefaced with a character/line numbers - but it depends.

A pattern I would generally start with is to restate the contextualization at the end:

    Here's my CV:
    -------------
        John Doe
        Serial serialization, deserialization, and reserialization specialist
        email@mail.john

        Experience:
        DOLE
        Can Serialization Specialist
    -------------
    Given my CV above, pls do X, Y ,Z. 

One more thing you can do is to separate your content out into different messages with different roles, e.g.: Initial contextualization: system, CV: user, instruction: system again.

Overall it’s tough to give a definitive answer because what’s best sometimes changes from minor model version to minor model version. I wouldn’t agonize over it too much, and use a fixed model version (gpt-4o-2024-08-06 as opposed to gpt-4o) :slight_smile:

Hope this helps you get started :slight_smile:

5 Likes

Personally, I think the real problem is the mixed use of system vs user messages… Here is how I would (usually) do it:

System message:

Instructions for the model:
what the model is, what the task is, and how to achieve it...

Now please process the following CV submitted by the user:

User message:

John Doe
125 Black Smith's St,
....

So the separation between the system setup and the data to work on is done naturally by separating them into diffrent messages.

3 Likes

This works extremely well, thank you. Is there anyway to have pre-defined chats with certain system message? Instead of sending for example thousands of lines in each request to tell the model what to do (if for example you want to include examples to train it)

On the go right now. Yes, this is possible with some fine-tuning done wisely. Check my messages about the approach and I’ll post something more specific after I get some time to do so.