CONVA api (Delete backstory)

Original Discord Post by luis_gabina | 2024-04-04 11:13:23

Hi, I am developing a simulator for the initial training of workers at an alarm monitoring center. I want to use convai to create telephone interaction with customers. For this reason I need to change the backstory at runtime to pass it the context and data of that client, that data is generated at runtime. Via api I can only update the backstory but I cannot delete the previous content. Do you plan to implement this utility?

Reply by devrelruss | 2024-04-05 18:02:35

Hi <@1052576219343900693>, just to confirm, your issue is that when you use Character Base API | Documentation to update the backstory, it only appends the new backstory, but does not replace it entirely?

Embedded Content:
Character API | Documentation
All the available APIs needed to create your own intelligent character with Convai.
Link: Character Base API | Documentation

Reply by luis_gabina | 2024-04-10 07:37:09

Hi <@996494873920286770> , that’s exactly. only expands the original information but does not allow you to delete and put totally different information in each update. In my case, the idea was to have prototypical characters with different narrative designs and update their contextual information in runtime, but with the current API functionalities it is not possible. I’ve tried to create new characters in every interaction even if it’s not viable in production, the characters would grow exponentially and there’s no way to erase them in runtime. Even doing this, I run into the difficulty that I can’t set up the Spanish speech recognition in the runtime

using StringContent jsonContents = new(
JsonSerializer.Serialize(new
{
charID = personajeID.characterID,
voiceType = “JennyMultilingualV2Neural”,
language_codes = new string { “es-ES” }

}),
Encoding.UTF8,
"application/json");

var response2 = await httpClient.PostAsync(“https://api.convai.com/character/update”, jsonContents);

Reply by mrnightx.exe | 2024-04-13 01:38:45

Hi, may I know how do you update the backstory from unity?

Reply by k3kalinix | 2024-04-14 20:04:25

Examples in C#:
Create character:

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class CreateCharacter : MonoBehaviour
{
    private string apiUrl = "https://api.convai.com/character/create";
    
    // Use this for initialization
    void Start()
    {
        StartCoroutine(CreateCharacterCoroutine());
    }
    
    IEnumerator CreateCharacterCoroutine()
    {
        var charData = new
        {
            charName = "Raymond",
            voiceType = "MALE",
            backstory = "Raymond Reddington is a main character in the NBC series The Blacklist. Reddington is a criminal mastermind, making it to #4 and later to #1 on the FBI's Ten Most Wanted Fugitives, who suddenly turns himself in after 20+ years of evading the FBI."
        };
        
        string jsonData = JsonUtility.ToJson(charData);
        
        using (UnityWebRequest request = UnityWebRequest.Post(apiUrl, jsonData))
        {
            request.SetRequestHeader("CONVAI-API-KEY", "<your api key>");
            request.SetRequestHeader("Content-Type", "application/json");
            request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonData));
            request.downloadHandler = new DownloadHandlerBuffer();
            
            yield return request.SendWebRequest();
            
            if (request.result != UnityWebRequest.Result.Success)
            {
                Debug.Log(request.error);
            }
            else
            {
                Debug.Log("Character created: " + request.downloadHandler.text);
            }
        }
    }
}```


**Update Character:**

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class UpdateCharacter : MonoBehaviour
{
    private string apiUrl = "https://api.convai.com/character/update";
    
    // Use this for initialization
    void Start()
    {
        StartCoroutine(UpdateCharacterCoroutine());
    }
    
    IEnumerator UpdateCharacterCoroutine()
    {
        var charData = new
        {
            charID = "<character ID>",
            backstory = "Updated backstory for Raymond Reddington...",
            voiceType = "MALE",
            charName = "Raymond Reddington",
            language_codes = new string[] { "en-US" }
        };
        
        string jsonData = JsonUtility.ToJson(charData);
        
        using (UnityWebRequest request = UnityWebRequest.Post(apiUrl, jsonData))
        {
            request.SetRequestHeader("CONVAI-API-KEY", "<your api key>");
            request.SetRequestHeader("Content-Type", "application/json");
            request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonData));
            request.downloadHandler = new DownloadHandlerBuffer();
            
            yield return request.SendWebRequest();
            
            if (request.result != UnityWebRequest.Result.Success)
            {
                Debug.Log(request.error);
            }
            else
            {
                Debug.Log("Character updated: " + request.downloadHandler.text);
            }
        }
    }
}

This conversation happened on the Convai Discord Server, so this post will be closed.