Is grammar check API for German language available?

Is grammar check API for German language available? If so - where can I find API call examples (NodeJS or another language)?

You can write Prompt: Correct the grammar in this text: “Danke für das Telefonat, aber ich sende Ihnen unser Angebot.”

and the answer is “Vielen Dank für das Telefonat. Ich sende Ihnen jedoch unser Angebot zu.”

:grinning:

1 Like

Thank you! Is the request generally sent like this? OpenAI API

It’s an invitation to model text-davinci-003. I’m not sure how well he knows German grammar. I think it is better to use the gpt-3.5-turbo model because it is better and cheaper.

1 Like

In order to use it, should we just change “model” parameter or any other adjustments needed?

ChatGpt is a new API and uses something different. This is the link to the documentation.

If you program with C#, I can make you a mini example for calling this API

That would be great (we will easily move it to NodeJS than)!

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace TestChatGpt
{
class Program
{
static async Task Main(string args)
{
string instructions = string.Empty;
string userMessage = string.Empty;
ChatGptResult result;

        // Example 1 - correcting grammar
        instructions = "Überprüfen und korrigieren Sie grammatikalische Fehler im Text.";
        userMessage = "Vielen Dank fĂźr dad Telefonat. Ich sende Ihnen jedoch unsere angebot zu.";
        result = await CreateCompletionChatGptAsync(instructions, null, userMessage);

        // Example  - chatbot with multiple interactions
        instructions = "I am a chatbot specialist for tourism in Germany";
        var conversation = new List<ChatGptMessage>();
        conversation.Add(new ChatGptMessage() { role = "user", content = "What is the capital of Germany?" });
        conversation.Add(new ChatGptMessage() { role = "assistant", content = "The capital of Germany is Berlin?" });
        userMessage = "How many inhabitants are there?";
        result = await CreateCompletionChatGptAsync(instructions, conversation, userMessage);

    }
    
    public static async Task<ChatGptResult> CreateCompletionChatGptAsync(string instructions, List<ChatGptMessage> conversations, string userMessage)
    {
        string _engineName = "gpt-3.5-turbo";
        string _apiKey = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx";
        
        ChatGpt3Request request = new ChatGpt3Request() { model = _engineName };

        if (instructions != string.Empty)
            request.messages.Add(new ChatGptMessage() { role = "system", content = instructions });
        
        if (conversations != null && conversations.Count() > 0)
            request.messages.AddRange(conversations);

        request.messages.Add(new ChatGptMessage() { role = "user", content = userMessage });
        

        ChatGptResult result = new ChatGptResult();
        int retries = 0;
        bool success = false;
        while (!success && retries < 3)
        {
            try
            {
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _apiKey);
                client.DefaultRequestHeaders.Add("User-Agent", "okgodoit/dotnet_openai_api");

                string jsonContent = JsonConvert.SerializeObject(request, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
                var stringContent = new StringContent(jsonContent, UnicodeEncoding.UTF8, "application/json");
                var response = await client.PostAsync($"https://api.openai.com/v1/chat/completions", stringContent);

                if (response.IsSuccessStatusCode)
                {
                    success = true;
                    string resultAsString = await response.Content.ReadAsStringAsync();
                    var resultObject = JsonConvert.DeserializeObject<OpenAiChatGptResult>(resultAsString);
                    result.Answer = resultObject.choices[0].message.content;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("API call failed: " + ex.Message);
            }

            if (!success)
            {
                retries++;
                Console.WriteLine("Retrying API call in 2 seconds...");
                await Task.Delay(2000);
            }
        }
        if (!success)
        {
            throw new Exception("API call failed after 3 retries");
        }
        return result;
    }
}

public class ChatGptResult
{
    public string Answer { get; set; }
}

class ChatGpt3Request
{
    public string model { get; set; }
    public List<ChatGptMessage> messages { get; set; } = new List<ChatGptMessage>();
}

public class ChatGptMessage
{
    public string role { get; set; }
    public string content { get; set; }
}

public class OpenAiChatGptResult
{
    public string id { get; set; }
    public string @object { get; set; }
    public int created { get; set; }
    public string model { get; set; }
    public UsageChatGpt usage { get; set; }
    public List<ChoiceChatGpt> choices { get; set; }
}
public class ChoiceChatGpt
{
    public Message message { get; set; }
    public string finish_reason { get; set; }
    public int index { get; set; }
}
public class Message
{
    public string role { get; set; }
    public string content { get; set; }
}
public class UsageChatGpt
{
    public int prompt_tokens { get; set; }
    public int completion_tokens { get; set; }
    public int total_tokens { get; set; }
}

}

Great! My developer already done NodeJS version, which works good. Here it is:

`const { Configuration, OpenAIApi } = require(“openai”);

const configuration = new Configuration({
//Insert Your Api Key Here
apiKey: ‘Instert Your Api Here’,
});
const openai = new OpenAIApi(configuration);

async function checkGrammar(text) {
const response = await openai.createCompletion({
model: “text-davinci-003”,
prompt: Correct this to standard German Grammer:\n\n${text},
temperature: 0,
max_tokens: 60,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});

// console.log(response);
// console.log(response.data);
// console.log(response.data.choices);
//console.log(response.data.choices[0]);

const correctedText = response.data.choices[0].text.trim();
return correctedText;
}

//you can paste english,german or any language here and it will give you answer in german
checkGrammar("chhatrapalsinh my name is ")
.then((correctedText) => console.log(correctedText))
.catch((error) => console.log(error));
`