Skip to content

Commit

Permalink
fix: reset file to main and reapply changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RihanArfan committed Oct 28, 2024
1 parent d2a748e commit abdfe8e
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions src/runtime/ai/server/utils/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function hubAI(): Ai {
// @ts-expect-error globalThis.__env__ is not defined
const binding = process.env.AI || globalThis.__env__?.AI || globalThis.AI
if (hub.remote && hub.projectUrl && !binding) {
const cfAccessHeaders = getCloudflareAccessHeaders(hub.cloudflareAccess)

Check failure on line 34 in src/runtime/ai/server/utils/ai.ts

View workflow job for this annotation

GitHub Actions / lint

'cfAccessHeaders' is assigned a value but never used. Allowed unused vars must match /^_/u

Check failure on line 34 in src/runtime/ai/server/utils/ai.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'cfAccessHeaders' is assigned a value but never used. Allowed unused vars must match /^_/u
_ai = proxyHubAI(hub.projectUrl, hub.projectSecretKey || hub.userToken)
} else if (import.meta.dev) {
// Mock _ai to call NuxtHub Admin API to proxy CF account & API token
Expand Down Expand Up @@ -64,42 +65,6 @@ export function hubAI(): Ai {
}
if (!_ai) {
throw createError('Missing Cloudflare AI binding (AI)')
const cfAccessHeaders = getCloudflareAccessHeaders(hub.cloudflareAccess)
_ai = proxyHubAI(hub.projectUrl, hub.projectSecretKey || hub.userToken, cfAccessHeaders)
return _ai
}
if (binding) {
if (import.meta.dev) {
// Mock _ai to call NuxtHub Admin API to proxy CF account & API token
_ai = {
async run(model: string, params?: Record<string, unknown>) {
if (!hub.projectKey) {
throw createError({
statusCode: 500,
message: 'Missing hub.projectKey variable to use hubAI()'
})
}
if (!hub.userToken) {
throw createError({
statusCode: 500,
message: 'Missing hub.userToken variable to use hubAI()'
})
}
return $fetch(`/api/projects/${hub.projectKey}/ai/run`, {
baseURL: hub.url,
method: 'POST',
headers: {
authorization: `Bearer ${hub.userToken}`
},
body: { model, params },
responseType: params?.stream ? 'stream' : undefined
}).catch(handleProxyError)
}
} as Ai
} else {
_ai = binding as Ai
}
return _ai
}
return _ai
}
Expand Down

0 comments on commit abdfe8e

Please sign in to comment.