Text Generation
Transformers
Safetensors
English
t5
text2text-generation
seq2seq
flan-t5
lightweight
grounded-qa
text-generation-inference
Instructions to use teapotai/tinyteapot with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use teapotai/tinyteapot with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="teapotai/tinyteapot")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("teapotai/tinyteapot") model = AutoModelForSeq2SeqLM.from_pretrained("teapotai/tinyteapot", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use teapotai/tinyteapot with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "teapotai/tinyteapot" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "teapotai/tinyteapot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/teapotai/tinyteapot
- SGLang
How to use teapotai/tinyteapot with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "teapotai/tinyteapot" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "teapotai/tinyteapot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "teapotai/tinyteapot" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "teapotai/tinyteapot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use teapotai/tinyteapot with Docker Model Runner:
docker model run hf.co/teapotai/tinyteapot
File size: 2,446 Bytes
21235f2 8334c0b 21235f2 8a4e9e9 8334c0b 21235f2 8a4e9e9 21235f2 8a4e9e9 21235f2 8334c0b 21235f2 8334c0b 4e1ab77 21235f2 4e1ab77 8a4e9e9 4e1ab77 21235f2 8334c0b 21235f2 4e1ab77 8334c0b 8a4e9e9 8334c0b 21235f2 8a4e9e9 21235f2 8a4e9e9 21235f2 8334c0b 4e1ab77 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
MODEL_NAME = "teapotai/tinyteapot"
MAX_INPUT_TOKENS = 512
class EndpointHandler:
def __init__(self, path: str = ""):
# EXACTLY like your snippet: load by repo id from Hugging Face Hub
self.tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
self.model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
self.model.eval()
self.device = torch.device("cpu")
self.model.to(self.device)
self.system_prompt = (
"You are Teapot, an open-source AI assistant optimized for low-end devices, "
"providing short, accurate responses without hallucinating while excelling at "
"information extraction and text summarization. "
"If the context does not answer the question, reply exactly: "
"'I am sorry but I don't have any information on that'."
)
@torch.inference_mode()
def __call__(self, data):
inputs = data.get("inputs")
if inputs is None:
raise ValueError("Missing required field 'inputs'.")
# Support:
# 1) inputs is a full prompt string (closest to your snippet)
# 2) inputs is {"context": ..., "question": ...}
if isinstance(inputs, str):
prompt = inputs
elif isinstance(inputs, dict):
context = inputs.get("context", "")
question = inputs.get("question", "")
prompt = f"{context}\n{self.system_prompt}\n{question}\n"
else:
raise ValueError("inputs must be a string OR an object with 'context' and 'question'.")
# Match your code path
enc = self.tokenizer(prompt, return_tensors="pt")
input_ids = enc["input_ids"]
attention_mask = enc["attention_mask"]
# Keep only the most recent tokens if too long
if input_ids.shape[1] > MAX_INPUT_TOKENS:
input_ids = input_ids[:, -MAX_INPUT_TOKENS:]
attention_mask = attention_mask[:, -MAX_INPUT_TOKENS:]
input_ids = input_ids.to(self.device)
attention_mask = attention_mask.to(self.device)
outputs = self.model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
do_sample=False,
)
answer = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
return {"generated_text": answer} |