mistralai / mistral-inference

Official inference library for Mistral models
https://mistral.ai/
Apache License 2.0
9.77k stars 874 forks source link

add Makefile #209

Open bionicles opened 3 months ago

bionicles commented 3 months ago

this Makefile enables developers to download and extract three Mistral open source models with a single word: make

Models included:

Note: there would still be some additional setup needed, specifically to tell the mistral-chat CLI where to find the models

If it's helpful, I can help update the README to show how to use the makefile We can also have the makefile install and run the cli We can even make it idempotently add mistral-models to the $PATH by adding code to their profile (example: https://github.com/bionicles/tree_plus/blob/main/tree_plus_src/scripts/alias_tree_plus.sh)

inlined here and lightly modified to save you a click

#!/bin/bash

# set your RC_FILE to .bashrc if you use bash 
# or set it to .zshrc if you use zsh
RC_FILE=~/.bash_profile # where the aliases will be added

# Function to idempotently add an alias if it doesn't exist in RC_FILE
add_alias() {
    grep -qF "alias $1=\"$2\"" $RC_FILE || echo "alias $1=\"$2\"" >> $RC_FILE
}

# Add alias
add_alias mc mistral-chat 

ah here's another nice script chunk that would enable the one above to automatically add a line to the user's profile which would indicate the path to find the mistral_models

export DEBUG=true

# ensure lines are added to a file only once
function idempotent_add_line_to_file() {
  local line="$1"
  local file="$2"
  # Check if the line already exists in the file
  if grep -Fxq "$line" "$file"; then
    ${DEBUG:=false} && echo "DEBUG(idempotent_add_line_to_file) line '$line' already in '$file'"
  else
    echo "$line" >> "$file"
    echo "DEBUG(idempotent_add_line_to_file) SCRIPT_DIR: $SCRIPT_DIR"
    echo "The line '$line' was added to '$file'"
  fi
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "DEBUG(idempotent_add_line_to_file) SCRIPT_DIR: $SCRIPT_DIR"
idempotent_add_line_to_file "export MISTRAL_MODELS_PATH=$SCRIPT_DIR/mistral_models" "$HOME/$RC_FILE"
export -f idempotent_add_line_to_file

key idea: it only adds the line once, so it won't keep re-adding it

could enable mistral to install local terminal utilities more easily without needing to tell people to tinker with their path too much

Anyway: TLDR - make it easier to download the models, and this description contains a couple of bash fragments to make it even easier