Skip to main content
TitanML 通过其训练、压缩和推理优化平台,帮助企业构建和部署更优质、更小型、更低成本、更高速的 NLP 模型。 我们的推理服务器 Titan Takeoff 支持通过单条命令在本地硬件上部署大语言模型。大多数嵌入模型都可以开箱即用。如果您在使用特定模型时遇到问题,请通过 hello@titanml.co 联系我们。

使用示例

以下是一些帮助您快速上手 Titan Takeoff Server 的示例。运行这些命令前,请确保 Takeoff Server 已在后台启动。更多信息请参阅启动 Takeoff 的文档页面
import time

from langchain_community.embeddings import TitanTakeoffEmbed

示例 1

基本用法,假设 Takeoff 正在您的机器上以默认端口(即 localhost:3000)运行。
embed = TitanTakeoffEmbed()
output = embed.embed_query(
    "What is the weather in London in August?", consumer_group="embed"
)
print(output)

示例 2

使用 TitanTakeoffEmbed Python Wrapper 启动 reader。如果您在首次启动 Takeoff 时未创建任何 reader,或希望添加新的 reader,可以在初始化 TitanTakeoffEmbed 对象时进行操作,只需将要启动的模型列表作为 models 参数传入即可。 您可以使用 embed.query_documents 一次嵌入多个文档。该方法的输入应为字符串列表,而 embed_query 方法则只接受单个字符串。
# Model config for the embedding model, where you can specify the following parameters:
#   model_name (str): The name of the model to use
#   device: (str): The device to use for inference, cuda or cpu
#   consumer_group (str): The consumer group to place the reader into
embedding_model = {
    "model_name": "BAAI/bge-large-en-v1.5",
    "device": "cpu",
    "consumer_group": "embed",
}
embed = TitanTakeoffEmbed(models=[embedding_model])

# The model needs time to spin up, length of time need will depend on the size of model and your network connection speed
time.sleep(60)

prompt = "What is the capital of France?"
# We specified "embed" consumer group so need to send request to the same consumer group so it hits our embedding model and not others
output = embed.embed_query(prompt, consumer_group="embed")
print(output)