Conversation Parsing

The SDKs contain nifty tools to help you with converting a blob of unstructured text into a conversation format

Let's say you have the input conversation unstructured in a text file that looks like:

Josh 00:00
Do you like math?

Mellisa 00:02
I like it but I'm not so good at it.

Let's also say that you want to parse this text into One AI conversation format so you can analyze it.
Here is what you do:

const OneAI = require("oneai");
const fs = require("fs");

const oneai = new OneAI("<YOUR-API-KEY-HERE>");

const text = fs.readFileSync("<YOUR-FILE-PATH>", {encoding: "ascii"});
const conversation = oneai.Conversation.parse(text)

console.log(conversation)
# pip install oneai
import oneai
import base64

oneai.api_key = "<YOUR-API-KEY-HERE>"

with open("<YOUR-FILE-PATH>", "r") as f:
  text = f.read()

pipeline = oneai.Pipeline(
  steps = [
    oneai.skills.Summarize()
  ]
)

conversation = oneai.Conversation.parse(text)

print(conversation)

which results in

Conversation {
  type: 'conversation',
  contentType: 'application/json',
  text: [
    {
      speaker: 'Josh',
      utterance: 'Do you like math?',
      speaker_line: 0,
      text_line: 1,
      speaker_length: 10
    },
    {
      speaker: 'Mellisa',
      utterance: "I like it but I'm not so good at it.",
      speaker_line: 3,
      text_line: 4,
      speaker_length: 13
    }
  ]
}

Did this page help you?