xiangsx / gpt4free-ts

Providing a free OpenAI GPT-4 API ! This is a replication project for the typescript version of xtekky/gpt4free
GNU General Public License v3.0
7.71k stars 1.36k forks source link

Test file #84

Open Nicat-dcw opened 1 year ago

Nicat-dcw commented 1 year ago
const axios = require("axios");

async function ask() {
  const objj = {
    messages: { prompt: "Hello" }, //[{" role":"user","content":"hello\n"},{"role":"assistant","content":"Hi there! How can I assist you today?"},{"role":"user","prompt":"who are you"}],
    model: "gpt-4"
  };

  try {
    const response = await axios.post(
      "http://127.0.0.1:3000/v1/chat/completions?site=better",{
      data: {
        prompt: "Hello",
        messages: { content: "Hello" }, //[{" role":"user","content":"hello\n"},{"role":"assistant","content":"Hi there! How can I assist you today?"},{"role":"user","prompt":"who are you"}],
        model: "gpt-4"  
      }},
      {
        body: {
         messages: { prompt: "Hello" }, //[{" role":"user","content":"hello\n"},{"role":"assistant","content":"Hi there! How can I assist you today?"},{"role":"user","prompt":"who are you"}],
         model: "gpt-4" 
        },
        headers: {
          "Content-Type": "application/json"
        }
      }
    );

    console.log(response.data.choices[0]);
  } catch (error) {
    console.error(error)
    console.error("Error making the request:", error.message);
  }
}

ask();

I trying this but server says need prompt in query

Nicat-dcw commented 1 year ago

@xiangsx

Nicat-dcw commented 1 year ago

I solved with some changes in index.ts