Add support to PROPER() formula suggestion

I’m writing to suggest adding support for the PROPER() formula. This formula is a standard Excel function that capitalizes the first letter of each word in a text string. It’s a very useful formula for formatting text, and it would be great to have it available in Coda as well.

Here is an example of how the PROPER() formula could be used in Coda:

Column1 = "JAMES smith"
Column2 formula = Column1.Proper()
Column2 result = "James Smith"

This formula would capitalize the first letter of each word in the text string in column1.

I believe that adding support for the PROPER() formula would be a valuable addition to Coda. It would make it easier for users to format text, and it would be consistent with the Excel formula set that many users are already familiar with.

1 Like

Proper() would be a nice addition, but it needs a 2nd parameter, an exception list (“van”, “de”, “der”, “d’”, “bin”, “al-” ) and some more.
Examples:
John de Winter, Jeanne d’Arc, Bill van der Made, Mohammad bin Salman al-Saoed, and so on.

2 Likes

that would be a very nice addition! A plus effort for the coda team for an extra mile nifty feature! :pray:t3:

And this is where a [seemingly] simple feature becomes a big time sync. :wink: There’s no end to the possible exceptions - too many to be sure and costly to implement and maintain.

More parameters are like more buttons and parts. I vote for fewer buttons and parts, but how?

This is where AGI plays well. It has the ability to infer the right transformation given almost zero context. Imagine a prompt that is constructed dynamically as the formula is fired - it factors in such things as the users OS language, the locality, and other sensitivities to construct the perfect rendering of the name.

This is the type of AI that changes products. It’s the subtle, under-the-covers features that no one sees as AI and thus, it is both magical and subliminal.

Implementing this in a Pack is near-trivial, but ideally, a native formula would be better suited to deliver this functionality.

1 Like

Hey @Bill_French ,

I agree for the most part. Is there already a possibility to incorporate AI functionality in CFL?

Obviously, in my suggestion, the 2nd parameter would actually be a column reference to a setup table that would be easy to maintain for different localities.

If the job can be done with AI it certainly would be easier, but a formula gives you 100% repeatable results, I am not so sure about AI.

It is going to take a while longer for me to think AI first, but there are definitely advantages.

You mean like an HTTP POST (or GET) formula? If there is, I somehow missed this game-changing interface. But I suspect you’re referring to a Coda formula in the AI Pack? If so, all of what I did below is possible using ChatGPT - I just wanted to prove the approach using the free PaLM AI models.

Indeed it does, but it comes with all the rigidity and complications of an inferencing process that may encounter unanticipated texts.

My hunch is a temperature setting of zero would make it fully deterministic and consistent. But in LLM land there always a risk of bias despite the LLM being trained on the broad content of the Interwebs. This is both a curse and a blessing.

A good example:

Mohammed bin Rashid al-Maktoum

It’s acceptable in Arab culture to express “al” (i.e., “the”) as a lowercase, hyphenated value. But the common use is capitalized without the hyphen. An AI solution would choose the latter, but both are acceptable (apparently). I say “apparently” because I’m not an international scholar in matters of addressing UAE royalty. :wink:

But even this case can be enforced as a rule assertion in the AI prompt. It depends on your own interpretation of the name formats. Perhaps these could also be surfaced as configurators to the formula.

The beauty of LLMs is they already factor in localities and cultural perspectives as well as languages. Consider this list - it has many places where I attempt to trip up the AI. I butchered this one and it figured it out.

Pack Code

This is the Pack I created to test this hypothesis. There are many ways to approach this using AI; I was biased toward Google’s AGI services for many reasons.

/*

   ***********************************************************
   ProperName : A Coda Column Format that embraces the proper 
                capitalization of names.
   Copyright (c) 2023 by Global Technologies Corporation
   ALL RIGHTS RESERVED
   ***********************************************************

*/

// import the packs sdk
import * as coda from "@codahq/packs-sdk";

// create the pack
export const pack = coda.newPack();

var cPaLMAPIKey   = "<your PaLM API key goes here>";
var cPaLMEndpoint = "https://generativelanguage.googleapis.com/v1beta2/models/";
var oResponse;

// set the network domain
pack.addNetworkDomain('generativelanguage.googleapis.com');

// ################################################################
//
// properName
//
// ################################################################
pack.addColumnFormat({
  name: "properName",
  instructions: "This column formula formats names into proper case names.",
  formulaName: "properName",
});

//
// define the column formula
//
pack.addFormula({

  resultType : coda.ValueType.String,

  name: "properName",
  description: "The name to format.",
  cacheTtlSecs: 0,

  parameters: [

    // cell content
    coda.makeParameter({
      type: coda.ParameterType.String,
      name: "nameString",
      description: "The name string.",
    }),

  ],

  // execute the formula
  execute: async function ([nameString], context) {

    console.log('nameString: ' + nameString);
    console.log(JSON.stringify(context));

    if (nameString) {

      var expression = "123"
      var text = `string text ${expression} string text`;

      var prompt = `
        Reformat this name using the proper name convention without explanations. 
        Do not assume that hypenated names are surnames. 
        Include only the name in the response. 
        Do not include any other text in the response.
        Do not reorder the name parts. Use the proper formatting for the origin country of the person. 
        Return a consistent output format according to the examples.

        Examples

        Name: Mohammad bin Salman Al Saud
        Output: Mohammad bin-Salman al-Saud

        Name: Jean Paul Sartre
        Output: Jean-Paul Sartre

        Name: Jeanne D’arc
        Output: Jeanne d'Arc

        Name: Kim Jong UN
        Output: Kim Jong-un

        Name: ${nameString}\nOutput:`;

      let thisPromise = await palmCreateTextCompletion(prompt, context)
        .then(json => {
          oResponse = json;
      });

      var thisResponse = await oResponse;
      var result = await thisResponse.body.candidates[0].output;

      return(result);

    } else {

      return("Name not provided to the formula.");

    }

  },

});


//
// PaLM TEXT COMPLETION
//
async function palmCreateTextCompletion(str, context)
{

  var url = cPaLMEndpoint + "text-bison-001:generateText?key=" + cPaLMAPIKey;

  var body = {
    "prompt": {
      "text" : str
    },
    "temperature": 0,
    "candidate_count": 1,
    "max_output_tokens" : 512,
    "top_k" : 4,
    "top_p" : 0.8,
  }

  const response = await context.fetcher.fetch( {
    url     : url,
    method  : 'POST',
    headers: {
      'Content-Type' : 'application/json'
    },
    'body' : JSON.stringify(body)
  });

  return(response);
}

4 Likes

Thank you for your answer and thank you for sharing the sample code: inspiring and enlightening!