C
C#10mo ago
KayJs

❔ What is problem?

using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace GenesisAPIFormApplication { public partial class Form1 : Form { private string apiUrl = "https://cluster-2.pudochu.repl.co/api/genesis"; private HttpClient httpClient = new HttpClient(); public Form1() { InitializeComponent(); } private async void button1_Click(object sender, EventArgs e) { // Sabit bir metin kullanarak API'ye metin gönderme işlemi string prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: " + "selam" + "\nJarvis:"; try { var content = new StringContent($"{"prompt": "{prompt}", "model": "text-dream-001"}", Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync(apiUrl, content); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); MessageBox.Show(responseString); } else { MessageBox.Show($"HTTP Hata Kodu: {response.StatusCode}"); // HTTP hata kodunu burada işleyebilirsiniz. } } catch (Exception ex) { MessageBox.Show("İstek gönderilirken bir hata meydana geldi: " + ex.Message); } } } }
46 Replies
Angius
Angius10mo ago
Idk, what is the problem? Does it crash? BSOD your PC? Make your plants wither?
KayJs
KayJs10mo ago
if clicked buton1 say in the html code : SyntaxError: Unexpected token in JSON at position 71 at JSON.parse (<anonymous>) at parse (/home/runner/Cluster-2/node_modules/body-parser/lib/types/json.js:92:19) at /home/runner/Cluster-2/node_modules/body-parser/lib/read.js:128:18 at AsyncResource.runInAsyncScope (node:async_hooks:203:9) at invokeCallback (/home/runner/Cluster-2/node_modules/raw-body/index.js:238:16) at done (/home/runner/Cluster-2/node_modules/raw-body/index.js:227:7) at IncomingMessage.onEnd (/home/runner/Cluster-2/node_modules/raw-body/index.js:287:7) at IncomingMessage.emit (node:events:513:28) at IncomingMessage.emit (node:domain:489:12) @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius10mo ago
You're doing some JSON parsing somewhere, not anywhere within this code though And that's throwing an error Because whatever JSON you're trying to handle is not valid
Pobiega
Pobiega10mo ago
at parse (/home/runner/Cluster-2/node_modules/body-parser/lib/types/json.js:92:19)
this is a clientside error
KayJs
KayJs10mo ago
ı am how to fix the problem (my english bad sorry :D)
Angius
Angius10mo ago
I'd start by sending actual proper JSON, and not a string masquerading itself as JSON
KayJs
KayJs10mo ago
how?
Angius
Angius10mo ago
You should make a model for the data you're sending, then send that using PostAsJsonAsync() For example:
class DataModel
{
[JsonPropertyName("name")]
public string Name { get; init; }
[JsonPropertyName("surname")]
public string Surname { get; init; }
}

var data = new DataModel {
Name = "Bob",
Surname = "Bobbit"
};

var response = await _client.PostAsJsonAsync(url, data);
class DataModel
{
[JsonPropertyName("name")]
public string Name { get; init; }
[JsonPropertyName("surname")]
public string Surname { get; init; }
}

var data = new DataModel {
Name = "Bob",
Surname = "Bobbit"
};

var response = await _client.PostAsJsonAsync(url, data);
KayJs
KayJs10mo ago
thanks
KayJs
KayJs10mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius10mo ago
Show code
KayJs
KayJs10mo ago
using System; using System.Net.Http; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Http.Json; // Uzantı kitaplığı namespace GenesisAPIFormApplication { public partial class Form1 : Form { private string apiUrl = "https://cluster-2.pudochu.repl.co/api/genesis"; private HttpClient httpClient = new HttpClient(); public Form1() { InitializeComponent(); } private async void button1_Click(object sender, EventArgs e) { // Sabit bir metin kullanarak API'ye metin gönderme işlemi string prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:"; try { var response = await httpClient.PostAsJsonAsync(apiUrl, new { prompt = prompt, model = "text-dream-001" }); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); MessageBox.Show(responseString); } else { MessageBox.Show($"HTTP Hata Kodu: {response.StatusCode}"); // HTTP hata kodunu burada işleyebilirsiniz. } } catch (Exception ex) { MessageBox.Show("İstek gönderilirken bir hata meydana geldi: " + ex.Message); } } } }
Denis
Denis10mo ago
$code
MODiX
MODiX10mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Denis
Denis10mo ago
$codegif
KayJs
KayJs10mo ago
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http.Json; // Uzantı kitaplığı

namespace GenesisAPIFormApplication
{
public partial class Form1 : Form
{
private string apiUrl = "https://cluster-2.pudochu.repl.co/api/genesis";
private HttpClient httpClient = new HttpClient();

public Form1()
{
InitializeComponent();
}

private async void button1_Click(object sender, EventArgs e)
{
// Sabit bir metin kullanarak API'ye metin gönderme işlemi
string prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:";

try
{
var response = await httpClient.PostAsJsonAsync(apiUrl, new { prompt = prompt, model = "text-dream-001" });

if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync();
MessageBox.Show(responseString);
}
else
{
MessageBox.Show($"HTTP Hata Kodu: {response.StatusCode}");
// HTTP hata kodunu burada işleyebilirsiniz.
}
}
catch (Exception ex)
{
MessageBox.Show("İstek gönderilirken bir hata meydana geldi: " + ex.Message);
}
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http.Json; // Uzantı kitaplığı

namespace GenesisAPIFormApplication
{
public partial class Form1 : Form
{
private string apiUrl = "https://cluster-2.pudochu.repl.co/api/genesis";
private HttpClient httpClient = new HttpClient();

public Form1()
{
InitializeComponent();
}

private async void button1_Click(object sender, EventArgs e)
{
// Sabit bir metin kullanarak API'ye metin gönderme işlemi
string prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:";

try
{
var response = await httpClient.PostAsJsonAsync(apiUrl, new { prompt = prompt, model = "text-dream-001" });

if (response.IsSuccessStatusCode)
{
var responseString = await response.Content.ReadAsStringAsync();
MessageBox.Show(responseString);
}
else
{
MessageBox.Show($"HTTP Hata Kodu: {response.StatusCode}");
// HTTP hata kodunu burada işleyebilirsiniz.
}
}
catch (Exception ex)
{
MessageBox.Show("İstek gönderilirken bir hata meydana geldi: " + ex.Message);
}
}
}
}
@ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius10mo ago
Everything seems fine, which means it really is an error on the server's side
KayJs
KayJs10mo ago
or .net version?
Angius
Angius10mo ago
No
KayJs
KayJs10mo ago
oke
Angius
Angius10mo ago
The error is on the server's side Since it says the error occured on line 71 of some JSON, and you're sending 4 lines at most So it probably handles some different JSON, and that's what throws the error
KayJs
KayJs10mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ or bad json connection?
Angius
Angius10mo ago
There's no such thing as "json connection" You send valid JSON to the server The server has an error due to some other JSON that's at least 71 lines long The issue is with the server code
KayJs
KayJs10mo ago
@angius he said bad json connection @pobiega
Pobiega
Pobiega10mo ago
dont ping people
KayJs
KayJs10mo ago
okey
Angius
Angius10mo ago
Well, you're not sending JSON with 71 lines, all your code is correct, it really doesn't seem like anything wrong with your code
KayJs
KayJs10mo ago
hmm
Brainiac V
Brainiac V10mo ago
Is there an API documentation or what kind of API is this?
KayJs
KayJs10mo ago
question answer
Brainiac V
Brainiac V10mo ago
Do you have a working example from Postman or any other source?
KayJs
KayJs10mo ago
example proggaming languege is JavaScript
Brainiac V
Brainiac V10mo ago
Show me a working example from this API because if we don't know if the API works at all, there is no sense in going any further
KayJs
KayJs10mo ago
let data = {
messages: [
{
"role": "admin", "content": "Senin ismin Kedi. Siz Konuşmalarınızda her zaman miyav yazan bir yapay zekasınız"
},
{
"role": "user",
"content": "selam nasılsın!"
}
],
model: "b2-heavy",
}

let axios = require('axios')

axios("https://cluster-2.pudochu.repl.co/api/genesis", {
"data": data,
"method": "POST"
}).then(c => c.data).then(c => console.log(c.text))
let data = {
messages: [
{
"role": "admin", "content": "Senin ismin Kedi. Siz Konuşmalarınızda her zaman miyav yazan bir yapay zekasınız"
},
{
"role": "user",
"content": "selam nasılsın!"
}
],
model: "b2-heavy",
}

let axios = require('axios')

axios("https://cluster-2.pudochu.repl.co/api/genesis", {
"data": data,
"method": "POST"
}).then(c => c.data).then(c => console.log(c.text))
Angius
Angius10mo ago
Well, the data you're sending with C# doesn't contain any messages Is it an optional property?
Brainiac V
Brainiac V10mo ago
Just did a small test with JSON, the API itself works, that's the JSON I sent:
{
"messages": [
{
"role": "admin",
"content": "Senin ismin Kedi. Siz Konuşmalarınızda her zaman miyav yazan bir yapay zekasınız"
},
{
"role": "user",
"content": "selam nasılsın!"
}
],
"model": "b2-heavy"
}
{
"messages": [
{
"role": "admin",
"content": "Senin ismin Kedi. Siz Konuşmalarınızda her zaman miyav yazan bir yapay zekasınız"
},
{
"role": "user",
"content": "selam nasılsın!"
}
],
"model": "b2-heavy"
}
Response is:
{
"text": "Miyeav! Ben Kedi, merhaba! Sizinle konuşmak için buradayım. Nasıl yardımcı olabilirim?"
}
{
"text": "Miyeav! Ben Kedi, merhaba! Sizinle konuşmak için buradayım. Nasıl yardımcı olabilirim?"
}
Angius
Angius10mo ago
So it probably needs messages
Brainiac V
Brainiac V10mo ago
Yep, removed messages, returns still 200 but with an error message, a bit weird API behaviour but we can't change that I guess
{
"error": true,
"error_message": "Prompt ve Messages kısmını girmediniz. Bunlardan bir tanesini veri olarak göndermeniz gerekiyor.",
"help": "discord.gg/cortexapi"
}
{
"error": true,
"error_message": "Prompt ve Messages kısmını girmediniz. Bunlardan bir tanesini veri olarak göndermeniz gerekiyor.",
"help": "discord.gg/cortexapi"
}
Angius
Angius10mo ago
So, oddly, not the error we've seen in this thread What if instead of messages you have the prompt property?
Brainiac V
Brainiac V10mo ago
let me check So if that's the JSON in the POST request:
{
"prompt": "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:"
"model": "text-dream-001"
}
{
"prompt": "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:"
"model": "text-dream-001"
}
We get this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected string in JSON at position 100<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (/home/runner/Cluster-2/node_modules/body-parser/lib/types/json.js:92:19)<br> &nbsp; &nbsp;at /home/runner/Cluster-2/node_modules/body-parser/lib/read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:203:9)<br> &nbsp; &nbsp;at invokeCallback (/home/runner/Cluster-2/node_modules/raw-body/index.js:238:16)<br> &nbsp; &nbsp;at done (/home/runner/Cluster-2/node_modules/raw-body/index.js:227:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/home/runner/Cluster-2/node_modules/raw-body/index.js:287:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:513:28)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:domain:489:12)</pre>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected string in JSON at position 100<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (/home/runner/Cluster-2/node_modules/body-parser/lib/types/json.js:92:19)<br> &nbsp; &nbsp;at /home/runner/Cluster-2/node_modules/body-parser/lib/read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:203:9)<br> &nbsp; &nbsp;at invokeCallback (/home/runner/Cluster-2/node_modules/raw-body/index.js:238:16)<br> &nbsp; &nbsp;at done (/home/runner/Cluster-2/node_modules/raw-body/index.js:227:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (/home/runner/Cluster-2/node_modules/raw-body/index.js:287:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:513:28)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:domain:489:12)</pre>
</body>
</html>
ah wait, forgot the comma sorry! So that's the valid JSON we sent:
{
"prompt": "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:",
"model": "text-dream-001"
}
{
"prompt": "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:",
"model": "text-dream-001"
}
Response:
{
"text": "Merhaba!"
}
{
"text": "Merhaba!"
}
So it seems like the structure is supported
KayJs
KayJs10mo ago
Where do I need to enter it then?
Angius
Angius10mo ago
Well, this code looks just fine
No description
Angius
Angius10mo ago
So
var client = new HttpClient();
var res = await client.PostAsJsonAsync(
"https://cluster-2.pudochu.repl.co/api/genesis",
new
{
prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:",
model = "text-dream-001"
}
);
await res.Content.ReadAsStringAsync()
var client = new HttpClient();
var res = await client.PostAsJsonAsync(
"https://cluster-2.pudochu.repl.co/api/genesis",
new
{
prompt = "Senin adın Jarvis. Her şeyi bilen üstün bir yapay zekasın.\n\nBen: selam\nJarvis:",
model = "text-dream-001"
}
);
await res.Content.ReadAsStringAsync()
Brainiac V
Brainiac V10mo ago
Did a small test myself, works also:
No description
Accord
Accord10mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.