Create Knowledge Base Article with API

Hello,
I have a question. We want to connect a LLM that answers incoming chat questions.
For this the answer of the LLM should be combined with the incoming question. From this a knowledge base article should be created.

What is the easiest way to create an article via API, I have the API "Create Document" but can't add a body - only title, categories, variations, visibility.

The title should be the question that was entered and the body the answer of the LLM's but I can't find a way to add the body except through the API Create a variation for a document. The goal is for our experts to be able to generate articles from the LLM's answers and for us to go the LLM route only if no corresponding article is found.

Many thanks in advance

1 Like

I haven't been able to track down an answer to this, but I'm still asking around. I have a hunch it has to do with POST /api/v2/knowledge/documentuploads, which gives you a signed URL to upload a file. The dots I can't connect are how that uploaded file becomes related to a document. The upload endpoint doesn't allow you to specify a document ID and the document endpoints don't allow you to specify a link to the uploaded file. If I don't respond back to this tomorrow, please open a case with Genesys Cloud Care to report missing documentation for the knowledge APIs as the current docs don't explain this concept.

@Felix I've found an answer. "content" isn't called content, it's called a "variation". You upload your "variation" using POST /api/v2/knowledge/knowledgebases/{knowledgeBaseId}/documents/{documentId}/variations.

2 Likes

Is it really the case that there isn't an html parser built into the SDKs? I looked at what it would take to build a variation and it is a pretty tedious lift to write yet another html parser just to load a document / document variation.

For example building a DocumentBody with the following components:

    DocumentBody,
    DocumentBodyBlock,
    DocumentBodyImage,
    DocumentBodyImageProperties,
    DocumentBodyList,
    DocumentBodyListBlock,
    DocumentBodyListBlockProperties,
    DocumentBodyListItemProperties,
    DocumentBodyParagraph,
    DocumentBodyParagraphProperties,
    DocumentBodyTable,
    DocumentBodyTableCaptionBlock,
    DocumentBodyTableCaptionItem,
    DocumentBodyTableCellBlock,
    DocumentBodyTableCellBlockProperties,
    DocumentBodyTableProperties,
    DocumentBodyTableRowBlock,
    DocumentBodyTableRowBlockProperties,
    DocumentBodyVideo,
    DocumentBodyVideoProperties,

Or am I misunderstanding, missing a simple interface, documentation on how to do it?

I am using the Python SDK currently.

The SDKs are generated based on the API's definition; they only provide a language-specific implementation of the exact contract of the REST API. The variations endpoint above requires JSON content.

Thanks for the quick response.

Do you know offhand beyond the autogenerated SDKs if there is a helper library that is able to generate the JSON from html using the SDKs api/json?

For example to make a simple DocumentVariation:

from lxml import html
from typing import List
import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.models import m
from m import (
    DocumentBody,
    DocumentBodyBlock,
    DocumentBodyImage,
    DocumentBodyImageProperties,
    DocumentBodyList,
    DocumentBodyListBlock,
    DocumentBodyListBlockProperties,
    DocumentBodyListItemProperties,
    DocumentBodyParagraph,
    DocumentBodyParagraphProperties,
    DocumentBodyTable,
    DocumentBodyTableCaptionBlock,
    DocumentBodyTableCaptionItem,
    DocumentBodyTableCellBlock,
    DocumentBodyTableCellBlockProperties,
    DocumentBodyTableProperties,
    DocumentBodyTableRowBlock,
    DocumentBodyTableRowBlockProperties,
    DocumentBodyVideo,
    DocumentBodyVideoProperties,
)

Example SDK helper:

def parse_html(html_body):
     return  some_lxml_parsing_to_sdk_objects(html_body)
dv = DocumentVariation()
dv.body = DocumentBody()
dv.body.blocks = []
block1 = DocumentBodyBlock()
block1.type = 'Paragraph'
block1.paragraph = DocumentBodyParagraph()
block1.paragraph.blocks = []
p1cont = DocumentContentBlock()
p1cont.type = 'Text'
p1cont.text = DocumentText()
p1cont.text = 'hello world'
block1.paragraph.blocks.append(p1cont)
dv.body.blocks.append(block1)
print(f"this seem like too much to be the right way to create a DocumentVariation: {dv}"

For some html like this:

<body>
    <p>hello world</p>
</body>

There's nothing available yet, but there's an intent: MyPureCloud/knowledge-html-converter · GitHub. I'll track down the owners and see if there's a roadmap estimate.

1 Like

In the meantime, if you're up for the task, you could use something like rehype to parse your HTML and generate an AST to upload. Parsing the HTML with that tool is the easy part. Normalizing the AST to the same structure the Genesys API accepts is going to be a source of unending fun. Presumably the repo linked above will help take some of that fun off your plate in the future.

1 Like

That repo is tentatively scheduled for release in October. You can watch the repo on github to get notified when content is pushed.

1 Like

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