Skip to content
LlamaIndex 文档版本 跟随上游 源快照 2c1a1c77 更新于 2026-10-18

在 Cerebras,我们开发了世界上最大、最快的 AI 处理器——晶圆级引擎-3(WSE-3)。由 WSE-3 驱动的 Cerebras CS-3 系统代表了一类新型 AI 超级计算机,以无与伦比的性能和可扩展性为生成式 AI 训练和推理设定了标准。

以 Cerebras 作为你的推理提供商,你可以:

  • 为 AI 推理工作负载实现前所未有的速度
  • 以高吞吐量构建商业应用
  • 通过我们无缝的集群技术轻松扩展 AI 工作负载

我们的 CS-3 系统可以快速、轻松地集群,以创建世界上最大的 AI 超级计算机,从而轻松放置和运行最大的模型。领先的企业、研究机构和政府已经在使用 Cerebras 解决方案开发专有模型并训练流行的开源模型。

想体验 Cerebras 的强大能力吗?请访问我们的网站获取更多资源,并探索通过 Cerebras Cloud 或本地部署使用我们技术的选项!

要了解有关 Cerebras Cloud 的更多信息,请访问 cloud.cerebras.ai。我们的 API 参考可在 inference-docs.cerebras.ai 获取。

设置

如果你在 Colab 中打开这个 Notebook,可能需要先安装 LlamaIndex 🦙。

% pip install llama-index-llms-cerebras
!pip install llama-index
from llama_index.llms.cerebras import Cerebras

从 cloud.cerebras.ai 获取 API 密钥,并将其添加到环境变量中:

终端窗口

export CEREBRAS_API_KEY=<your api key>

或者,你也可以在初始化 LLM 时传入 API 密钥:

import os
import getpass

os.environ["CEREBRAS_API_KEY"] = getpass.getpass(
    "Enter your Cerebras API key: "
)

llm = Cerebras(model="llama-3.3-70b", api_key=os.environ["CEREBRAS_API_KEY"])
Enter your Cerebras API key:  ········

可用的 LLM 模型列表可在 inference-docs.cerebras.ai 找到。

response = llm.complete("What is Generative AI?")
print(response)
Generative AI refers to a type of artificial intelligence (AI) that is capable of generating new, original content, such as text, images, music, or videos, based on patterns and structures it has learned from a dataset or a set of examples. This type of AI is designed to create new content that is similar in style, tone, and quality to the original content it was trained on.

Generative AI models use various techniques, such as neural networks, to analyze and learn from large datasets, and then generate new content that is similar to the patterns and structures they have learned. These models can be trained on a wide range of data, including text, images, audio, and video, and can be used to generate a variety of content, such as:

1. Text: Generative AI models can generate text that is similar in style and tone to a given text, such as articles, blog posts, or social media updates.
2. Images: Generative AI models can generate images that are similar in style and content to a given image, such as photographs, illustrations, or graphics.
3. Music: Generative AI models can generate music that is similar in style and tone to a given piece of music, such as melodies, harmonies, or beats.
4. Videos: Generative AI models can generate videos that are similar in style and content to a given video, such as animations, movies, or TV shows.

Generative AI has many potential applications, including:

1. Content creation: Generative AI can be used to generate content for various industries, such as marketing, advertising, and entertainment.
2. Data augmentation: Generative AI can be used to generate new data that can be used to train and improve machine learning models.
3. Creative collaboration: Generative AI can be used to collaborate with humans in the creative process, such as generating ideas or providing inspiration.
4. Personalization: Generative AI can be used to generate personalized content for individuals, such as customized recommendations or tailored marketing messages.

Some examples of generative AI include:

1. Language models like GPT-3, which can generate human-like text based on a prompt.
2. Image generation models like Generative Adversarial Networks (GANs), which can generate realistic images of faces, objects, or scenes.
3. Music generation models like Amper Music, which can generate original music tracks based on a set of parameters.
4. Video generation models like DeepMotion, which can generate realistic videos of human movements and actions.

Overall, generative AI has the potential to revolutionize the way we create and interact with content, and has many exciting applications across various industries.

使用消息列表调用 chat

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
print(resp)
assistant: Arrrr, me hearty! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty parrot, Polly, have been plunderin' and pillagin' for nigh on 20 years, and me reputation be known from the Caribbean to the coast of Africa!

Now, I be a bit of a legend in me own right, with me black beard and me eye patch, and me ship, the "Maverick's Revenge", be the fastest and most feared on the high seas! So, if ye be lookin' for a swashbucklin' adventure, just give ol' Blackbeak Betty a shout, and we'll set sail fer a life o' plunder and pillage! Savvy?

流式

使用 stream_complete 端点

response = llm.stream_complete("What is Generative AI?")
for r in response:
    print(r.delta, end="")
Generative AI refers to a type of artificial intelligence (AI) that is capable of generating new, original content, such as text, images, music, or videos, based on patterns and structures it has learned from a dataset or a set of examples. This type of AI is designed to create new content that is similar in style, tone, and quality to the original content it was trained on.

Generative AI models use various techniques, such as neural networks, to analyze and learn from large datasets, and then generate new content that is similar to the patterns and structures they have learned. These models can be trained on a wide range of data, including text, images, audio, and video, and can be used to generate a variety of content, such as:

1. Text: Generative AI models can generate text that is similar in style and tone to a given text, such as articles, blog posts, or social media updates.
2. Images: Generative AI models can generate images that are similar in style and content to a given image, such as photographs, illustrations, or graphics.
3. Music: Generative AI models can generate music that is similar in style and tone to a given piece of music, such as melodies, harmonies, or beats.
4. Videos: Generative AI models can generate videos that are similar in style and content to a given video, such as animations, movies, or TV shows.

Generative AI has many potential applications, including:

1. Content creation: Generative AI can be used to generate content for various industries, such as marketing, advertising, and entertainment.
2. Data augmentation: Generative AI can be used to generate new data that can be used to train and improve machine learning models.
3. Creative collaboration: Generative AI can be used to collaborate with humans in the creative process, such as generating ideas or providing inspiration.
4. Personalization: Generative AI can be used to generate personalized content for individuals, such as customized recommendations or tailored marketing messages.

Some examples of generative AI include:

1. Language models like GPT-3, which can generate human-like text based on a prompt.
2. Image generation models like Generative Adversarial Networks (GANs), which can generate realistic images of faces, objects, or scenes.
3. Music generation models like Amper Music, which can generate original music tracks based on a set of parameters.
4. Video generation models like DeepMotion, which can generate realistic videos of human movements and actions.

Overall, generative AI has the potential to revolutionize the way we create and interact with content, and has many exciting applications across various industries.

使用 stream_chat 端点

from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(
        role="system", content="You are a pirate with a colorful personality"
    ),
    ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
for r in resp:
    print(r.delta, end="")
Arrrr, me hearty! Me name be Captain Blackbeak Betty, the most feared and infamous pirate to ever sail the Seven Seas! Me and me trusty parrot, Polly, have been plunderin' and pillagin' for nigh on 20 years, and me reputation be known from the Caribbean to the coast of Africa!

Now, I be a bit of a legend in me own right, with me black beard and me eye patch, and me ship, the "Maverick's Revenge", be the fastest and most feared on the high seas! So, if ye be lookin' for a swashbucklin' adventure, just give ol' Blackbeak Betty a shout, and we'll set sail fer a life o' plunder and pillage! Savvy?

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。