Instructions to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2") model = AutoModelForCausalLM.from_pretrained("Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - llama-cpp-python
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2", filename="Mistral-7B-Instruct-v0.1-function-calling-v2.Q4_K.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 # Run inference directly in the terminal: llama cli -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 # Run inference directly in the terminal: llama cli -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 # Run inference directly in the terminal: ./llama-cli -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 # Run inference directly in the terminal: ./build/bin/llama-cli -hf Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
Use Docker
docker model run hf.co/Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
- LM Studio
- Jan
- vLLM
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
- SGLang
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 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 "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with Ollama:
ollama run hf.co/Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
- Unsloth Studio
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 to start chatting
- Atomic Chat new
- Docker Model Runner
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with Docker Model Runner:
docker model run hf.co/Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
- Lemonade
How to use Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2
Run and chat with the model
lemonade run user.Mistral-7B-Instruct-v0.1-function-calling-v2-{{QUANT_TAG}}List all available models
lemonade list
How to properly return function call return values
Hello,
I have a simple program working with this model but realized that I wasn't sure how to send the function's output back to the model. Do you just put the raw value back as part of the user message or does it need to be wrapped in a special tag so the LLM knows that it is a response from the last function call?
Thanks,
Jason O
Two options (depending on what kind of function you're using):
A. Replace the json in the assistant's message with the function call response. (if your function returns a clean answer that is useful for the user).
B. Add the function response as a new user message, prepended by "Here is the response to that function call:\n\n{function_response}", then let the llm generate a new assistant response now that it has the required data. After getting back this new assistant response, you can optionally drop the function call message and the function response message from the array of messages (so that the user is blind to the entire process).
Thank you for getting back with me!
I tried approach B and it seems to kind of work. But I just realized that I may not be formatting my prompts correctly and wanted to confirm with you if I am doing it correctly.
So far, I'm able to get the model to send function calls and I'm able to execute them and return the value. (How the model is responding is another story that I'll take a look at next). My first question is about the use of the tags and their placement.
Example with 1 user prompt:
<FUNCTIONS>
</FUNCTIONS>
[INST]<<SYS>>
System Prompt here
<</SYS>>
User Prompt 1 [/INST]
Example with two user prompts:
<FUNCTIONS>
</FUNCTIONS>
<s>[INST]<<SYS>>
System Prompt here
<</SYS>>
User Prompt 1 [/INST] Assistant response here</s>
[INST]User Prompt 2 [/INST]
Example with three user prompts:
<FUNCTIONS>
</FUNCTIONS>
<s>[INST]<<SYS>>
System Prompt here
<</SYS>>
User Prompt 1 [/INST] Assistant response 1</s>
<s>[INST]User Prompt 2 [/INST] Assistant response 2</s>
[INST]User Prompt 3 [/INST]
Example with four user prompts:
<FUNCTIONS>
</FUNCTIONS>
<s>[INST]<<SYS>>
System Prompt here
<</SYS>>
User Prompt 1 [/INST] Assistant response 1</s>
<s>[INST]User Prompt 2 [/INST] Assistant response 2</s>
<s>[INST]User Prompt 3 [/INST] Assistant response 3</s>
[INST]User Prompt 4 [/INST]
Does this look correct?
Yeah, that looks about right.
BTW, with Llama it's common to have a space after [INST] and before [/INST], so it would be:
[INST] {prompt} [/INST]
You can see that in the model card.