Created
March 14, 2024 10:05
-
-
Save yusukebe/8875dc251b72007ab0caa7f4ad372e8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type ExportedHandler } from '@cloudflare/workers-types' | |
import { Ai } from '@cloudflare/ai' | |
type Env = { | |
AI: any | |
} | |
export default { | |
fetch: async (req, env) => { | |
const ai = new Ai(env.AI) | |
const res = await ai.run('@cf/meta/llama-2-7b-chat-int8', { | |
prompt: 'Please explain how to write a good code.', | |
stream: true | |
}) | |
if (res instanceof ReadableStream) { | |
return new Response(res, { | |
headers: { | |
'Transfer-Encoding': 'chunked' | |
} | |
}) | |
} | |
return new Response('response is not a stream.') | |
} | |
} satisfies ExportedHandler<Env> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment