Convert GPT output to excel/split strings

Hello everybody,

I have used the GPT Generate Text Completion to get an output. I saved the output (in the properties ot the GTC activity) to an variable called ‘response_text’. Then i use a message box with the command ‘response_text.tostring’ wich shows me the output text of the prompt. That works fine. I prompted GPT to set the text into a list of numbers like:

“1. firstname
2. lastname
3. country”

and so on. That works. The messagebox shows me a list of 9 numbers with text behind it. Now I want each number in a different cell in Excel. So i used the multiple assign activity to assign ‘firstname’ to response_text.split("1."c).tostring .

But when i use a message box with the command firstname.tostring to display ‘firstname’ it says ‘system.string’. What approach is best to get all of these numbered text into a differtent excel column?

Hi @tech2 ,

The Expression used is to convert a String into an Array of String. To access each individual split we would have to use Indices or if first split is needed you would need to assign it like below :

firstname = response_text.split("1."c)(0).tostring

Would recommend to check the expressions and the outputs and their types/representations in the Immediate Panel using Debug first, so that we can arrive at a conclusion of what is the right Split to be used. More on Debugging below :

thank you very much for the clear explanation. It works. Now it splits en it shows me the splitted text (0). How can I split text between 2 words? So that I cancreate a variable for each number in the list (like for 1. and 2. and 3. )

@tech2 ,

For Starters and to be more precise, could you provide us with a Sample Text/Input and provide us with the Expected Output from it ?

Do also provide us with the Expression that was working for you, so that we can modify the same expression for the other fields and keep it in sync.

Well the input is a large text document, and GPT summarizes the document into:

  1. firstname
  2. lastname
  3. city
  4. country
  5. description
  6. wishes

and so on. So i want te assign 1 variable for each number (1 for 1. firstname, 1 for 2. lastname, 1 for 3. city and so on) so that in the end i can write each variable to an excel column.

How would I split it?

@tech2 ,

Maybe a regex would be a better option :

System.Text.RegularExpressions.Regex.Match(InputText,"(?<=1.).*").Value

You can just replace 1. with 2. to get the value for 2. field and assign it to a separate variable.

thank you. And if i would like to do it without regex? How would the command look like? is it variable.split("2.-3."c)(0) ?

@tech2 ,

The Expressions would be a bit lengthy, Could also do with Substring After individual Line Split :

InputText.Split(Environment.NewLine.ToCharArray)(0).TrimStart("1.".ToCharArray)

i now used Split((Split(Response_Text,“1.”)(1).ToString),“2.”)(0).ToString

and it works fine.

thanks!

@supermanPunch

Now I have about 10 assigned variables. How to write each one of them to a column in Excel? What is the easiest approach?

@tech2 ,

We could use Add Data Row activity and populate the datatable (A Datatable Schema need to built) for each GPT Output.

Also, We do confirm that you are able to use the expressions for Splitting of the GPT Output string. So the initial Topic Query was addressed and Solved.

We would encourage you to create a Separate Topic on the Writing data to Excel or Populating the Datatable, so that we can separate the topics and get better help from other users as well.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.