Stability AI logoStableLM

A seven billion parameter foundation model tuned for chat.

Deploy StableLM behind an API endpoint in seconds.

Deploy model

Example usage

This code example shows how to invoke the model using the requests library in Python. The model has a couple of key inputs:

  1. prompt: The input text sent to the model.

  2. max_new_tokens: Allows you to control the length of the output sequence.

The output of the model is a JSON object which has a key called output that contains the generated text.

Input
1import requests
2import os
3
4# Replace the empty string with your model id below
5model_id = ""
6baseten_api_key = os.environ["BASETEN_API_KEY"]
7
8data = {
9    "prompt": "Write a python script that computes the meaning of life.",
10    "max_new_tokens": 512,
11    "temperature": 0.9
12}
13
14# Call model endpoint
15res = requests.post(
16    f"https://model-{model_id}.api.baseten.co/production/predict",
17    headers={"Authorization": f"Api-Key {baseten_api_key}"},
18    json=data
19)
20
21# Print the output of the model
22print(res.json())
JSON output
1{
2    "output": "You are a software engineer.Your job is to write python code that calculates the meaning of life. You do this by using the PyMATH library.\nHere is an example of a simple python program that uses the MATH library:\n```\n# This is a test code using the math library\n\n# MATH library is used to create a function for calculating the sum of two numbers\n\ndef add(x, y):\n    return x + y\n\ndef subtract(x, y):\n    return x - y\n\ndef times_add(x, y):\n    return x * y\n\ndef times_subtract(x, y):\n    return x * y - y\n\ndef get_meaning(add, subtract, times_add, times_subtract):\n    result = 0\n    for i in range(0, 15):\n        result += times_add(i, times_subtract(add(i, subtract(i, i)) * i)\n    return result\n\n# Example usage: add 3, subtract -3, times_subtract 4, get 5\nprint(get_meaning(add, subtract, times_add, times_subtract))\n```\nThis program defines a function called `times_add` and `times_subtract` that takes an integer `i` and two integers `x` and `y` as arguments and calculates the number of times `i` is to be added, subtracted and multiplied with `x` and `y`.\n\nThe `times_add` function uses the formula `x * y = i` to multiply every integer `i` by `x` and `y` and adds up all the results.\n\nThe `times_subtract` function is almost the same, but instead of using the formula `x * y - y` it uses the formula `x * y - y - (y - y) * i` to subtract the previous multiplication result and add it to the current result.\n\nThe `get_meaning` function takes the `add` and `subtract` and `times_add` and `times_subtract` as arguments and returns the final result of the calculation.\n\nYou can run the program by running the following command in the terminal:\n```\npython script.py\n```\nAnd it will print the final result of the calculation."
3}

Deploy any model in just a few commands

Avoid getting tangled in complex deployment processes. Deploy best-in-class open-source models and take advantage of optimized serving for your own models.

$

truss init -- example stable-diffusion-2-1-base ./my-sd-truss

$

cd ./my-sd-truss

$

export BASETEN_API_KEY=MdNmOCXc.YBtEZD0WFOYKso2A6NEQkRqTe

$

truss push

INFO

Serializing Stable Diffusion 2.1 truss.

INFO

Making contact with Baseten πŸ‘‹ πŸ‘½

INFO

πŸš€ Uploading model to Baseten πŸš€

Upload progress: 0% | | 0.00G/2.39G