0

I am trying to write an application in c# that allows me to post a snippet of code to the textsynth api.

try
        {
            using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.textsynth.com/v1/engines/gptj_6B/completions"))
            {
                request.Headers.TryAddWithoutValidation("Authorization", "Bearer API_KEY");
                request.Content = new StringContent("{\"prompt\": \"" + message.Replace("\n", "\\n") + "\", \"max_tokens\": " + textBox2.Text + " }");
                request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                this.Text = "Waiting for AI response...";
                var response = await httpClient.SendAsync(request);

                var jsonData = await response.Content.ReadAsStringAsync();
                MessageBox.Show(jsonData);
                AiResponse aiResponse = JsonConvert.DeserializeObject<AiResponse>(jsonData);
                previousReponse = aiResponse.text;
                return aiResponse.text;

            }
        } catch (Exception e)

the message string contains as an example:

t = 0, p = 0, q = 0;

int num1, num2;

cout << "enter two numbers" << endl;
cin >> num1 >> num2;

t = t + num1;

The API will return this message to me:

expecting ',' or '}'

I know this has to do with request.Content = new StringContent("{\"prompt\": \"" + message.Replace("\n", "\\n") + "\", \"max_tokens\": " + textBox2.Text + " }");

and im sure its has to do with the format of the code im sending into the json. any help?

0 Answers0