# Model Picker

A prompt field for an AI chat with a model chip and a send button. Click the chip (or press the down arrow on it) to open the menu. Point at a model, or move to it with the arrow keys, and its speed, quality and cost bars fill while the footer tray rolls to its first-token time and price. Turn on extended thinking to choose an effort level, which also raises the time in the tray. The demo walks through the menu on its own until you point at it.

<demo-model-picker>



</demo-model-picker>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/model-picker.json"
```

## Usage

```vue
<script setup lang="ts">
  import { ref } from 'vue';
  import ModelPicker from '~/components/ui/model-picker/ModelPicker.vue';
  import type {
    ModelPickerEffortLevel,
    ModelPickerModel,
    ModelPickerSubmit,
  } from '~/components/ui/model-picker/types';

  const models: ModelPickerModel[] = [
    {
      id: 'large',
      name: 'Large',
      tagline: 'Hardest problems',
      speed: 2,
      quality: 5,
      cost: 5,
      latency: 2.1,
      price: 25,
    },
    {
      id: 'small',
      name: 'Small',
      tagline: 'Quick and light',
      speed: 5,
      quality: 3,
      cost: 1,
      latency: 0.4,
      price: 4,
    },
  ];

  const model = ref('large');
  const thinking = ref(false);
  const effort = ref<ModelPickerEffortLevel>('medium');
  const webSearch = ref(false);

  function send(payload: ModelPickerSubmit): void {
    console.log(payload);
  }
</script>

<template>
  <ModelPicker
    v-model="model"
    v-model:thinking="thinking"
    v-model:effort="effort"
    v-model:web-search="webSearch"
    :models="models"
    @submit="send"
  />
</template>
```

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        models
      </code>
    </td>
    
    <td>
      <code>
        ModelPickerModel[]
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      Models in the menu. See the model fields below.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        model-value
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      <code>
        v-model
      </code>
      
      . Id of the selected model, or <code>
        'auto'
      </code>
      
      . Empty picks the first one.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        thinking
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      <code>
        v-model:thinking
      </code>
      
      . Extended thinking on or off.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        effort
      </code>
    </td>
    
    <td>
      <code>
        'low' | 'medium' | 'high'
      </code>
    </td>
    
    <td>
      <code>
        'medium'
      </code>
    </td>
    
    <td>
      <code>
        v-model:effort
      </code>
      
      . Thinking effort. Shown while thinking is on.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        web-search
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      <code>
        v-model:web-search
      </code>
      
      . Web search on or off.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        prompt
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      <code>
        v-model:prompt
      </code>
      
      . Text in the prompt field.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        open
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      <code>
        v-model:open
      </code>
      
      . Whether the menu is open.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        show-auto
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Adds an Auto row. Its id is <code>
        'auto'
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        auto-label
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Auto'
      </code>
    </td>
    
    <td>
      Name of the Auto row.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        auto-tagline
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Picks per message'
      </code>
    </td>
    
    <td>
      Tagline of the Auto row.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        placeholder
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Ask anything…'
      </code>
    </td>
    
    <td>
      Placeholder of the prompt field.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        accent
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#3b76e1'
      </code>
    </td>
    
    <td>
      Colour of filled bars, checks and switches.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        effort-scale
      </code>
    </td>
    
    <td>
      <code>
        Record<Effort, number>
      </code>
    </td>
    
    <td>
      <code>
        { low: 1.8, medium: 2.6, high: 4 }
      </code>
    </td>
    
    <td>
      Multiplies the first-token time when thinking is on.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        hints
      </code>
    </td>
    
    <td>
      <code>
        ModelPickerHints
      </code>
    </td>
    
    <td>
      see source
    </td>
    
    <td>
      Tray texts for Auto, thinking on/off and web search on/off.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        autoplay
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        false
      </code>
    </td>
    
    <td>
      Opens the menu and steps through it on its own. Stops when the user interacts.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element.
    </td>
  </tr>
</tbody>
</table>

## Model fields

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Unique id, used as the <code>
        v-model
      </code>
      
       value.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Name in the chip and the menu.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        tagline
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      One line under the name.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        glyph
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Letter in the icon tile. Defaults to the first letter.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        icon
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Iconify name, e.g. <code>
        lucide:zap
      </code>
      
      . Replaces the glyph.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        speed
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Speed rating from 0 to 5.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        quality
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Quality rating from 0 to 5.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cost
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Cost rating from 0 to 5.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        latency
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Seconds to the first token, without extended thinking.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        price
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Dollars per million tokens.
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        submit
      </code>
    </td>
    
    <td>
      <code>
        ModelPickerSubmit
      </code>
    </td>
    
    <td>
      Fires on send or Enter in the prompt with <code>
        { prompt, model, thinking, effort, webSearch }
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The chip is a button with `aria-haspopup="menu"` and `aria-expanded`. Enter, Space or the down arrow opens the menu on the selected model; the up arrow opens it on the last item.
- Model rows are `menuitemradio` items with `aria-checked`. Thinking and web search are `menuitemcheckbox` items.
- The effort control is a group of `menuitemradio` items. Left and right arrows change the effort.
- Up and down arrows, Home and End move through the menu. Enter or Space activates an item. Escape closes the menu and returns focus to the chip. Tab or a click outside closes it.
- The tray is an `aria-live` region, so the time and price are announced.
- With reduced motion the menu fades without movement and the bars and numbers change without animation.
