惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
博客园 - 【当耐特】
V
Visual Studio Blog
GbyAI
GbyAI
V
V2EX
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
量子位
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件

StudyingLover's Blog

Diffusion Policy笔记 rwkv笔记 act笔记 nanovllm-block_manager opencode多智能体 nanobot-pre-train nanobot-rl nanobot-sft nanobot-checkpoint_manager nanobot-gpt nanobot-mid-train Vision Mamba (Vim)笔记 BPE演示 最后一遍学习Transformer YOLOv5 目标检测笔记 下载根服务器解析记录 Dynaseal A Backend-Controlled LLM API Key Distribution Scheme with Constrained Invocation Parameters 判断链表有环 王道25数据结构勘误 关于perplexity的open-sourcing-r1-1776 AI为什么不像人类一样进行多轮对话 新博客改造日记和功能测试 linuxqq只显示登陆背景图 数字设计和计算机体系结构(机械工业出版社)勘误(自制) Dynaseal:面向未来端侧llm agent的llm api key分发机制 A Definitive Guide to Markdown Style This post is using MDX, Where you can embed JSX and Astro components RT-Patch学习 pydantic实现的LLM ReAct fastapi 和 uvicorn 设置监听 ipv6
cloudlflare推理llama2
About the Author StudyingLover · 2023-10-11 · via StudyingLover's Blog

cloudlflare推理llama2

最近,cloudlfare悄悄上线了一项新功能,全球网络上的gpu加速推理,显然的,我们可以用它推理llama2,cloudflare也提供了一个库进行推理。

新建一个cloudflare,然后,代码改成下面的,就可以进行推理了

import { Ai } from './vendor/@cloudflare/ai.js';

export default {
  async fetch(request, env) {
    const tasks = [];
    const ai = new Ai(env.AI);

    // Get the request body
    const requestBody = await request.json();

    // messages - chat style input
    let chat = {
      messages: [
        { role: 'system', content: 'You are a helpful, kind, honest, friendly, good at writing and never fails to answer my requests immediately and with details and precision.'},
        { role: 'user', content: requestBody.prompt }
      ]
    };
    let response = await ai.run('@cf/meta/llama-2-7b-chat-int8', chat);
    tasks.push({ inputs: chat, response });

    return Response.json(tasks);
  }
};

我们可以测试一下,在命令行运行下面的命令,将https://example.workers.dev/ 换成你的网址。

curl -X POST https://example.workers.dev/ -d '{"prompt":"Write a poem that talks about the connectivity cloud"}' 

看到类似下面的返回值代表成功

[{"inputs":{"messages":[{"role":"system","content":"You are a helpful, kind, honest, friendly, good at writing and never fails to answer my requests immediately and with details and precision."},{"role":"user","content":"Write a poem that talks about the connectivity cloud"}]},"response":{"response":"In the realm of the digital sky,\nWhere information flows, and data fly,\nThere's a place that brings us all together,\nA connectivity cloud, a true forever.\n\nIt's a space that's vast and wide,\nWhere thoughts and ideas collide,\nA hub of communication and exchange,\nWhere the world's voices all combine and blend.\n\nIn this cloud of connectivity,\nWe find our voices, our identity,\nA platform for sharing and growth,\nWhere our stories are told and our dreams take flight.\n\nWith just a click or tap of a key,\nWe can connect with anyone, anywhere,\nSharing laughter, love, and tears,\nIn this digital embrace, we all share.\n\nSo let us cherish this cloud of connectivity,\nThis gift that brings us all sovereignty,\nFor in its depths, we find our tribe,\nAnd our voices, heard, can never be denied.\n\nIn this cloud of connectivity,\nWe are all connected, you see,\nA global community, united and free,\nIn this digital age, where we all can be"}}]