Hono and an empty env variable

I'm trying to run an worker ai using hono.

This is my index file:

import { fromHono } from 'chanfana';
import { Hono } from 'hono';
import { EmbeddingCreate } from 'endpoints/embeddingCreate';
import { EmbeddingFetch } from 'endpoints/embeddingFetch';

const app = new Hono();

const openapi = fromHono(app, {
docs_url: '/',
});

// Endpoints
openapi.get('/api/embeddings/:text/:distance', EmbeddingFetch);
openapi.post('/api/embeddings/:text', EmbeddingCreate);

export default app;

And this is my wrangler file:

name = "worker-test"
main = "src/index.ts"
compatibility_date = "2024-01-10"

[[vectorize]]
binding = "VECTORIZE"
index_name = "findu-job-desc-test1"

[ai]
binding = "AI"

And my handle function looks like this:

async handle(c) {
const data = await this.getValidatedData<typeof this.schema>();
const embeddingToCreate = data.body;

try {
const response: EmbeddingResponse = await c.env.ai.run('@cf/baai/bge-base-en-v1.5', {
text: embeddingToCreate.text,
});

return {
success: true,
embedding: {
text: embeddingToCreate.text,
embedding: response.data,
},
};
} catch (error) {
console.error(error);
}
}

The c.env is empty and the c.env.AI.run is undefined.
What am I missing?
Was this page helpful?