DEV Community

Cover image for Introducing ModelFusion: Build AI apps with JavaScript and TypeScript
Lars Grammel
Lars Grammel

Posted on • Updated on • Originally published at modelfusion.dev

Introducing ModelFusion: Build AI apps with JavaScript and TypeScript

If you're a JavaScript or TypeScript developer, you've likely noticed the skyrocketing interest in building AI applications, especially since the launch of ChatGPT in November 2022. With AI on the rise, many are exploring new and creative ways to integrate models into applications, chatbots, and agents. But here's a common roadblock: there are few libraries designed specifically for JS/TS developers that ease working with AI models, including LLMs (Large Language Models).

Maybe you've experienced this yourself, as I did: You start with something like LangChain, build your first app, and feel a sense of accomplishment. But then, you hit a wall as you realize it's not easily adjustable to your unique needs. You might then resort to using OpenAI or other APIs directly, only to end up rolling your own framework. It's a path filled with complexity and unnecessary hassle.

That's why I created ModelFusion. I went through this exact process and recognized the need for a solution that provides many reusable elements and unification across models without being too constraining. Unlike other tools that may feel like "black magic," ModelFusion is designed as a library, not a framework. Think of it as a toolbox that empowers you with full power and control over the underlying models, adding support features with minimal overhead.

Quick Example

Here's a simple example demonstrating how you might use ModelFusion to generate text with OpenAI:

import { generateText, openai } from "modelfusion";

const text = await generateText({
  model: openai.CompletionTextGenerator({
    model: "gpt-3.5-turbo-instruct",
  }),
  prompt: "Write a short story about a robot learning to love: ",
});
Enter fullscreen mode Exit fullscreen mode

The response also contains additional information such as the metadata and the full response. The ModelFusion documentation contains many examples and demo apps.

Key Features

Here are the features that make ModelFusion stand out:

  • Type Inference and Validation: Leveraging TypeScript and Zod, ModelFusion ensures that you get exactly what you expect from your models. No more guesswork, only clear and validated responses.
  • Flexibility and Control: You're in charge of your prompts, settings, and raw model responses. Adjust and adapt without feeling boxed in by the framework.
  • No Chains and Predefined Prompts: Start from examples and build applications using familiar JavaScript concepts. Clear and explicit, without any confusing black magic.
  • Support for different AI Models: Go beyond text with integrations like text-to-image and voice-to-text. ModelFusion supports a variety of models to suit your creative vision.
  • Integrated Support Features: Focus on your application with essential features like logging, retries, throttling, tracing, and error handling built right in.

ModelFusion integrates with a diverse range of model providers, vector indices, and observability tools, such as OpenAI, Llama.cpp, Pinecone, and Helicone. This growing list of integrations offers you, the JS/TS developer, a flexible and adaptable toolbox to suit your unique needs, without any unnecessary complexity.

Getting Started

Here's what you need to kickstart your journey with ModelFusion:

  1. Explore the Code: Visit the ModelFusion GitHub repository to take a closer look at the source code, contribute, or even raise an issue if you encounter any challenges.
  2. Read the Docs: If you want to dive deep into the functionalities, the ModelFusion documentation is packed with examples, demo apps, and tutorials that will guide you through various use cases and integrations.
  3. Join the Community: Have any questions or need help? Don't hesitate to engage with other like-minded developers in the ModelFusion Discord. We're here to support each other.

If you're working with AI models in JavaScript or TypeScript, explore ModelFusion; your feedback and participation can shape this toolkit to better serve the developer community.

Top comments (7)

Collapse
 
ben profile image
Ben Halpern

Looks really well thought out

Collapse
 
lgrammel profile image
Lars Grammel

Thank you!

Collapse
 
ironside profile image
HighFather (LightSide)

Thanks for sharing this 🙌

Collapse
 
scofieldidehen profile image
Scofield Idehen

This is an exciting way to look at it, i find the approcah convincing and interesting, would definatly go test it out.

Thumbs up.

Collapse
 
fanpelt profile image
Rene

Awesome, looking forward to checking it out!

Collapse
 
evasteps_83 profile image
Eva

Thanks for sharing and publishing this!

Collapse
 
adetimmy_ profile image
Adetimmy

Nice, will definitely look it up!