Skip to content

Commit

Permalink
Refactor ai-api run logic (#3387)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquinGimenez1 authored Jan 22, 2025
1 parent fd8ee70 commit b4f0b20
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/cloudflare/internal/ai-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Cloudflare, Inc.
// Copyright (c) 2025 Cloudflare, Inc.
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0

Expand Down Expand Up @@ -142,25 +142,24 @@ export class Ai {
this.aiGatewayLogId = res.headers.get('cf-aig-log-id');
this.lastRequestHttpStatusCode = res.status;

if (inputs['stream']) {
if (!res.ok) {
throw await this._parseError(res);
}
if (!res.ok) {
throw await this._parseError(res);
}

if (inputs['stream']) {
return res.body;
} else {
if (!res.ok || !res.body) {
throw await this._parseError(res);
}

const contentType = res.headers.get('content-type');
}

if (contentType === 'application/json') {
return (await res.json()) as object;
}
if (!res.body) {
throw await this._parseError(res);
}

return res.body;
const contentType = res.headers.get('content-type');
if (contentType === 'application/json') {
return (await res.json()) as object;
}

return res.body;
}

/*
Expand Down

0 comments on commit b4f0b20

Please sign in to comment.