chatgpt-cloudflare
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7880
124