SambaNovaCloud
SambaNova 的 SambaNova Cloud 是一個使用開源模型執行推理的平台
注意
您目前正在瀏覽一個頁面,該頁面記錄了如何將 SambaNovaCloud 模型用作文字完成模型。我們建議您使用聊天完成模型。
您可能正在尋找 SambaNovaCloud 聊天模型。
概觀
整合細節
類別 | 套件 | 本地 | 可序列化 | JS 支援 | 套件下載 | 最新套件 |
---|---|---|---|---|---|---|
SambaNovaCloud | langchain_community | ❌ | beta | ❌ |
這個範例將說明如何使用 LangChain 與 SambaNovaCloud 模型互動
設定
憑證
要存取 ChatSambaNovaCloud 模型,您需要建立一個 SambaNovaCloud 帳戶,取得一個 API 金鑰,並將其設定為 SAMBANOVA_API_KEY
環境變數
import getpass
import os
if "SAMBANOVA_API_KEY" not in os.environ:
os.environ["SAMBANOVA_API_KEY"] = getpass.getpass()
安裝
此整合位於 langchain-community
套件中。 我們還需要安裝 sseclient-py 套件,這是執行串流預測所必需的
%pip install --quiet -U langchain-community sseclient-py
實例化
from langchain_community.llms.sambanova import SambaNovaCloud
llm = SambaNovaCloud(
model="Meta-Llama-3.1-70B-Instruct",
max_tokens_to_generate=1000,
temperature=0.01,
# top_k = 50,
# top_p = 1.0
)
API 參考:SambaNovaCloud
調用
現在我們可以實例化我們的模型物件並產生聊天完成
input_text = "Why should I use open source models?"
completion = llm.invoke(input_text)
completion
"**Advantages of Open Source Models**\n\nUsing open source models can bring numerous benefits to your project or organization. Here are some reasons why you should consider using open source models:\n\n### 1. **Cost-Effective**\n\nOpen source models are free to use, modify, and distribute. This can significantly reduce the costs associated with developing and maintaining proprietary models.\n\n### 2. **Community Support**\n\nOpen source models are often maintained by a community of developers and users who contribute to their improvement. This community support can lead to faster bug fixes, new feature additions, and better documentation.\n\n### 3. **Transparency and Customizability**\n\nOpen source models provide complete transparency into their architecture and implementation. This allows you to customize and fine-tune the model to suit your specific needs.\n\n### 4. **Faster Development**\n\nBy leveraging pre-trained open source models, you can accelerate your development process. You can focus on fine-tuning the model for your specific use case rather than building one from scratch.\n\n### 5. **Improved Security**\n\nOpen source models are often reviewed and audited by a large community of developers, which can help identify and fix security vulnerabilities.\n\n### 6. **Interoperability**\n\nOpen source models can be easily integrated with other open source tools and frameworks, promoting interoperability and reducing vendor lock-in.\n\n### 7. **Access to State-of-the-Art Technology**\n\nMany open source models are developed by top researchers and institutions, providing access to state-of-the-art technology and techniques.\n\n### Example Use Cases\n\n* **Computer Vision**: Use open source models like TensorFlow's Object Detection API or OpenCV's pre-trained models for image classification, object detection, and segmentation tasks.\n* **Natural Language Processing**: Leverage open source models like spaCy or Stanford CoreNLP for text processing, sentiment analysis, and language translation tasks.\n* **Speech Recognition**: Utilize open source models like Kaldi or Mozilla's DeepSpeech for speech-to-text applications.\n\n**Getting Started**\n\nTo get started with open source models, explore popular repositories on GitHub or model hubs like TensorFlow Hub or PyTorch Hub. Familiarize yourself with the model's documentation, and experiment with pre-trained models before fine-tuning them for your specific use case.\n\nBy embracing open source models, you can accelerate your development process, reduce costs, and tap into the collective knowledge of the developer community."
# Streaming response
for chunk in llm.stream("Why should I use open source models?"):
print(chunk, end="", flush=True)
**Advantages of Open Source Models**
Using open source models can bring numerous benefits to your projects. Here are some reasons why you should consider them:
### 1. **Cost-Effective**
Open source models are free to use, modify, and distribute. This can significantly reduce the costs associated with developing and maintaining proprietary models.
### 2. **Community Support**
Open source models are often maintained by a community of developers, researchers, and users. This community can provide support, fix bugs, and contribute to the model's improvement.
### 3. **Transparency and Reproducibility**
Open source models are transparent in their architecture, training data, and hyperparameters. This transparency allows for reproducibility, which is essential in scientific research and development.
### 4. **Customizability**
Open source models can be modified to suit specific use cases or requirements. This customizability enables developers to adapt the model to their needs, which can lead to better performance and accuracy.
### 5. **Faster Development**
Using open source models can accelerate development by providing a pre-trained foundation. This allows developers to focus on fine-tuning the model for their specific task, rather than starting from scratch.
### 6. **Access to State-of-the-Art Models**
Open source models often represent the state-of-the-art in their respective domains. By using these models, developers can leverage the latest advancements in AI research.
### 7. **Reduced Vendor Lock-in**
Open source models are not tied to a specific vendor or platform. This reduces the risk of vendor lock-in and allows developers to switch to alternative solutions if needed.
### Example Use Cases
* **Computer Vision**: Using open source models like YOLO (You Only Look Once) or SSD (Single Shot Detector) for object detection tasks.
* **Natural Language Processing**: Leveraging open source models like BERT (Bidirectional Encoder Representations from Transformers) or RoBERTa (Robustly Optimized BERT Pretraining Approach) for text classification, sentiment analysis, or language translation.
* **Speech Recognition**: Utilizing open source models like Kaldi or Mozilla DeepSpeech for speech-to-text applications.
**Getting Started**
To get started with open source models, you can explore popular repositories on GitHub or model hubs like the TensorFlow Model Garden or the PyTorch Model Zoo. These resources provide pre-trained models, documentation, and tutorials to help you integrate open source models into your projects.
By embracing open source models, you can tap into the collective knowledge and expertise of the developer community, accelerate your development process, and create more accurate and efficient AI solutions.
鏈結
我們可以像這樣將完成模型與提示模板鏈結起來
from langchain_core.prompts import PromptTemplate
prompt = PromptTemplate.from_template("How to say {input} in {output_language}:\n")
chain = prompt | llm
chain.invoke(
{
"output_language": "German",
"input": "I love programming.",
}
)
API 參考:PromptTemplate
'The translation of "I love programming" in German is:\n\n"Ich liebe das Programmieren."\n\nHere\'s a breakdown of the sentence:\n\n* "Ich" means "I"\n* "liebe" is the verb "to love" in the first person singular (I love)\n* "das" is the definite article for "Programmieren" (programming)\n* "Programmieren" is the verb "to program" in the infinitive form, but in this context, it\'s used as a noun to refer to the activity of programming.\n\nSo, "Ich liebe das Programmieren" is a common way to express your passion for programming in German.'
API 參考
有關所有 SambaNovaCloud
llm 功能和配置的詳細文檔,請訪問 API 參考:https://langchain-python.dev.org.tw/api_reference/community/llms/langchain_community.llms.sambanova.SambaNovaCloud.html