--- title: Indian Budget RAGBot emoji: 👀 colorFrom: green colorTo: gray sdk: gradio sdk_version: 4.40.0 app_file: app.py pinned: false short_description: Boost NLP with MonsterAPI and Haystack. --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference # MonsterAPI Integration with Haystack ![MonsterAPI Logo](logo.png) ## Overview MonsterAPI offers powerful language models designed to handle various text-generation tasks with high efficiency. By integrating MonsterAPI with the Haystack framework, users can enhance their natural language processing capabilities, utilizing advanced models for improved performance in search, question answering, and more. To get started, sign up for an API key [here](https://monsterapi.ai/). New users receive 2500 FREE credits upon signing up, enabling you to explore MonsterAPI’s features and capabilities without incurring initial costs. ## Benefits of Using MonsterAPI with Haystack The integration of MonsterAPI with Haystack brings several advantages: - **Advanced Language Models**: Access to state-of-the-art models that excel in generating and understanding text. - **Seamless Integration**: MonsterAPI's API is compatible with OpenAI's API, allowing easy integration into Haystack's pipeline. - **Enhanced Functionality**: Leverage the strengths of both Haystack’s framework and MonsterAPI’s models for more robust and accurate NLP solutions. ## Usage ### Using `Generator` Here’s how you can use a model served via MonsterAPI to perform question answering on a web page with Haystack: 1. Set the environment variable `MONSTER_API_KEY`. 2. Choose a [compatible model](https://developer.monsterapi.ai/). ```python from haystack import Pipeline from haystack.utils import Secret from haystack.components.fetchers import LinkContentFetcher from haystack.components.converters import HTMLToDocument from haystack.components.builders import PromptBuilder from haystack.components.generators import OpenAIGenerator fetcher = LinkContentFetcher() converter = HTMLToDocument() prompt_template = """ According to the contents of this website: {% for document in documents %} {{document.content}} {% endfor %} Answer the given question: {{query}} Answer: """ prompt_builder = PromptBuilder(template=prompt_template) llm = OpenAIGenerator( api_key=Secret.from_env_var("MONSTER_API_KEY"), api_base_url="https://llm.monsterapi.ai/v1/", model="microsoft/Phi-3-mini-4k-instruct", generation_kwargs={"max_tokens": 256} ) pipeline = Pipeline() pipeline.add_component("fetcher", fetcher) pipeline.add_component("converter", converter) pipeline.add_component("prompt", prompt_builder) pipeline.add_component("llm", llm) pipeline.connect("fetcher.streams", "converter.sources") pipeline.connect("converter.documents", "prompt.documents") pipeline.connect("prompt.prompt", "llm.prompt") result = pipeline.run({"fetcher": {"urls": ["https://developer.monsterapi.ai/docs/"]}, "prompt": {"query": "What are the features of MonsterAPI?"}}) print(result["llm"]["replies"][0]) ``` ### Using `ChatGenerator` To engage in a multi-turn conversation with a MonsterAPI model, follow this example: 1. Set the environment variable `MONSTER_API_KEY`. 2. Choose a [compatible model](https://developer.monsterapi.ai/). ```python from haystack.components.generators.chat import OpenAIChatGenerator from haystack.dataclasses import ChatMessage from haystack.utils import Secret generator = OpenAIChatGenerator( api_key=Secret.from_env_var("MONSTER_API_KEY"), api_base_url="https://llm.monsterapi.ai/v1/", model="microsoft/Phi-3-mini-4k-instruct", generation_kwargs={"max_tokens": 256} ) 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) ``` ## Resources - [MonsterAPI Website](https://monsterapi.ai/) - [Haystack GitHub Repository](https://github.com/deepset-ai/haystack) - [Haystack PyPI Package](https://pypi.org/project/haystack-ai) - [Report Issues](https://github.com/deepset-ai/haystack/issues) ## Getting Help For any questions or support, please refer to the [Haystack documentation](https://github.com/deepset-ai/haystack) or contact the [MonsterAPI support team](mailto:support@monsterapi.ai).