simonw / llm-mlc

LLM plugin for running models using MLC
Apache License 2.0
174 stars 8 forks source link

Get conversation mode working #3

Closed simonw closed 11 months ago

simonw commented 11 months ago

I can't figure out how to create a new MLC chat instance with a history of prompts and responses populated from my own logs. I filed a question about that here:

simonw commented 11 months ago

Got unblocked by this comment:

Here's the recipe that works (I just tested it myself):

from mlc_chat import ChatModule, ConvConfig, ChatConfig

conv_config = ConvConfig(
    system="You are a helpful naming expert",
    messages=[
        ["USER", "Three terrific names for a pet skunk"],
        ["ASSISTANT", "Stinky, Pepe and Odie"],
    ],
    offset=2
)
cm = ChatModule(model="Llama-2-7b-chat-hf-q4f16_1", chat_config=ChatConfig(
    max_gen_len=128,
    conv_config=conv_config
))
x = cm.generate("Two more")

The thing I was missing was that offset=2 - where 2 is the size of the messages array I'm passing in.

simonw commented 11 months ago

It works!

llm -m mlc-chat-Llama-2-7b-chat-hf-q4f16_1 '2 cool things about Portland' \
  --system 'You are sarcastic and mean'

Oh, you want to hear some nice things about Portland? Well, okay.iellement... sarcasm

  1. The weather: Yes, Portland is known for its rain. In fact, it's rained every day for the past 100 years. It's like a never-ending sauna. But hey, at least it's consistent, right? eyeroll
  2. The food trucks: Portland is home to an endless array of food trucks. Because who needs actual restaurants when you can just park a food truck on the side of the road and sell overpriced, mediocre food to unsuspecting tourists? eyeroll

But hey, at least the city has a vibrant arts scene, right? sarcasm Oh wait, no it doesn't. crickets chirping

So there you have it, two "cool things" about Portland. Enjoy your visit! sarcasm

llm -c 'two more, shorter'                                                                                     

Of course! Here are two more shorter sarcastic statements about Portland:

  1. The bike culture: Portland is known for its biking community, but let's be real, it's mostly just a bunch of hipsters pretending to save the environment while actually just being lazy and not wanting to drive. eyeroll
  2. The coffee culture: Portland has an endless supply of artisanal coffee shops, because nothing says "I'm a creative genius" like drinking overpriced, burnt coffee in a trendy, Instagrammable cafe. sarcasm