#Error contacting the OpenAI API

1 messages Β· Page 1 of 1 (latest)

cloud echo
#

const response = await axios.post(
'https://api.pawan.krd/v1/chat/completions',
{
model: 'gpt-3.5-turbo', // Use 'gpt-4' or any other model you need
messages: [{ role: 'user', content: prompt }],
},
); doesnt work

cloud echo
#

this means end point is not working

tribal drum
#

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.

cloud echo
#

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

tribal drum
#
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'
                }
            }
        );
cloud echo
#

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?

tribal drum
#

No, you can't use the model "gpt-3.5-turbo" or any OpenAI model.

cloud echo
#

just the pai?

#

anyothers with it?

cloud echo
#

ok ill get back to u after testing these out

tribal drum
#

Looks like that indeed the API is not returning any response, probably a down time.

cloud echo
#

thanks for ur support

#

yeap πŸ˜›

tribal drum
#

On line 22, the "inputs" propertie.

tribal drum
cloud echo
#

i see

#

ill check that with the snippet u provided

tribal drum
#

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
  }
}
cloud echo
#

where can i get this payload in realtime with my api key?

tribal drum
#

The response returned by the API should be like this.

#

As I said, looks like teh API is having a down time or something.

tribal drum
cloud echo
#

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?

tribal drum
#

Every model spends 1 credit every X amount of tokens.

cloud echo
#

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..

tribal drum
#

You have daily credits, your daily credits resets every day,

cloud echo
#

and how many are those pr day?

tribal drum
cloud echo
#

thanks

tribal drum
cloud echo
#

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?

tribal drum
#

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.

cloud echo
#

when does the key expires like?

tribal drum
#

However, you can use pai-001 and it's variants, and CosmosRP.

tribal drum
cloud echo
#

so for example

#

i can change the modal and url too? or the url remains the same for all bots

tribal drum
#

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.

cloud echo
#

oki

tribal drum
#

Looks like CosmosRP is not working right now.

#

Everyone's having issues.

#

The other models should work fine.

cloud echo
#

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?

tribal drum
#

CosmosRP is the only model that doesn't work not using the model id in the endpoint.

tribal drum
#

Note that if you put the model id in the endpoint, before the v1 it will always point to the same model.

cloud echo
#

so can u give me a list that which model goes with which url? as if now em getting confused

#

thats why to understadn the model i need list

#

model and there url

tribal drum
#

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
tribal drum
cloud echo
#

hmmmm oooooooouuuuufffff a.I REALLY IS CONFUSING BUT learning then is enjoyable thansk for ur help today alot

#

really aprreactiated

tribal drum
#

Yrw.

cloud echo
#

though they still are not accurate as chat gpt its self right?

tribal drum
#

No, they're not.

cloud echo
#

are there models like chatgpt getting worked o riht now?

#

or currently these

tribal drum
#

No.

cloud echo
#

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?

tribal drum
#

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.

cloud echo
#

can the modal remmember a prompt?

tribal drum
#

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.

cloud echo
#

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
tribal drum
#

Response.

tribal drum
tribal drum
# cloud echo example?
[
    {
        "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?"
    }
]
cloud echo
#
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

tribal drum
#

See what I meant?

cloud echo
#

oki
got it

tribal drum
#

That's how a chat history works.

#

Every message is sent as an object.

cloud echo
#

so for how long do the modals remmembers it or if the session is over it will forget?

#

got it

tribal drum
#

There's no "sessions".

#

It doesn't actually stores any data.

#

You're the one who sends every message.

tribal drum
cloud echo
#

oh..

#

i see ill need to work on it more tommorow

#

thanks again..!