--- base_model: google/functiongemma-270m-it library_name: transformers license: gemma tags: - function-calling - coffee-robot - mcp - gemma - tool-use - fine-tuned - chinese language: - zh pipeline_tag: text-generation datasets: - custom model-index: - name: functiongemma-270m-it-coffee-robot-mcp results: - task: type: function-calling name: Function Calling dataset: name: Coffee Robot MCP Dataset type: custom metrics: - type: accuracy value: 1.0 name: Accuracy --- # ☕ Coffee Robot MCP - FunctionGemma 270M 基於 `google/functiongemma-270m-it` 微調的咖啡機器人外送任務 Function Calling 模型。(此為企業內部點餐 api 整合測試模型) ## 📋 模型描述 此模型專門針對咖啡機器人外送場景進行微調,能夠將自然語言指令轉換為結構化的 Function Call,適用於 MCP (Model Context Protocol) 整合。 ### 主要特點 - 🎯 專注於咖啡外送任務的 Function Calling - 🇹🇼 支援繁體中文自然語言輸入 - ⚡ 輕量化模型(270M 參數),適合邊緣部署 - 🔧 相容 MCP 協議格式 ## 🛠️ 支援功能 ### Function: `send_coffee` | 參數 | 類型 | 說明 | 可選值 | |------|------|------|--------| | `baseDrink` | string | 飲品種類 | `americano`, `latte`, `oat_latte`, `milk` | | `floor` | integer | 配送樓層 | 1-11 | | `temperature` | string | 飲品溫度 | `hot`, `iced` | | `addons` | array | 加購選項 | `extra_espresso`, `paper_cup` | | `quantity` | integer | 數量 | 1-10 | ## 📊 模型效能 | 指標 | 基礎模型 | 微調後模型 | |------|----------|------------| | Function Calling 準確率 | 95.95% | 100.00% | | 提升幅度 | - | +4.05% | ### 訓練配置 - **訓練輪數**: 3 - **學習率**: 1e-05 - **有效批次大小**: 16 - **訓練樣本數**: 625 - **驗證樣本數**: 74 ## 💻 使用方式 ### 基本使用 ```python from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline model_id = "renhehuang/functiongemma-270m-it-coffee-robot-mcp" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto") pipe = pipeline("text-generation", model=model, tokenizer=tokenizer) tools = [ { "type": "function", "function": { "name": "send_coffee", "description": "送咖啡到指定樓層", "parameters": { "type": "object", "properties": { "baseDrink": {"type": "string", "enum": ["americano", "latte", "oat_latte", "milk"]}, "floor": {"type": "integer", "minimum": 1, "maximum": 11}, "temperature": {"type": "string", "enum": ["hot", "iced"]}, "addons": {"type": "array", "items": {"type": "string", "enum": ["extra_espresso", "paper_cup"]}}, "quantity": {"type": "integer", "minimum": 1, "maximum": 10}, }, "required": ["baseDrink", "floor", "temperature", "quantity"], }, }, } ] messages = [{"role": "user", "content": "幫我送一杯熱美式到五樓"}] prompt = tokenizer.apply_chat_template( messages, tools=tools, tokenize=False, add_generation_prompt=True, ) out = pipe(prompt, max_new_tokens=256, do_sample=False) print(out[0]["generated_text"][len(prompt):]) ``` ### 輸出範例 **輸入**: `"幫我送一杯熱美式到五樓"` **輸出**: ``` call: send_coffee{baseDrink:americano, floor:5, temperature:hot, quantity:1} ``` ## 🔗 MCP 整合 此模型可與 MCP Server 整合,實現自動化咖啡外送流程: ```python # 解析 Function Call import re def parse_function_call(output): pattern = r"(.*?)" matches = re.findall(pattern, output, re.DOTALL) # 解析並回傳結構化資料 return matches ``` ## ⚠️ 限制與注意事項 1. **領域限制**: 此模型專為咖啡外送場景設計,不適用於其他 Function Calling 任務 2. **語言支援**: 主要支援繁體中文,其他語言效果可能不佳 3. **樓層範圍**: 僅支援 1-11 樓 4. **飲品種類**: 僅支援 4 種飲品類型 ## 📝 引用 ```bibtex @misc{coffee-robot-mcp-2025, title={Coffee Robot MCP - FunctionGemma Fine-tuned Model}, author={renhehuang}, year={2025}, publisher={Hugging Face}, url={https://huggingface.co/renhehuang/functiongemma-270m-it-coffee-robot-mcp} } ``` ## 📄 授權 本模型基於 [Gemma License](https://ai.google.dev/gemma/terms) 授權。使用前請確認已接受 Google Gemma 的使用條款。 ## 🙏 致謝 - [Google](https://ai.google.dev/) - 提供 FunctionGemma 基礎模型 - [Hugging Face](https://huggingface.co/) - 提供模型託管與訓練工具