Passing parameter to API call in serverconnect

Hi guys,

I just lost an entire day trying to solve a problem (that i am sure is super simple) before giving up and asking here now:

I have a form to generate an email using chatGPT with a few options and a template list. When clicking on generate I generate a message in a js function and depending on the options selected by the user that would look like that:

emailText = “You are a helpful assistant that writes emails for a real estate agent, for real estate transactions in French using a provided template. You can modify the template. Always be polite. Mention that the deadline is past since -41 days. Mention the transaction name: Maison de Bel Airs. he name of the person you are writing to is: Olivia Durand.”

I am trying to pass that value to my serverconnect, but i just cannot. I have tried regular variable, localStorage, sessions nothing works. My API call to openAI is good it works well when i hardcode the message.

so to put it simply lets say I run the following code when clicking on a button:

function generateMessage(){
emailText = ‘A message’;
return emailText;
}

How can i then pass it to my serverconnect generateGPT.load({messagetext: ???})

I have also tried to run the serverconnect from my function but nothing happens, it looks like the line is ignored:

function generateMessage(){
emailText = ‘A message’;
dmx.parse(generateGPT.load({messagetext: emailText}));
}

Thank you

Hello! You can use dmxset on your js like
dmx.app.set('MyMessage', emailText);

So then you can use {{MyMessage}} on app connect

Thanks but it still doesn’t work. i am wondering if it’s not the scope of my js function.

Here is the function:

function generateMessage(){
emailText = ‘A message’;
dmx.app.set(‘MyMessage’, emailText);
}

Here is the API body:

{
“model”: “gpt-4-turbo”,
“messages”: [
{
“role”: “system”,
“content”: “You are an assistant”
},
{
“role”: “user”,
“content”: “{{MyMessage}}”
}
]
}

and the api error:

  1. error: {message: “Invalid value for ‘content’: expected a string, got null.”, type: “invalid_request_error”,…}

  2. code: null

  3. message: “Invalid value for ‘content’: expected a string, got null.”

  4. param: “messages.[1].content”

  5. type: “invalid_request_error”

How are you calling the function?
Can you just test this paragraph <p>{{MyMessage}}</p>

for testing purpose i have added a button to call the function. using p worked

Maybe it’s a timing issue, what about running a flow? So you execute the js and then the server connect?

1 Like