Instruct assistant to split text into 2

This is the response I get from OpenAI Assistant API that I’ve created.
I’m building a translator.
I want to save original answer in a different field and the translation in the other one. How can I do this?

Ideally I’d instruct Assistant GPT to differentiate this 2 in separate JSON key/values but not sure it can do that.

I failed extracting separate texts using Regex patterns or splitting them by where \n\n is. Nothing seems to work… Can you point me into right direction?

  1. I would use the json mode to split out the reponses:
    https://platform.openai.com/docs/guides/text-generation/json-mode

  2. Unfortunately I don’t know if they had the foresight to include the json capabilities into the new assistant api’s.

  3. If you’re willing to use chat, here’s how I’d do it.

const completion = await openai.chat.completions.create({
        response_format: { type: "json_object" },
        model: defaultModel,
        messages: [{ "role": "system", "content": systemMessageForBot },
        {
            "role": "user",
            "content": `
                You are tasked with finding the field inside of this segment of html. 
                You must capture:
                - the prompt
                - the type of input (text, radio, etc.)
                - the recommended answer
                - a selector that would select that input for scripting purposes.
                - a set of actions to take on the element (a series of either "click" or "type" actions)
                (accessing the element in order to carry out the action)
                The response should be provided in json format, like so:

                A.) a text field asking for phone number:
                '''<div class="jobs-easy-apply-form-section__grouping><div class="fb-dash-form-element jobs-easy-apply-form-element mt4" style="width:100%" tabindex="-1" data-test-form-element=""><!---->        <div data-test-single-line-text-form-component="">  <div id="ember365" class="artdeco-text-input artdeco-text-input--type-text artdeco-text-input--color-default artdeco-text-input--state-required ember-view">  <div id="ember366" class="artdeco-text-input--container ember-view">  <label for="single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber" class="artdeco-text-input--label">Mobile phone number</label>  <input class=" artdeco-text-input--input" id="single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber" required="" aria-describedby="single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber-error" type="text"></div><!----><!----></div>  <div id="single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber-error"><!----></div></div><!---->  </div></div>'''
                The json describing the execution of the input is as follows:
                {
                    "prompt": "Phone Number",
                    "type": "phone",
                    "answer": "555-555-5555",
                    "actions": [
                        {
                            "actionType": "click",
                            "selector": "input[id='single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber']"
                        },
                        {
                            "actionType": "type",
                            "selector": "input[id='single-line-text-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824869-phoneNumber-nationalNumber']",
                            "actionValue": "281-407-0048"
                        },
                    ]
                }

                B.) a select field asking for email:
                '''<div class="jobs-easy-apply-form-section__grouping
                                "> 
                            <div class="fb-dash-form-element jobs-easy-apply-form-element mt1" style="width:100%" tabindex="-1" data-test-form-element="">
                    <!---->        <div data-test-text-entity-list-form-component="">
                        <label for="text-entity-list-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824877-multipleChoice" class="fb-dash-form-element__label
                            fb-dash-form-element__label-title--is-required" data-test-text-entity-list-form-title="">
                        <span aria-hidden="true"><!---->Email address<!----></span><span class="visually-hidden"><!---->Email address<!----></span>
                        </label>

                        <span class="visually-hidden" data-test-text-entity-list-form-required="">
                        Required
                        </span>
                    <select id="text-entity-list-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824877-multipleChoice" aria-describedby="text-entity-list-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824877-multipleChoice-error" aria-required="true" required="" data-test-text-entity-list-form-select="">
                        <option value="Select an option">
                            Select an option
                        </option>
                        <option value="email@protonmail.com">
                            email@protonmail.com
                        </option>
                        <option value="email@live.com">
                            email@live.com
                        </option>
                        <option value="email@gmail.com">
                            email@gmail.com
                        </option>
                    </select>
                    <!----></div>
                    <!---->  </div>
                    </div>'''

                The json describing the execution of the input is as follows:
                {
                    "prompt": "Email",
                    "type": "select",
                    "answer": "email@looneytunes.com"
                    "actions": [
                        {
                            "actionType": "select",
                            "selector": [id^="text-entity-list-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-"][id$="-multipleChoice"]",
                            "actionValue": "email@looneytunes.com"
                        },
                    ]
                }

                C.) a radio field asking a yes or no question:
                '''<div class="jobs-easy-apply-form-section__grouping            ">                    <div class="fb-dash-form-element jobs-easy-apply-form-element mt4" style="width:100%" tabindex="-1" data-test-form-element=""><!---->        <fieldset data-test-form-builder-radio-button-form-component="true" id="radio-button-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824821-multipleChoice" aria-describedby="radio-button-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824821-multipleChoice-error">    <legend>    <span data-test-form-builder-radio-button-form-component__title="" class="fb-dash-form-element__label        fb-dash-form-element__label-title--is-required">        <span aria-hidden="true"><!---->Are you comfortable commuting to this job's location?<!----></span><span class="visually-hidden"><!---->Are you comfortable commuting to this job's location?<!----></span>    </span>        <span class="visually-hidden" data-test-form-builder-radio-button-form-component__required="">        Required        </span>    </legend>    <div data-test-text-selectable-option="0" class="fb-text-selectable__option display-flex"><input data-test-text-selectable-option__input="Yes" id="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)-0" class="fb-form-element__checkbox" name="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)" aria-required="true" type="radio" value="Yes"><label data-test-text-selectable-option__label="Yes" for="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)-0" class="t-14">    <!---->Yes<!----></label></div>    <div data-test-text-selectable-option="1" class="fb-text-selectable__option display-flex"><input data-test-text-selectable-option__input="No" id="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)-1" class="fb-form-element__checkbox" name="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)" aria-required="true" type="radio" value="No"><label data-test-text-selectable-option__label="No" for="urn:li:fsd_formElement:urn:li:jobs_applyformcommon_easyApplyFormElement:(3758101698,103824821,multipleChoice)-1" class="t-14">    <!---->No<!----></label></div></fieldset><div id="radio-button-form-component-formElement-urn-li-jobs-applyformcommon-easyApplyFormElement-3758101698-103824821-multipleChoice-error"><!----></div><!---->  </div></div>'''
                The json describing the execution of the input is as follows:
                {
                    "prompt": "Are you comfortable commuting to this job's location?",
                    "type": "radio",
                    "answer": "Yes",
                    "actions": [
                        {
                            "actionType": "click",
                            "selector": "label[data-test-text-selectable-option__label='Yes']"
                        }
                    ]
                }

                Here is the segment of interest containing the field:
                ${segmentofInterest}
                The json describing the execution of the input is as follows:
            `},
        ],
    });

Notice how i specified json mode and then gave several examples (each being for a slightly diff use case)

Yeah I think it has function calling capabilities which I could probably use. Not sure. Anyway I’m trying for simpler solutions tbh. And thanks for your suggestion :pray:

1 Like

Sh** you just inspired another solution. Instead of asking in 1 call to respond and to translate I’ll just do a separate call for translation.

1 Like

yeah, breaking down steps/questions into smaller ones seems to be the way to get around a lot of the problems with chatgpt.

1 Like