Sentence case in German

I suspect this is a very difficult, if not impossible one. In German, as is well known, adjectives, pronouns and adverbs are written with a lower case letter but substantives with a capital letter. This implies that in a German text, the extension “Sentence Case” is not usable. Is it possible (I wouldn’t know how) to solve this problem? Perhaps a tip: all words, where you can put der, die or das before them (and in all four cases): e.g. der Mann, die Frau, das Kind, das Schönste [=the most beautiful], das Wichtigste [=the most important] are capitalised.

A tough challenge for a hand coded algorithm but I reckon maybe it’s easy for a generative AI. I took my GPT-3 extension and modified it thus:

// #popclip
// name: DE Sentence (OpenAI)
// icon: circle de
// language: javascript
// after: paste-result
// entitlements: [network]
// options: [{identifier: apikey, label: API Key, type: string,
//   description: 'Obtain API key from https://platform.openai.com/account/api-keys'}] 
const openai = require("axios").create({
  baseURL: 'https://api.openai.com/v1/',
  headers: { Authorization: `Bearer ${popclip.options.apikey}` }
});
const { data } = await openai.post('edits', {
  model: 'text-davinci-edit-001',
  input: popclip.input.text,
  instruction: "Render this sentence with correct German capitalization"
});
return data.choices[0].text;

(The above block is an extension snippet - select the text it then click “Install Extension” when PopClip appears.)

Please note you will need to sign up for an account with OpenAI via https://openai.com/api/, and then get your API key from https://platform.openai.com/account/api-keys to insert in the extension config.

Testing it with the following sentence:

können sie mir helfen? ich feiere meinen geburtstag.

Können Sie mir helfen? Ich feiere meinen Geburtstag.

CleanShot 2023-02-22 at 12.45.23

So there we go! Looks promising.

1 Like

Unfortunately, the extension does not work for me. I tested different texts and nothing changes at all when I select the extension in PopClip.

This works perfect for me! , thank you very much, @nick

@Koen: you have first to make an extension. Before the extension is installed in PopClip, login with your account into OpenAI API and create your personal API-Key for that extension. Now you can put in that API-Key for your new extension!

I tested the extension with an old Goethe text and with a german Wikipedia text for Tolstois «Krieg and Frieden». It works!

(Text is limited to 512 characters, as coded in @nick ´s snippet. Is this a fixed limitation, @nick ?)

I think this could open a wide array of new functions for PopClip! :slight_smile:

1 Like

Not at all, you can put anything you like. What that controls is the max number of “tokens” GPT will produce in the output. In general it’s useful for controlling the length of the output.
But in this case, it would make more sense to actually set that to the number of words in the input text plus some amount of buffer. I’ll edit my code to do that.

I know right? Head is spinning with possibilities … the key will be to bring this to the non-programmers in an easy way. Maybe to begin with simply a web page “Type what you want your extension to do” that will spit out a pre-packaged extension. I’m planning to make a “make your own extension” webpage anyway that will be an easy, visual interface to making snippets, so could incorporate it into that.

Also I’m interested in the possibility of teaching GPT with examples of popclip extensions and actually get it to write an extension’s code, rather than act as the backend. It’s all rather interesting in this new world. So much to do so little time…

1 Like

@Koen apologies for how technical this is. I’d like to make a more accessible version of this eventually, but this is all very experimental and new. However, as long as you can sign up for an OpenAPI account and obtain an API key (see links above), it should then be fairly straightforward.

I think the first text I tried might have been too long. With a shorter text, the extension rather worked. I’m just not sure yet whether I should create another account with that OpenAPI or not. The first time I got some kind of “token” there once (which works) but now when I want to create an account (which may be unnecessary) I apparently have to pay for it. I therefore interrupted the registration process. Indeed, as a non-developer, this is all rather complex for me.

1 Like

I see now that I had landed on the wrong site (https://www.openapis.org)! Not quite awake yet apparently and haven’t had coffee yet…

I now just had to mention you great attempt at Keyboard Maestro Forum, sorry for that! :slight_smile: , see
https://forum.keyboardmaestro.com/latest

2 Likes

Oh no – that’s like saying Voldemort out loud! Just kidding; welcome KM folk.

2 Likes

Just a little update. I discovered a different API endpoint that is more suited for this kind of task, using “edits” rather than “completions”.

It works pretty much the same, but it should perform a little better.

I’ve updated the code in the original post.

1 Like

Thanks a lot!