Model is a combination of data (which can include configuration, trained model weights, or other information) and code that defines how the model operates. By structuring your code to be compatible with this API, you benefit from a structured way to version your application so you can more systematically keep track of your experiments.
This guide shows you how to define a Weave Model, call it to capture inputs and outputs, take advantage of automatic versioning when your code or parameters change, serve the model behind a local API, and tag production calls for filtering. It’s for developers who build LLM-powered applications with Weave and want a repeatable way to track and compare iterations of their app.
- Python
- TypeScript
To create a model in Weave, you need the following:You can call the model as usual with:This tracks the model settings along with the inputs and outputs anytime you call After calling this, you see that you now have two versions of this model in the UI, each with different tracked calls.For additional instructions, see serve.
- A class that inherits from
weave.Model - Type definitions on all parameters
- A typed
predictfunction with@weave.op()decorator
predict(). You now have a versioned Weave Model that records every prediction it makes, which the following sections build on.Automatic versioning of models
When you change the parameters or the code that defines your model, Weave logs these changes and updates the version. This lets you compare predictions across versions of your model. Use this to iterate on prompts or to try a different LLM and compare predictions across settings.For example, here you create a new model:Serve models
Serving a model exposes itspredict function over HTTP, which is useful for testing it from other applications or sharing it with teammates without distributing the underlying code. To start a FastAPI server for a Weave model, replace [MODEL-REF] with the reference to your model and run: