Instructions to use rwl4/gpt2-medium-chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rwl4/gpt2-medium-chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="rwl4/gpt2-medium-chat")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("rwl4/gpt2-medium-chat") model = AutoModelForCausalLM.from_pretrained("rwl4/gpt2-medium-chat") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use rwl4/gpt2-medium-chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "rwl4/gpt2-medium-chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rwl4/gpt2-medium-chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/rwl4/gpt2-medium-chat
- SGLang
How to use rwl4/gpt2-medium-chat 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 "rwl4/gpt2-medium-chat" \ --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": "rwl4/gpt2-medium-chat", "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 "rwl4/gpt2-medium-chat" \ --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": "rwl4/gpt2-medium-chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use rwl4/gpt2-medium-chat with Docker Model Runner:
docker model run hf.co/rwl4/gpt2-medium-chat
how do i get it to not repeat what i said on answer?
here is my code im trying to get it to just reply but without repeating example also im not sure about the warning? :
%Run ai_test1.py
Listening...
You said: hello how are you today
C:\Users\xanth\AppData\Roaming\Python\Python310\site-packages\transformers\generation\utils.py:1421: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )
warnings.warn(
Chatbot: hello how are you today?
A. I'm doing well.
B. How about you?
C. Good morning. How are things going? How long have you been here? What do you think of the new
Listening...
You said: can you tell me a joke
Chatbot: can you tell me a joke about a cat?user
What is the most common way to describe a person who is a genius?
A person with a brilliant mind.assistant
The most commonly used way of describing a
#!/usr/bin/python3
import sys
import pyttsx3
import speech_recognition as sr
#from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load the model and tokenizer
#tokenizer = AutoTokenizer.from_pretrained("liam168/chat-DialoGPT-small-en")
#model = AutoModelForSeq2SeqLM.from_pretrained("liam168/chat-DialoGPT-small-en")
tokenizer = AutoTokenizer.from_pretrained("rwl4/gpt2-medium-chat")
model = AutoModelForCausalLM.from_pretrained("rwl4/gpt2-medium-chat", pad_token_id=50256)
def generate_response(user_input):
input_ids = tokenizer.encode(user_input, return_tensors="pt")
response_ids = model.generate(input_ids, max_length=50, num_return_sequences=1, no_repeat_ngram_size=2)
response = tokenizer.decode(response_ids[0], skip_special_tokens=True)
return response
def listen_to_command():
r = sr.Recognizer()
while True:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("Listening...")
try:
audio = r.listen(source)
command = r.recognize_google(audio)
print("You said:", command)
response = generate_response(command)
print("Chatbot:", response)
speak(response)
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service:", str(e))
def speak(text):
tts_engine = pyttsx3.init()
tts_engine.say(text)
tts_engine.runAndWait()
if __name__ == "__main__":
listen_to_command()