Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chatgpt-cloudflare

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatgpt-cloudflare - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

31

dist/src/ChatGPTClient.js

@@ -40,20 +40,11 @@ import { ConversationContext } from "./ConversationContext";

const response = await this.post(BASE_URL, body, headers);
const json = (await response.json());
if ("error" in json) {
const error = new Error(json.error.message);
const responseBody = (await response.json());
// Error handling
if (Object.prototype.hasOwnProperty.call(responseBody, "error")) {
const error = new Error(responseBody.error.message);
this.errorHandler(error);
throw error;
}
else if ("choices" in json && json.choices.length > 0) {
const responseContent = json.choices[0].message.content;
context.addMessage({
role: ASSISTANT_LABEL,
content: responseContent,
});
return {
text: responseContent,
id: json.id,
};
}
else {
if (!Object.prototype.hasOwnProperty.call(responseBody, "choices") ||
responseBody.choices.length === 0) {
const error = new Error("Did not receive any message choices");

@@ -63,2 +54,12 @@ this.errorHandler(error);

}
// Happy path
const responseContent = responseBody.choices[0].message.content;
context.addMessage({
role: ASSISTANT_LABEL,
content: responseContent,
});
return {
text: responseContent,
id: responseBody.id,
};
}

@@ -65,0 +66,0 @@ catch (error) {

{
"name": "chatgpt-cloudflare",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "ChatGPT API client, compatible with Cloudflare Workers",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc