Search And Generate Toolhouse
Toolhouse is a comprehensive infrastructure platform designed for developing, deploying, and managing tool-based capabilities in large language models (LLMs).
Toolhouse enables seamless integration of external functionalities—referred to as tools—into LLM workflows.
Key tool capabilities include:
- Extracting structured and unstructured data from web or social media sources
- Programmatically generating images
- Executing code snippets and returning computed outputs
This cookbook provides a technical guide on enhancing LLMs deployed on Fireworks.AI with tool-based extensions, eliminating the need for manual coding or explicit prompt engineering.
In this demonstration, we detail the process of configuring an LLM to generate images based on real-time data inputs.
We will leverage Toolhouse with the firefunction-v2 model, hosted on Fireworks's infrastructure.
This model is optimized for high-precision tool utilization, ensuring robust and accurate execution of integrated tasks.
1. Setup
Let's install the dependencies. We will use the OpenAI SDK which is compatible with Fireworks's API - as long as we set the base_url.
We're also installing Toolhouse's Python SDK to access pre-built, pre-hosted tools.
To integrate Fireworks and Toolhouse, you'll need to set up two environment variables: FIREWORKS_API_KEY and TOOLHOUSE_API_KEY. Follow these steps to obtain your API keys:
- Fireworks API Key: Get your key by visiting the Fireworks API Console.
- Toolhouse API Key: Sign up for Toolhouse using this link to receive FREE credits. You will receive your API key as part of the onboarding step, and you can always, navigate to the Toolhouse API Keys page to create and get an API key.
- Install the X tool: In your Toolhouse dashboard, click Install next to the "Search X" tool (direct link).
- Install the Image Generation tool: In your Toolhouse dashboard, click Install next to the "Image Generation" tool (direct link).
Set up keys in Colab
Once you have signe-up and got both API keys, set them as environment variables to start using Fireworks with Toolhouse.
To do that click on the Key icon in the left menu on Colab and click "Add new secret".
Create 2 keys and make sure their name is spelled like below:
FIREWORKS_API_KEY
TOOLHOUSE_API_KEY
Enter the values for each key and switch on the allow note book access"
2. Setting up the SDKs
Since we've imported the SDKs already, let's initialize them and authenticate ourselves using the API keys we just set.
If you want to check again, your API keys should be now in the left sidebar of Google Colab after clicking the key icon.
We will use the accounts/fireworks/models/firefunction-v2 model.
This model is based on the Mixtral model and was fine-tuned for tool use and function calling:
We can test that we can call the model hosted on Fireworks by running the cell below. It should output some info about NYC.
Well, the Big Apple, the City That Never Sleeps, New York City, there's just so much to love about this place! The energy is electric, the diversity is unparalleled, and the opportunities are endless. From iconic landmarks like the Statue of Liberty, Central Park, and Times Square, to world-class museums like the Met and MoMA, there's always something new to explore and discover. And let's not forget about the food – from classic New York-style pizza and bagels to cutting-edge culinary innovations, your taste buds will never be bored. Plus, with some of the best universities and research institutions in the world, NYC is a hub for learning and innovation. So, why is New York so awesome? Because it's the city where dreams come true, where anything is possible, and where the world comes to live, work, and play!
Likewise, you can use the th.get_tools() function to display all of the Toolhouse tools you have installed:
For this demo, we will be using two tools from Toolhouse's store.
- Search X
- Image generation
The first tool lets you search the X social network and the second tool lets you generate an image from a prompt and returns it to the LLM.
3. Configure Tool Calls
First we'll configure the user prompt to the LLM.
This is a basic python list with a dictionary within it that takes role and a content.
We set role to user because this is a command that we, the user, want the LLM to understand.
Doing so will allow us to give a specific command to the LLM. The LLM will look at what tools we have available and attempt to leverage them to achieve the task.
We'll send this message to our LLM hosted on Fireworks.
Because we have tools provided by Toolhouse we can skip having to code our own Search X parser. The tools are hosted and maintained by the Toolhouse team and are optimized for LLM usage.
As you can see from the output above, the LLM properly identified that we'd like to invoke the 'search_x' tool
You can see the arguments it generated by running the code below, it will break iut down by ID, type and function arguments:
4. Execute Tool Call
Now that we learned how the LLM can generate arguments to pass to a function we'll have to run the function with those arguments.
The tool gets executed via the run_tools command, with the parameters that were identified in the previous LLM call.
After that we will get the result, and append it to the context, the messages variable.
Let's see what our messages list looks like:
We're now going to pass the whole message chain to the LLM. The LLM will generate a proper response based on our initial prompt:
Find the last three messages from the account named @FireworksAI_HQ on X/Twitter and summarize them in one sentence. Make it funny!
4.1 The Funny Summary
LLM RESPONSE: The last three messages from @FireworksAI_HQ on X/Twitter summarize to this funny sentence: "One day, @FireworksAI_HQ just woke up and decided to rule all complex reasoning benchmarks with its new model, f1. But then it got distracted by all the sweet AI Game Night invites and forgot to conquer the world... yet!" 😂
Let's add this last response - a funny summary of three posts retrieved from X - to the history of messages.
To achieve this we're combining two arrays into a new variable called new_messages.
Next we're going to give a new command to the LLM - generate us an image from this funny caption using the tool provided by Toolhouse.
This tool uses Flux - an image model hosted on Fireworks, then hosts it to a storage location on the img.toolhouse.ai subdomain.
This shows you that a tool can be used to perform multiple action at once (image generation and hosting), but it's up to you - the user and creator of tools - how to set up every tool for best agentic use.
We've installed this tool in step 1.
Now that the LLM generated an image and stored it, we just want it to let the user know that the image is ready and can be viewed.
We're going to - yet again - ask the LLM to take the output of the function call and generate a response.
[{'role': 'user', 'content': 'Find the last three messages from the account named @FireworksAI_HQ on X/Twitter and summarize them in one sentence. Make it funny!'}, {'content': None, 'role': 'assistant', 'tool_calls': [{'id': 'call_059bQb1Ev2JA4CwMyK7PoTPY', 'function': {'arguments': '{"query": "@FireworksAI_HQ", "max_results": 3}', 'name': 'search_x'}, 'type': 'function', 'index': 0}]}, {'role': 'tool', 'tool_call_id': 'call_059bQb1Ev2JA4CwMyK7PoTPY', 'name': 'search_x', 'content': '<tweet>After #AWSreInvent sessions, it’s time for AI Game Night on Dec 3rd! 🎮 \n\nJoin @MongoDB, @arizeai, @FireworksAI_HQ & @HasuraHQ for games, drinks, and networking with tech innovators.\n\nDon’t miss it! RSVP today. 👇\nhttps://t.co/upX3tWOA7x https://t.co/rDls8EJAKt\nby @Karissa_Wood_ at 2024-11-19T23:21:01.000Z\n Conversation ID: 1859014042683126052\n\n<tweet>\n\n<tweet>Will you be at @awscloud re:Invent 2024 next month?\n\nJoin us, @mongodb, @cohere, and @FireworksAI_HQ on Dec 4 at 1 PM (Wynn Las Vegas, Bollinger room) for a panel on building scalable, high-performance #genAI apps. \n\nHear from top AI leaders and learn how to level up your AI stack.\n\nDon’t miss it! #reInvent2024 #Anyscale #AI\nby @anyscalecompute at 2024-11-19T20:11:57.000Z\n Conversation ID: 1858966463010533522\n\n\nPhoto: <tweet>\n\n<tweet>🏎️ f1 - a new complex reasoning model from @FireworksAI_HQ \n\nseems like this one slipped under the radar a bit yesterday, I haven\'t seen a ton of mentions of it\n\n> 🏎️ f1 is a new "Compound AI" system from Fireworks AI that "interweaves several different open models at inference time"\n\nit\'s beating both gpt-4o and Sonnet 3.5 on complex reasoning benchmarks (note: o1-preview is still the reasoning king 👑 )\n\nthe advantage is that you can give it a complex reasoning task and it will autonomously leverage the built in compound reasoning capabilities with a single prompt, extracting away the complexity of building your own compound system\n\nin the video you can see me asking it everyone\'s favorite reasoning task 🍓\n\nit breaks down the question first by enumerating the letters, then answers correctly\nby @daniel_mac8 at 2024-11-19T18:33:19.000Z\n Conversation ID: 1858941639776956457\n\n\n(Video)[https://pbs.twimg.com/ext_tw_video_thumb/1858941506515533824/pu/img/8Bt7W05G-Ee2lVb9.jpg]\nSources:\n [video/mp4](https://video.twimg.com/ext_tw_video/1858941506515533824/pu/vid/avc1/1280x720/AT1O_yX8M3CrxZNk.mp4?tag=14)\n[video/mp4](https://video.twimg.com/ext_tw_video/1858941506515533824/pu/vid/avc1/640x360/Un-jwHJYiGNnE05g.mp4?tag=14)\n[video/mp4](https://video.twimg.com/ext_tw_video/1858941506515533824/pu/vid/avc1/1920x1080/4TEGJvNlzb2T5ROp.mp4?tag=14)\n[application/x-mpegURL](https://video.twimg.com/ext_tw_video/1858941506515533824/pu/pl/vCYM85adEMYwB5Vc.m3u8?tag=14)\n[video/mp4](https://video.twimg.com/ext_tw_video/1858941506515533824/pu/vid/avc1/480x270/_y3mwsXfuT72796Q.mp4?tag=14)<tweet>\n\n<tweet>@RubiksAI @lqiao @FireworksAI_HQ @dzhulgakov Impressive scaling. Intriguing connection to real-time data too.\nby @SufiyanSIshaq at 2024-11-19T17:14:31.000Z\n Conversation ID: 1819832483040604370\n\n\n<tweet>\n\n<tweet>You can now try f1 by @FireworksAI_HQ in the AI Analyst app: https://t.co/RnwBrDxHTv\nby @e2b_dev at 2024-11-19T16:05:01.000Z\n Conversation ID: 1858904318826414561\n\n beats most popular LLMs across benchmarks\n\nf1 is a compound AI model, that is, an LLM-based system with more components, e.g., chaining multiple models, retrievers, or external tools\n\nSee how to try f1 for free in the ✴️@e2b_dev AI Analyst app ✴️👇\nby @tereza_tizkova at 2024-11-19T16:03:57.000Z\n Conversation ID: 1858904053041754260\n\n\nPhoto: <tweet>\n\n<tweet>@cognitivecompai @huybery @Yuchenj_UW @lmarena_ai @FireworksAI_HQ @NousResearch Paris Hackathons too 🤗\n\nI\'ll be there for the next 1.5 months haha\nby @calebfahlgren at 2024-11-19T15:10:14.000Z\n Conversation ID: 1858727523619885215\n\n\n<tweet>\n\n<tweet>After #AWSreInvent sessions, it’s time for AI Game Night on Dec 3rd! 🎮 \n\nJoin @MongoDB, @arizeai, @FireworksAI_HQ & @HasuraHQ for games, drinks, and networking with tech innovators.\n\nDon’t miss it! RSVP today. 👇\nhttps://t.co/6wtwpEQluN https://t.co/8xS8SEPVB5\nby @pietrosandonato at 2024-11-19T13:32:38.000Z\n Conversation ID: 1858865970938278236\n\n<tweet>\n\n<tweet>@sonyatweetybird @FireworksAI_HQ try it out here: https://t.co/yL4EvPFrzN https://t.co/H1Uvzu0ngd\nby @_akhaliq at 2024-11-19T07:17:08.000Z\n Conversation ID: 1858614388787474769\n\n<tweet>\n\n<tweet>After #AWSreInvent sessions, it’s time for AI Game Night on Dec 3rd! 🎮 \n\nJoin @MongoDB, @arizeai, @FireworksAI_HQ & @HasuraHQ for games, drinks, and networking with tech innovators.\n\nDon’t miss it! RSVP today. 👇\nhttps://t.co/fcIaTshU64 https://t.co/wzlzAierct\nby @anujbpanchal at 2024-11-19T07:01:19.000Z\n Conversation ID: 1858767494418239611\n\n<tweet>\n'}, {'role': 'assistant', 'content': 'The last three messages from @FireworksAI_HQ on X/Twitter summarize to this funny sentence: "One day, @FireworksAI_HQ just woke up and decided to rule all complex reasoning benchmarks with its new model, f1. But then it got distracted by all the sweet AI Game Night invites and forgot to conquer the world... yet!" 😂'}, {'role': 'user', 'content': 'Generate an image from the funny summary'}, {'content': None, 'refusal': None, 'role': 'assistant', 'audio': None, 'tool_calls': [{'id': 'call_Fb1JuuM8vGUskB7qGWtrg2gT', 'function': {'arguments': '{"prompt": "a photo of a cat, sitting on the couch, looking at the camera with its ruler hat, beside a table with notebooks labeled @FireworksAI_HQ f1. The background is a world map. The cat\'s face is funny and curious. There is a small AI Game Night invitation on top of the table", "width": "512", "height": "512", "steps": "15"}', 'name': 'image_generation_flux'}, 'type': 'function', 'index': 0}]}, {'role': 'tool', 'tool_call_id': 'call_Fb1JuuM8vGUskB7qGWtrg2gT', 'name': 'image_generation_flux', 'content': '{"result":"https://img.toolhouse.ai/7E4EnI.jpg"}'}]
LLM RESPONSE: 
And there you have it, if you have managed to run all the cells in the correct order you should see a message with a valid URL. If you click it you will be able to see the generated image! The image is pretty random and truly depends on what "funny summary" we generated in step 4.1