From 4d729d816d5a01f7ff7d8457c1057e6b9d0d83c8 Mon Sep 17 00:00:00 2001 From: Luis Felipe Salazar Ucros <40307832+luisfucros@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:35:46 -0500 Subject: [PATCH] Add SambaNova Integration (#291) * Feature: Add sambanova.md * Feature: add sambanova logo * fix typo --- integrations/sambanova.md | 132 ++++++++++++++++++++++++++++++++++++++ logos/sambanova.png | Bin 0 -> 9429 bytes 2 files changed, 132 insertions(+) create mode 100644 integrations/sambanova.md create mode 100644 logos/sambanova.png diff --git a/integrations/sambanova.md b/integrations/sambanova.md new file mode 100644 index 00000000..4508da55 --- /dev/null +++ b/integrations/sambanova.md @@ -0,0 +1,132 @@ +--- +layout: integration +name: Sambanova +description: Use open Language Models served by Sambanova +authors: + - name: Sambanova Team + socials: + twitter: SambaNovaAI + linkedin: https://www.linkedin.com/company/sambanova +pypi: https://pypi.org/project/haystack-ai/ +repo: https://github.com/deepset-ai/haystack +type: Model Provider +report_issue: https://github.com/deepset-ai/haystack/issues +logo: /logos/sambanova.png +version: Haystack 2.0 +toc: true +--- + +### **Table of Contents** + +- [Overview](#overview) +- [Usage](#usage) + +## Overview + +SambaNova is an AI company that develops SN40L Reconfigurable Dataflow Unit (RDU), a processor that provides native dataflow processing and high-performance for fast inference of Large Language Models. + +To start using SambaNova, sign up for an API key [here](https://cloud.sambanova.ai/). +This will give you access to SambaNova Cloud API, which offers rapid inference of open Language Models like Llama 3 and Qwen. + +## Usage + +SambaNova Cloud API is OpenAI compatible, making it easy to use in Haystack via OpenAI Generators. + + +### Using `Generator` + +Here's an example of using Llama served via SambaNova to perform question answering using RAG with `PromptBuilder`. +You need to set the environment variable `SAMBANOVA_API_KEY` and choose a [compatible model](https://cloud.sambanova.ai/). + +```python +from haystack import Document, Pipeline +from haystack.components.builders.prompt_builder import PromptBuilder +from haystack.components.retrievers.in_memory import InMemoryBM25Retriever +from haystack.document_stores.in_memory import InMemoryDocumentStore + +from haystack.components.generators import OpenAIGenerator +import os + +os.environ["SAMBANOVA_API_KEY"] = "YOUR_SAMBANOVA_API_KEY" + +document_store = InMemoryDocumentStore() +document_store.write_documents( + [ + Document(content="The Function-Calling API enables dynamic, agentic workflows by allowing the model to suggest and select function calls based on user input." + "This feature facilitates flexible agentic workflows that adapt to varied needs."), + Document(content="Interact with multimodal models directly through the Inference API (OpenAI compatible) and Playground" + "for seamless text and image processing."), + Document( + content="New Python and Gradio code samples make it easier to build and deploy applications on SambaNova Cloud. These examples simplify" + "integrating AI models, enabling faster prototyping and reducing setup time." + ), + ] +) + +template = """ +Given only the following information, answer the question. +Ignore your own knowledge. + +Context: +{% for document in documents %} + {{ document.content }} +{% endfor %} + +Question: {{ query }}? +""" + +llm = OpenAIGenerator( + api_key=Secret.from_env_var("SAMBANOVA_API_KEY"), + api_base_url="https://api.sambanova.ai/v1", + model="Meta-Llama-3.3-70B-Instruct", + generation_kwargs = {"max_tokens": 512} +) + +pipe = Pipeline() + +pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store)) +pipe.add_component("prompt_builder", PromptBuilder(template=template)) +pipe.add_component("llm", llm) +pipe.connect("retriever", "prompt_builder.documents") +pipe.connect("prompt_builder", "llm") + +query = "Functionalities of Sambanova API?" + +response = pipe.run({"prompt_builder": {"query": query}, "retriever": {"query": query}}) + +print(response["llm"]["replies"]) +``` + +### Using `ChatGenerator` + +See an example of engaging in a multi-turn conversation with Llama 3.3. +You need to set the environment variable `SAMBANOVA_API_KEY` and choose a [compatible model](https://cloud.sambanova.ai/). + +```python +from haystack.components.generators.chat import OpenAIChatGenerator +from haystack.dataclasses import ChatMessage +from haystack.utils import Secret +import os + +os.environ["SAMBANOVA_API_KEY"] = "YOUR_SAMBANOVA_API_KEY" + +generator = OpenAIChatGenerator( + api_key=Secret.from_env_var("SAMBANOVA_API_KEY"), + api_base_url="https://api.sambanova.ai/v1", + model="Meta-Llama-3.3-70B-Instruct", + generation_kwargs = {"max_tokens": 512} +) + + +messages = [] + +while True: + msg = input("Enter your message or Q to exit\nšŸ§‘ ") + if msg=="Q": + break + messages.append(ChatMessage.from_user(msg)) + response = generator.run(messages=messages) + assistant_resp = response['replies'][0] + print("šŸ¤– "+assistant_resp.content) + messages.append(assistant_resp) +``` diff --git a/logos/sambanova.png b/logos/sambanova.png new file mode 100644 index 0000000000000000000000000000000000000000..7b4493c91e3ad7daadc114f179686d51b295c554 GIT binary patch literal 9429 zcmV;`Br4m9P)004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw0004ZP)t-s0002^>frRorT5mp z^uwX+nP264F64D4<8UA2aUkS#Bja)+_t(Mq)V%l7x%K7Q_RqBQznbckR_m5q>5x$5 zcPis@BI9r#<8UA5f;;P&Uh0%r?4D=z!=dSoP2p$};%XJ=g+J+#QSG5?`Qy~+iALvy zJ@m+^?W1q!gg)YF6X9qP&-BBf>5NO{b|~R!5$1g}@2Yv|heP$`*X4UK z;%pf4xR2s#6ya3AWBQRs$3;b;@#Y82*uGU}02>zG~l z*TDGN#rM^{>5)?6YZmO9Vffg>?xu9fh&tJ?^P^=!{F_aw6ht7UFCe<8dJ4Zyn-p8{udY;b{}%Z5iWm9^q;g|Ns9l z#Sx+a0041xQchC<1S36MZHuVM*XF=TH5>;fLuQY&#og}o#ixW?N_q0@%%o`zjjl6t zxaR!VmJ~dL&H9~IoeHt^H154XWwZhM(Ql^q;LVp|5Ev}S*>)gczDP|i=u)|eeuGBg zPF;iI^LtaJI@5}{jf-nr^Tbj2?6>;o4bH}i6!RXO#oh)!X;7v7hBQj<*^fD%t#-vA)*>gU^Pn zMx~8%__dF%S5d8K+3^B16jWk>m8zFCo~ z5avD5>DgF$VS46PvsQn$nLrnp$_O*u=i{vYWRrpV=jzHub9Rlj`g6?}ZeqPGQ)u0W zSPf>Tw&a{|Ooth(pQ!S2{!`?5x5-v$-AZvV3%*58Q9{vZbYjywnTSRsilXG-r8qm8 zGgm=-CiELeIgV8(wq9=c?Ywx_;_-Nb3F{>3@$9xddr?0%@W)=1<@9glas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