#Error contacting the OpenAI API
1 messages Β· Page 1 of 1 (latest)
FIrst of, this API doesn't provide any OpenAI model.
Second, you need to set an API key in order to use the API, unless you are using cosmosrp.
alrady using an api key provided by the bot
const axios = require('axios');
require('dotenv').config(); // Ensure you have this line if using dotenv
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: `${__dirname}/preload.js`,
contextIsolation: true,
nodeIntegration: false,
},
});
win.loadFile('index.html');
}
// Ensure you have your API key in your .env file
ipcMain.handle('send-message', async (event, message) => {
try {
const response = await axios.post('https://api.pawan.krd/v1/chat/completions', {
inputs: message, // Make sure this matches the expected payload
}, {
headers: {
'Authorization': `Bearer ${process.env.API_KEY}`, // Use your API key
},
});
return response.data.message; // Adjusted based on expected response structure
} catch (error) {
console.error('API Error:', error.response ? error.response.data : error.message);
throw new Error('Error communicating with the API: ' + (error.response ? error.response.data : error.message));
}
});
app.whenReady().then(createWindow);
// Handle window all closed event
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
as u can see nothing is wrong in here
await axios.post(
'https://api.pawan.krd/v1/chat/completions',
{
model: 'pai-001',
messages: [{ role: 'user', content: prompt }],
},
{
headers: {
'Authorization': 'Bearer Your API KEY', // Pur your API Key
'Content-Type': 'application/json'
}
}
);
as i send the mesage hi it jsut sits there and waits until no response from endpoint
is pai a model name?
we cant use gpt 3.5?
No, you can't use the model "gpt-3.5-turbo" or any OpenAI model.
ok ill get back to u after testing these out
Looks like that indeed the API is not returning any response, probably a down time.
On line 22, the "inputs" propertie.
That's not how the body payload is supposed to be.
On line 28, response.data.message is also wrong.
The response payload is something like this:
{
"id": number,
"created": number,
"model": string,
"object": string,
"choices": [
{
"finish_reason": string,
"message": {
"role": "assistant",
"content": string
}
}
],
"usage": {
"prompt_tokens": number,
"completion_tokens": number,
"total_tokens": number
}
}
where can i get this payload in realtime with my api key?
The response returned by the API should be like this.
As I said, looks like teh API is having a down time or something.
I think it won't return any response, but if it id, it would be like this.
ok so i just had my first successfull answer to a hi
and the second too
okay now how many tokens pr day do i have?
Every model spends 1 credit every X amount of tokens.
that credit is taken by us? or?
API Response: {
id: 'chatcmpl-S5UGHftEBGdxsTQkiMBQqrjDyvZa',
created: 1729946348797,
model: 'pai-001',
object: 'chat-completion',
choices: [ { finish_reason: 'stop', index: 0, message: [Object] } ],
usage: { prompt_tokens: 5, completion_tokens: 155, total_tokens: 160 }
}
this is what i get..
You have daily credits, your daily credits resets every day,
and how many are those pr day?
If you go to https://discord.com/channels/1055397662976905229/1064807234825113621 and use /info you'll be able to se it.
thanks
Now you can use dot notation to read the response, respose.choices[0].message.content
so with one key i got from bot i can use any model?
or each key is assinged to each bot?
i mean i need different key for different bots
i means model
example 1 key = alll bots usage?
You key has a tier, you can use all free models.
CosmosRP Pro, is not a free model, therefore you need to be a supporter to use it.
when does the key expires like?
However, you can use pai-001 and it's variants, and CosmosRP.
They doesn't.
so for example
const response = await axios.post('https://api.pawan.krd/v1/chat/completions', {
model: 'pai-001',
i can change the modal and url too? or the url remains the same for all bots
Developers: https://api.pawan.krd/pai-001/v1
Roleplay: https://api.pawan.krd/pai-001-rp/v1
No, look.
AS you can see, this one has the model on the Endpoint.
So yes, you can change the URL, adding the model in the endpoint instead of in the request body in the model param.
But that won't change anything.
It's just the same.
And when using direct requests with axios, node fetch, cURL and etc, you need to add the /chat/completions to the endpoint.
oki
i think the cosmosrp doesnt work https://api.pawan.krd/cosmosrp-it/v1/chat/completions
Looks like CosmosRP is not working right now.
Everyone's having issues.
The other models should work fine.
i see so the end point url needs to be changed like the one i gave just now? or willl it work with the normal one hs well?
https://api.pawan.krd/v1/chat/completions with this one?
CosmosRP is the only model that doesn't work not using the model id in the endpoint.
Every other model, you can use this endpoint and just put the model id on the request body.
Note that if you put the model id in the endpoint, before the v1 it will always point to the same model.
so can u give me a list that which model goes with which url? as if now em getting confused
cuz as u see if i use pai-001-light this with https://api.pawan.krd/pai-001-light/v1 it gives me Error communicating with the API.
thats why to understadn the model i need list
model and there url
Sure.
pai-001: https://api.pawan.krd/pai-001/v1/chat/completions
pai-001-rp: https://api.pawan.krd/pai-001-rp/v1/chat/completions
pai-001-light: https://api.pawan.krd/pai-001-light/v1/chat/completions
pai-001-light-rp: https://api.pawan.krd/pai-001-light-rp/v1/chat/completions
cosmosrp: https://api.pawan.krd/cosmosrp/v1/chat/completions
cosmosrp-i: https://api.pawan.krd/cosmosrp-it/v1/chat/completions
As I said, you need to add the /chat/completions to the endpoint.
hmmmm oooooooouuuuufffff a.I REALLY IS CONFUSING BUT learning then is enjoyable thansk for ur help today alot
really aprreactiated
Yrw.
though they still are not accurate as chat gpt its self right?
No, they're not.
No.
so successfully i have implemented it to a muktiplayer game and works perfect now i want to know that can we set custom commands with these modals? like to learn more about the game or tge server or multiplayer?
or just simppy make a custom command to do just the specific task?
No idea what you meant by commands, however, in any way, that is something you would have to do by yourself based on what you want.
can the modal remmember a prompt?
As you can see in the example I gave you, messages is an array of objects.
Every object on this array is a different message.
If you include the "prompt" on this array it will "remember" it.
example?
The response payload is something like this:
{
"id": number,
"created": number,
"model": string,
"object": string,
"choices": [
{
"finish_reason": string,
"message": {
"role": "assistant",
"content": string
}
}
],
"usage": {
"prompt_tokens": number,
"completion_tokens": number,
"total_tokens": number
}
}
``` which part for ptompt
Response.
I'm talking about messages on the body payload.
[
{
"role": "user",
"content": "Hello, my name is Since."
},
{
"role": "assistant",
"content": "Hi, Since, nice to meet you!"
},
{
"role": "user",
"content": "Do you remember what is my name?"
}
]
await axios.post(
'https://api.pawan.krd/v1/chat/completions',
{
model: 'pai-001',
messages: [{ role: 'user', content: prompt }],
},
{
headers: {
'Authorization': 'Bearer Your API KEY', // Pur your API Key
'Content-Type': 'application/json'
}
}
);
``` but the content prompt gets the prompt only doesnt remmembers it
oh
See what I meant?
oki
got it
so for how long do the modals remmembers it or if the session is over it will forget?
got it
There's no "sessions".
It doesn't actually stores any data.
You're the one who sends every message.
There's a limit of how much the model can process, that's all.