Cloudflare llama 3.1 免费大尝鲜:中文效果令你意想不到
- 作者
Cloudflare 最近在其 Worker AI 平台上推出了支持 Llama 3.1 模型的服务,现在你可以免费通过 Workers AI Playground 或 API 使用这一强大的模型,模型 ID 为 @cf/meta/llama-3.1-8b-instruct。
Meta 的 Llama 模型系列一向以其在常识、可控性、数学计算、工具使用和多语言翻译等领域的卓越表现而闻名。全新的 Llama 3.1 模型更是支持高精度(bfloat16)发布,整合了函数调用,并新增对 8 种语言的支持。内置的多语言支持让你可以用英语、法语、德语、印地语、意大利语、葡萄牙语、西班牙语和泰语编写提示并获取回应。这意味着你的应用程序可以轻松触及全球用户,只需一个模型即可实现全球化。Meta 宣称 LLama 3.1 的模型已经可以对标 GPT-4o:
另外 Llama 3.1 也引入了原生函数调用,使得大语言模型能够生成结构化的 JSON 输出,并将其输入到不同的 API 中。这种开箱即用的功能不需要专门微调,大大简化了工具使用流程。
下面我们就通过 Cloudflare 的接口和 Playground 来测试一下 Llama 3.1 模型的效果,最后的结果绝对会令你大吃一惊。
接口试用
在 Cloudflare 申请了 API Key 之后,就可以通过代码来访问 Worker AI 的接口了,以下是一个使用 curl 命令发起请求的示例。
curl -X POST \
https://api.cloudflare.com/client/v4/accounts/b8670bc8c2657831fe6c8bb12ba17ccf/ai/run/@cf/meta/llama-3-8b-instruct \
-H "Authorization: Bearer {{API_KEY}}" \
-d '{"messages":[{"role":"system","content":"You are a friendly assistant that helps write stories"},{"role":"user","content":"Write a short story about a llama that goes on a journey to find an orange cloud "}]}'
通过 python 发起请求的示例。
import requests
API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/b8670bc8c2657831fe6c8bb12ba17ccf/ai/run/"
headers = {"Authorization": "Bearer {{API_KEY}}"}
def run(model, inputs):
input = { "messages": inputs }
response = requests.post(f"{API_BASE_URL}{model}", headers=headers, json=input)
return response.json()
inputs = [
{ "role": "system", "content": "You are a friendly assistan that helps write stories" },
{ "role": "user", "content": "Write a short story about a llama that goes on a journey to find an orange cloud "}
];
output = run("@cf/meta/llama-3-8b-instruct", inputs)
print(output)
执行之后就可以得到对应的返回:
{'result': {'response': "Once upon a time, in a lush green valley surrounded by towering mountains, there lived a curious llama named Lola. Lola was known for her love of exploring new places and discovering hidden wonders. One day, while lounging in her favorite spot under a ancient oak tree, she gazed up at the sky and spotted something peculiar – an orange cloud!\n\nAccording to the wise old and blind llama, Rufus, such a cloud was said to possess magical properties, healing the sick and granting wisdom to those who reached it. Lola's curiosity was piqued, and she decided that she had to find this mystical cloud, no matter what the journey entailed.\n\nWith a determined look on her face, Lola set off early in the morning, packing a light backpack with some snacks, a water bottle, and a map. She traversed through the winding trails, crossing meadows and streams, meeting various creatures along the way. There were chatty squirrels, giggling butterflies, and even a wise old badger who offered her sage advice.\n\nAs the sun began to set, casting a warm orange glow on the landscape, Lola found herself at the foot of a steep mountain. The path ahead was treacherous, but she knew she had to push on. With a deep breath, she began the ascent, her llama legs strong and steady.\n\nThe night grew darker, and Lola used her keen senses to navigate the rocky terrain. She spotted fireflies lighting up the path, leading her to a serene lake nestled in the mountains. The water's surface reflected the starry sky, and Lola felt an overwhelming sense of peace wash over her.\n\nThe next morning, she continued her journey, and after a few hours of climbing, she reached the top of the mountain. And there, before her, lay the most breathtaking sight she had ever seen – the orange cloud! It glowed with an ethereal light, radiating warmth and tranquility.\n\nLola approached the cloud cautiously, sensing its power. As she reached out to touch it, the cloud enveloped her in a soothing mist. Suddenly, visions of the natural world flooded her mind – the interconnectedness of all living beings, the beauty of the earth, and the importance of preserving it for future generations.\n\nOverwhelmed with gratitude, Lola vowed to share her newfound wisdom with others. She spent the next few days learning the secrets of the orange cloud, and when she returned to her valley, she shared her story with Rufus and the other llamas.\n\nFrom that day on, Lola became"}, 'success': True, 'errors': [], 'messages': []}
中文大尝鲜
下面通过 Workers AI LLM Playground 来问模型几个中文问题。
TCP 为什么和 OSI 的分层不一样?请用中文回答。
Redis 的字符串用的是什么数据结构
Java synchronized 是否支持升降级
请介绍一下特朗普
从上面几个问题的回答来看,模型的结果相当糟糕,刚开始还是在用中文,后面就和其他语言混杂着输出了,有点莫名其妙。
结论
通过以上尝试,我们发现尽管 Llama 3.1模型已经相当出色,但在中文支持方面仍有较大提升空间。当然,这也为国内的大模型厂商提供了新的机会,相信在一两个月内我们将会看到新一波的大模型升级,不得不非常令人期待,哈哈。
分享内容