2023-12-04 00:23:55 -07:00
|
|
|
const axios = require("axios");
|
|
|
|
|
2023-12-13 14:56:07 -07:00
|
|
|
const concurrentRequests = 75;
|
2023-12-04 00:23:55 -07:00
|
|
|
const headers = {
|
|
|
|
Authorization: "Bearer test",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
};
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
model: "gpt-4",
|
|
|
|
max_tokens: 1,
|
|
|
|
stream: false,
|
|
|
|
messages: [{ role: "user", content: "Hi" }],
|
|
|
|
};
|
|
|
|
|
|
|
|
const makeRequest = async (i) => {
|
|
|
|
try {
|
|
|
|
const response = await axios.post(
|
2023-12-13 14:56:07 -07:00
|
|
|
"http://localhost:7860/proxy/google-ai/v1/chat/completions",
|
2023-12-04 00:23:55 -07:00
|
|
|
payload,
|
|
|
|
{ headers }
|
|
|
|
);
|
|
|
|
console.log(
|
|
|
|
`Req ${i} finished with status code ${response.status} and response:`,
|
|
|
|
response.data
|
|
|
|
);
|
|
|
|
} catch (error) {
|
2023-12-13 14:56:07 -07:00
|
|
|
const msg = error.response
|
|
|
|
console.error(`Error in req ${i}:`, error.message, msg || "");
|
2023-12-04 00:23:55 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const executeRequestsConcurrently = () => {
|
|
|
|
const promises = [];
|
|
|
|
for (let i = 1; i <= concurrentRequests; i++) {
|
|
|
|
console.log(`Starting request ${i}`);
|
|
|
|
promises.push(makeRequest(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all(promises).then(() => {
|
|
|
|
console.log("All requests finished");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
executeRequestsConcurrently();
|