SambaNova
SambaNova 的 Sambastudio 是一个用于运行您自己的开源模型的平台
此示例介绍了如何使用 LangChain 与 SambaNova 嵌入模型进行交互
SambaStudio
SambaStudio 允许您训练、运行批处理推理作业,以及部署在线推理端点以运行您自己微调的开源模型。
部署模型需要 SambaStudio 环境。在 sambanova.ai/products/enterprise-ai-platform-sambanova-suite 获取更多信息
注册您的环境变量
import os
sambastudio_base_url = "<Your SambaStudio environment URL>"
sambastudio_base_uri = "<Your SambaStudio environment URI>"
sambastudio_project_id = "<Your SambaStudio project id>"
sambastudio_endpoint_id = "<Your SambaStudio endpoint id>"
sambastudio_api_key = "<Your SambaStudio endpoint API key>"
# Set the environment variables
os.environ["SAMBASTUDIO_EMBEDDINGS_BASE_URL"] = sambastudio_base_url
os.environ["SAMBASTUDIO_EMBEDDINGS_BASE_URI"] = sambastudio_base_uri
os.environ["SAMBASTUDIO_EMBEDDINGS_PROJECT_ID"] = sambastudio_project_id
os.environ["SAMBASTUDIO_EMBEDDINGS_ENDPOINT_ID"] = sambastudio_endpoint_id
os.environ["SAMBASTUDIO_EMBEDDINGS_API_KEY"] = sambastudio_api_key
直接从 LangChain 调用 SambaStudio 托管的嵌入!
from langchain_community.embeddings.sambanova import SambaStudioEmbeddings
embeddings = SambaStudioEmbeddings()
text = "Hello, this is a test"
result = embeddings.embed_query(text)
print(result)
texts = ["Hello, this is a test", "Hello, this is another test"]
results = embeddings.embed_documents(texts)
print(results)
API 参考:SambaStudioEmbeddings
您可以手动传递端点参数并手动设置 SambaStudio 嵌入端点中的批处理大小
embeddings = SambaStudioEmbeddings(
sambastudio_embeddings_base_url=sambastudio_base_url,
sambastudio_embeddings_base_uri=sambastudio_base_uri,
sambastudio_embeddings_project_id=sambastudio_project_id,
sambastudio_embeddings_endpoint_id=sambastudio_endpoint_id,
sambastudio_embeddings_api_key=sambastudio_api_key,
batch_size=32, # set depending on the deployed endpoint configuration
)
或者您可以使用部署在您的 CoE 中的嵌入模型专家
embeddings = SambaStudioEmbeddings(
batch_size=1,
model_kwargs={
"select_expert": "e5-mistral-7b-instruct",
},
)