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
Download handler.py from teapotai/tinyteapot: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/teapotai/tinyteapot/resolve/8a4e9e94dea3500a1fab15ae1ce17e279a336340/handler.py
- Command line
-
hf download hf://teapotai/tinyteapot@8a4e9e94dea3500a1fab15ae1ce17e279a336340/handler.py
-
curl -L -o handler.py https://huggingface.co/teapotai/tinyteapot/resolve/8a4e9e94dea3500a1fab15ae1ce17e279a336340/handler.py
2.45 kB
| 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'." | |
| ) | |
| 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} |