跳到主要內容

Titan Takeoff

TitanML 透過我們的訓練、壓縮和推論最佳化平台,協助企業建構和部署更好、更小、更便宜且更快速的 NLP 模型。

我們的推論伺服器 Titan Takeoff 讓您只需一個指令,就能在本地硬體上部署 LLM。 大多數嵌入模型都支援開箱即用。如果您在使用特定模型時遇到問題,請透過 hello@titanml.co 告知我們。

範例用法

以下是一些有用的範例,可讓您開始使用 Titan Takeoff Server。 您需要確保 Takeoff Server 已在背景啟動,才能執行這些指令。 如需更多資訊,請參閱 啟動 Takeoff 的說明文件頁面

import time

from langchain_community.embeddings import TitanTakeoffEmbed
API 參考: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)

此頁面是否對您有幫助?