Update README.md
Browse files
README.md
CHANGED
|
@@ -1,202 +1,86 @@
|
|
| 1 |
-
-
|
| 2 |
-
base_model: mistralai/Mistral-7B-Instruct-v0.2
|
| 3 |
-
library_name: peft
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
# Model Card for Model ID
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
## Model Details
|
| 13 |
-
|
| 14 |
-
### Model Description
|
| 15 |
-
|
| 16 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
-
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
|
| 197 |
-
##
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 201 |
|
| 202 |
-
|
|
|
|
| 1 |
+
# MCP Tool-Calling Agent (v1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
This repository contains a specialized version of `mistralai/Mistral-7B-Instruct-v0.2`, fine-tuned to function as a reasoning engine for a tool-calling AI agent.
|
| 4 |
|
| 5 |
+
The model has been trained to understand natural language requests related to a custom set of "MCP" tools and translate them into a specific, structured format suitable for execution in an application backend.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
---
|
| 8 |
+
## Model Description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
This model was fine-tuned using **Parameter-Efficient Fine-Tuning (PEFT)** with **LoRA** on a custom, high-quality dataset. Its primary skill is to receive a user prompt and generate a tool call in a specific, sandboxed format. While the fine-tuning has exposed it to several tool types, its core capability is understanding the intent to use a tool and structuring the output accordingly.
|
| 11 |
|
| 12 |
+
The model expects prompts in a `SYSTEM-USER-ASSISTANT` format and has been trained to generate tool calls with the 'tool_code' format..
|
| 13 |
|
| 14 |
+
## Intended Use
|
| 15 |
|
| 16 |
+
This model is not a general-purpose chatbot. It is a specialized component intended to be used within a larger application or "agent" that can parse and execute the generated code.
|
| 17 |
|
| 18 |
+
* **Primary Use:** Translating natural language commands into structured code for automation.
|
| 19 |
+
* **Out of Scope:** General conversation, creative writing, or tasks outside its trained toolset.
|
| 20 |
|
| 21 |
+
---
|
| 22 |
+
## How to Use
|
| 23 |
|
| 24 |
+
The model is a PEFT adapter, meaning you must load it on top of the original base model. The following code provides a complete example of how to load the model from the Hub and run inference.
|
| 25 |
|
| 26 |
+
```python
|
| 27 |
+
import torch
|
| 28 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 29 |
+
from peft import PeftModel
|
| 30 |
|
| 31 |
+
# --- 1. Configuration ---
|
| 32 |
+
BASE_MODEL_REPO_ID = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 33 |
+
# Replace with your actual model repository ID on the Hub
|
| 34 |
+
FINE_TUNED_REPO_ID = "yashsoni78/mcp_tool_model"
|
| 35 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 36 |
|
| 37 |
+
# --- 2. Load Model and Tokenizer ---
|
| 38 |
+
print(f"Loading base model: {BASE_MODEL_REPO_ID}")
|
| 39 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 40 |
+
BASE_MODEL_REPO_ID,
|
| 41 |
+
torch_dtype=torch.bfloat16,
|
| 42 |
+
device_map=DEVICE
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
print(f"Loading fine-tuned adapter & tokenizer from: {FINE_TUNED_REPO_ID}")
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained(FINE_TUNED_REPO_ID)
|
| 47 |
|
| 48 |
+
# Resize token embeddings to account for any special tokens added during training
|
| 49 |
+
base_model.resize_token_embeddings(len(tokenizer))
|
| 50 |
|
| 51 |
+
# Load the LoRA adapter and merge it into the base model for faster inference
|
| 52 |
+
model = PeftModel.from_pretrained(base_model, FINE_TUNED_REPO_ID)
|
| 53 |
+
model = model.merge_and_unload()
|
| 54 |
+
model.eval() # Set the model to evaluation mode
|
| 55 |
|
| 56 |
+
print("✅ Model loaded successfully.")
|
| 57 |
|
| 58 |
+
# --- 3. Run Inference ---
|
| 59 |
+
system_prompt = "You are an expert assistant that uses MCP tools. When a tool is required, you must respond *only* with the 'tool_code' format."
|
| 60 |
+
user_prompt = "What's the status of my 'database-main' VM?"
|
| 61 |
|
| 62 |
+
formatted_prompt = f"SYSTEM: {system_prompt}\nUSER: {user_prompt}\nASSISTANT:"
|
| 63 |
+
inputs = tokenizer(formatted_prompt, return_tensors="pt").to(DEVICE)
|
| 64 |
|
| 65 |
+
outputs = model.generate(**inputs, max_new_tokens=150, pad_token_id=tokenizer.eos_token_id)
|
| 66 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True).split("ASSISTANT:")[1].strip()
|
| 67 |
|
| 68 |
+
print("\n--- Model Output ---")
|
| 69 |
+
print(response)
|
| 70 |
|
| 71 |
+
````
|
| 72 |
|
| 73 |
## Training Details
|
| 74 |
|
| 75 |
+
* **Base Model:** `mistralai/Mistral-7B-Instruct-v0.2`
|
| 76 |
+
* **Fine-Tuning Method:** PEFT (LoRA) with 4-bit quantization (`bitsandbytes`).
|
| 77 |
+
* **Dataset:** The model was trained on a curated, high-quality dataset containing a balanced mix of tool-calling examples and conversational ("negative") examples to teach it when *not* to call a tool. Special tokens `[TOOL_CODE_START]` and `[TOOL_CODE_END]` were added to the vocabulary.
|
| 78 |
+
* **Training Procedure:** The model was trained using the `SFTTrainer` from the TRL library.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
## Limitations and Bias
|
| 81 |
|
| 82 |
+
* **Syntax Hallucination:** As a probabilistic model, it may occasionally generate tool calls with slightly incorrect syntax (e.g., wrong object names, extra parameters). It is **highly recommended** to use this model within an application that performs a `Parse -> Validate -> Execute` loop to ensure safety and reliability.
|
| 83 |
+
* **Scope:** The model's knowledge is limited to the patterns and tools seen during fine-tuning. It cannot use new tools without being re-trained.
|
| 84 |
+
* **Language:** The model was trained exclusively on English language prompts.
|
| 85 |
|
| 86 |
+
```
|