初始化项目,由ModelHub XC社区提供模型
Model: mlx-community/functiongemma-270m-it-bf16 Source: Original Platform
This commit is contained in:
36
.gitattributes
vendored
Normal file
36
.gitattributes
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
45
README.md
Normal file
45
README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
license: gemma
|
||||
tags:
|
||||
- gemma3
|
||||
- gemma
|
||||
- google
|
||||
- functiongemma
|
||||
- mlx
|
||||
pipeline_tag: text-generation
|
||||
library_name: mlx
|
||||
extra_gated_heading: Access Gemma on Hugging Face
|
||||
extra_gated_prompt: To access FunctionGemma on Hugging Face, you’re required to review
|
||||
and agree to Google’s usage license. To do this, please ensure you’re logged in
|
||||
to Hugging Face and click below. Requests are processed immediately.
|
||||
extra_gated_button_content: Acknowledge license
|
||||
base_model: google/functiongemma-270m-it
|
||||
---
|
||||
|
||||
# mlx-community/functiongemma-270m-it-bf16
|
||||
|
||||
This model [mlx-community/functiongemma-270m-it-bf16](https://huggingface.co/mlx-community/functiongemma-270m-it-bf16) was
|
||||
converted to MLX format from [google/functiongemma-270m-it](https://huggingface.co/google/functiongemma-270m-it)
|
||||
using mlx-lm version **0.28.4**.
|
||||
|
||||
## Use with mlx
|
||||
|
||||
```bash
|
||||
pip install mlx-lm
|
||||
```
|
||||
|
||||
```python
|
||||
from mlx_lm import load, generate
|
||||
|
||||
model, tokenizer = load("mlx-community/functiongemma-270m-it-bf16")
|
||||
|
||||
prompt = "hello"
|
||||
|
||||
if tokenizer.chat_template is not None:
|
||||
messages = [{"role": "user", "content": prompt}]
|
||||
prompt = tokenizer.apply_chat_template(
|
||||
messages, add_generation_prompt=True
|
||||
)
|
||||
|
||||
response = generate(model, tokenizer, prompt=prompt, verbose=True)
|
||||
```
|
||||
279
chat_template.jinja
Normal file
279
chat_template.jinja
Normal file
@@ -0,0 +1,279 @@
|
||||
{%- macro format_parameters(properties, required) -%}
|
||||
{%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}
|
||||
{%- set ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in properties | dictsort -%}
|
||||
{%- if key not in standard_keys -%}
|
||||
{%- if ns.found_first %},{% endif -%}
|
||||
{%- set ns.found_first = true -%}
|
||||
{{- key }}:{description:<escape>{{ value['description'] }}<escape>
|
||||
{%- if value['type'] | upper == 'STRING' -%}
|
||||
{%- if value['enum'] -%}
|
||||
,enum:{{ format_argument(value['enum']) }}
|
||||
{%- endif -%}
|
||||
{%- elif value['type'] | upper == 'OBJECT' -%}
|
||||
,properties:{
|
||||
{%- if value['properties'] is defined and value['properties'] is mapping -%}
|
||||
{{- format_parameters(value['properties'], value['required'] | default([])) -}}
|
||||
{%- elif value is mapping -%}
|
||||
{{- format_parameters(value, value['required'] | default([])) -}}
|
||||
{%- endif -%}
|
||||
}
|
||||
{%- if value['required'] -%}
|
||||
,required:[
|
||||
{%- for item in value['required'] | default([]) -%}
|
||||
<escape>{{- item -}}<escape>
|
||||
{%- if not loop.last %},{% endif -%}
|
||||
{%- endfor -%}
|
||||
]
|
||||
{%- endif -%}
|
||||
{%- elif value['type'] | upper == 'ARRAY' -%}
|
||||
{%- if value['items'] is mapping and value['items'] -%}
|
||||
,items:{
|
||||
{%- set ns_items = namespace(found_first=false) -%}
|
||||
{%- for item_key, item_value in value['items'] | dictsort -%}
|
||||
{%- if item_value is not none -%}
|
||||
{%- if ns_items.found_first %},{% endif -%}
|
||||
{%- set ns_items.found_first = true -%}
|
||||
{%- if item_key == 'properties' -%}
|
||||
properties:{
|
||||
{%- if item_value is mapping -%}
|
||||
{{- format_parameters(item_value, value['items']['required'] | default([])) -}}
|
||||
{%- endif -%}
|
||||
}
|
||||
{%- elif item_key == 'required' -%}
|
||||
required:[
|
||||
{%- for req_item in item_value -%}
|
||||
<escape>{{- req_item -}}<escape>
|
||||
{%- if not loop.last %},{% endif -%}
|
||||
{%- endfor -%}
|
||||
]
|
||||
{%- elif item_key == 'type' -%}
|
||||
{%- if item_value is string -%}
|
||||
type:{{ format_argument(item_value | upper) }}
|
||||
{%- else -%}
|
||||
type:{{ format_argument(item_value | map('upper') | list) }}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{ item_key }}:{{ format_argument(item_value) }}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
,type:<escape>{{ value['type'] | upper }}<escape>}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endmacro -%}
|
||||
{% macro format_function_declaration(tool_data) -%}
|
||||
declaration:{{- tool_data['function']['name'] -}}
|
||||
{description:<escape>{{- tool_data['function']['description'] -}}<escape>
|
||||
{%- set params = tool_data['function']['parameters'] -%}
|
||||
{%- if params -%}
|
||||
,parameters:{
|
||||
{%- if params['properties'] -%}
|
||||
properties:{ {{- format_parameters(params['properties'], params['required']) -}} },
|
||||
{%- endif -%}
|
||||
{%- if params['required'] -%}
|
||||
required:[
|
||||
{%- for item in params['required'] -%}
|
||||
<escape>{{- item -}}<escape>
|
||||
{{- ',' if not loop.last -}}
|
||||
{%- endfor -%}
|
||||
],
|
||||
{%- endif -%}
|
||||
{%- if params['type'] -%}
|
||||
type:<escape>{{- params['type'] | upper -}}<escape>}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
}
|
||||
{%- endmacro -%}
|
||||
{% macro format_argument(argument, escape_keys=True) -%}
|
||||
{%- if argument is string -%}
|
||||
{{- '<escape>' + argument + '<escape>' -}}
|
||||
{%- elif argument is boolean -%}
|
||||
{%- if argument -%}
|
||||
{{- 'true' -}}
|
||||
{%- else -%}
|
||||
{{- 'false' -}}
|
||||
{%- endif -%}
|
||||
{%- elif argument is mapping -%}
|
||||
{{- '{' -}}
|
||||
{%- set ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in argument | dictsort -%}
|
||||
{%- if ns.found_first %},{% endif -%}
|
||||
{%- set ns.found_first = true -%}
|
||||
{%- if escape_keys -%}
|
||||
{{- '<escape>' + key + '<escape>' -}}
|
||||
{%- else -%}
|
||||
{{- key -}}
|
||||
{%- endif -%}
|
||||
:{{- format_argument(value, escape_keys=escape_keys) -}}
|
||||
{%- endfor -%}
|
||||
{{- '}' -}}
|
||||
{%- elif argument is sequence -%}
|
||||
{{- '[' -}}
|
||||
{%- for item in argument -%}
|
||||
{{- format_argument(item, escape_keys=escape_keys) -}}
|
||||
{%- if not loop.last %},{% endif -%}
|
||||
{%- endfor -%}
|
||||
{{- ']' -}}
|
||||
{%- else -%}
|
||||
{{- argument -}}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{{ bos_token }}
|
||||
{%- set ns = namespace(prev_message_type=None) -%}
|
||||
{#- Tool Declarations -#}
|
||||
{%- set loop_messages = messages -%}
|
||||
{%- if tools or messages[0]['role'] == 'system' or messages[0]['role'] == 'developer' -%}
|
||||
{{- '<start_of_turn>developer\n' -}}
|
||||
{%- if messages[0]['role'] == 'system' or messages[0]['role'] == 'developer' -%}
|
||||
{%- if messages[0]['content'] is string -%}
|
||||
{{- messages[0]['content'] | trim -}}
|
||||
{%- elif messages[0]['content'] is sequence -%}
|
||||
{%- for item in messages[0]['content'] -%}
|
||||
{%- if item['type'] == 'text' -%}
|
||||
{{- item['text'] | trim -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- set loop_messages = messages[1:] -%}
|
||||
{%- endif -%}
|
||||
{%- if tools -%}
|
||||
{%- for tool in tools %}
|
||||
{{- '<start_function_declaration>' -}}
|
||||
{{- format_function_declaration(tool) | trim }}
|
||||
{{- '<end_function_declaration>' -}}
|
||||
{%- endfor %}
|
||||
{%- endif -%}
|
||||
{{- '<end_of_turn>\n' }}
|
||||
{%- endif %}
|
||||
{#- Loop through messages. -#}
|
||||
{%- for message in loop_messages -%}
|
||||
{%- if (message['role'] == 'assistant') -%}
|
||||
{#- Rename "assistant" to "model". -#}
|
||||
{%- set role = "model" -%}
|
||||
{%- else -%}
|
||||
{%- set role = message['role'] -%}
|
||||
{%- endif -%}
|
||||
{%- if role != 'tool' -%}
|
||||
{%- if ns.prev_message_type != 'tool_response' -%}
|
||||
{{- '<start_of_turn>' + role + '\n' }}
|
||||
{%- endif -%}
|
||||
{%- set ns.prev_message_type = None -%}
|
||||
{%- if 'content' in message and message['content'] is not none -%}
|
||||
{%- if message['content'] is string -%}
|
||||
{{ message['content'] | trim }}
|
||||
{%- elif message['content'] is sequence -%}
|
||||
{%- for item in message['content'] -%}
|
||||
{%- if item['type'] == 'image' -%}
|
||||
{{ '<start_of_image>' }}
|
||||
{%- elif item['type'] == 'text' -%}
|
||||
{{ item['text'] | trim }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid content type in user/assistant message") }}
|
||||
{%- endif -%}
|
||||
{%- set ns.prev_message_type = 'content' -%}
|
||||
{%- endif -%}
|
||||
{%- if 'tool_calls' in message and message['tool_calls'] and message['tool_calls'] is iterable -%}
|
||||
{#- Tool Calls -#}
|
||||
{%- for tool_call in message['tool_calls'] -%}
|
||||
{% set function = tool_call['function'] %}
|
||||
{{- '<start_function_call>call:' + function['name'] + '{' -}}
|
||||
{%- if 'arguments' in function -%}
|
||||
{%- if function['arguments'] is mapping -%}
|
||||
{%- set ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in function['arguments'] | dictsort -%}
|
||||
{%- if ns.found_first %},{% endif -%}
|
||||
{%- set ns.found_first = true -%}
|
||||
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
||||
{%- endfor -%}
|
||||
{%- elif function['arguments'] is string -%}
|
||||
{# This handles string-JSON, just in case #}
|
||||
{{ function['arguments'] }}
|
||||
{%- endif %}
|
||||
{%- endif -%}
|
||||
{{- '}<end_function_call>' -}}
|
||||
{%- endfor -%}
|
||||
{%- if loop.last -%}
|
||||
{{ '<start_function_response>' }}
|
||||
{%- endif -%}
|
||||
{%- set ns.prev_message_type = 'tool_call' -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{#- Tool Responses -#}
|
||||
{%- if 'content' in message and message['content'] -%}
|
||||
{%- if message['content'] is mapping -%}
|
||||
{%- if 'name' in message['content'] and 'response' in message['content'] -%}
|
||||
{{ '<start_function_response>response:' + message['content']['name'] | trim + '{' }}
|
||||
{%- set response_ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in message['content']['response'] | dictsort -%}
|
||||
{%- if response_ns.found_first %},{% endif -%}
|
||||
{%- set response_ns.found_first = true -%}
|
||||
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
||||
{%- endfor -%}
|
||||
{{- '}<end_function_response>' -}}
|
||||
{%- elif 'name' in message -%}
|
||||
{{ '<start_function_response>response:' + message['name'] | trim + '{' }}
|
||||
{%- set response_ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in message['content'] | dictsort -%}
|
||||
{%- if response_ns.found_first %},{% endif -%}
|
||||
{%- set response_ns.found_first = true -%}
|
||||
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
||||
{%- endfor -%}
|
||||
{{- '}<end_function_response>' -}}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
|
||||
{%- endif -%}
|
||||
{%- elif message['content'] is string -%}
|
||||
{%- if 'name' in message -%}
|
||||
{{ '<start_function_response>response:' + message['name'] | trim + '{value:' + format_argument(message['content'], escape_keys=False) + '}<end_function_response>' }}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid tool response: 'name' must be provided.") }}
|
||||
{%- endif -%}
|
||||
{%- elif message['content'] is sequence -%}
|
||||
{%- for item in message['content'] -%}
|
||||
{%- if item is mapping -%}
|
||||
{%- if 'name' in item and 'response' in item -%}
|
||||
{{ '<start_function_response>response:' + item['name'] | trim + '{' }}
|
||||
{%- set response_ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in item['response'] | dictsort -%}
|
||||
{%- if response_ns.found_first %},{% endif -%}
|
||||
{%- set response_ns.found_first = true -%}
|
||||
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
||||
{%- endfor -%}
|
||||
{{- '}<end_function_response>' -}}
|
||||
{%- elif 'name' in message -%}
|
||||
{{ '<start_function_response>response:' + message['name'] | trim + '{' }}
|
||||
{%- set response_ns = namespace(found_first=false) -%}
|
||||
{%- for key, value in item | dictsort -%}
|
||||
{%- if response_ns.found_first %},{% endif -%}
|
||||
{%- set response_ns.found_first = true -%}
|
||||
{{- key -}}:{{- format_argument(value, escape_keys=False) -}}
|
||||
{%- endfor -%}
|
||||
{{- '}<end_function_response>' -}}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid tool response mapping: must contain 'name' and 'response' keys, or 'name' must be in the message.") }}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid tool response message: multiple responses must all be mappings") }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{{ raise_exception("Invalid content type in tool message: must be mapping, sequence of mappings, or string.") }}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- set ns.prev_message_type = 'tool_response' -%}
|
||||
{%- endif -%}
|
||||
{%- if ns.prev_message_type not in ['tool_call', 'tool_response'] -%}
|
||||
{{ '<end_of_turn>\n' }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if add_generation_prompt -%}
|
||||
{%- if ns.prev_message_type != 'tool_response' -%}
|
||||
{{- '<start_of_turn>model\n' -}}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
58
config.json
Normal file
58
config.json
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"_sliding_window_pattern": 6,
|
||||
"architectures": [
|
||||
"Gemma3ForCausalLM"
|
||||
],
|
||||
"attention_bias": false,
|
||||
"attention_dropout": 0.0,
|
||||
"attn_logit_softcapping": null,
|
||||
"bos_token_id": 2,
|
||||
"dtype": "bfloat16",
|
||||
"eos_token_id": [
|
||||
1,
|
||||
49
|
||||
],
|
||||
"final_logit_softcapping": null,
|
||||
"head_dim": 256,
|
||||
"hidden_activation": "gelu_pytorch_tanh",
|
||||
"hidden_size": 640,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 2048,
|
||||
"layer_types": [
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"sliding_attention",
|
||||
"full_attention"
|
||||
],
|
||||
"max_position_embeddings": 32768,
|
||||
"model_type": "gemma3_text",
|
||||
"num_attention_heads": 4,
|
||||
"num_hidden_layers": 18,
|
||||
"num_key_value_heads": 1,
|
||||
"pad_token_id": 0,
|
||||
"query_pre_attn_scalar": 256,
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_local_base_freq": 10000.0,
|
||||
"rope_parameters": null,
|
||||
"rope_scaling": null,
|
||||
"rope_theta": 1000000.0,
|
||||
"sliding_window": 512,
|
||||
"transformers_version": "4.57.3",
|
||||
"use_bidirectional_attention": false,
|
||||
"use_cache": true,
|
||||
"vocab_size": 262144
|
||||
}
|
||||
819
cookbook/function_calling_examples.ipynb
Normal file
819
cookbook/function_calling_examples.ipynb
Normal file
@@ -0,0 +1,819 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Function Calling with FunctionGemma\n",
|
||||
"\n",
|
||||
"This notebook demonstrates how to use [Google's FunctionGemma](https://huggingface.co/google/functiongemma-270m-it) for function calling with MLX-LM. We'll cover different use cases including datetime, weather, calendar, email, database queries, and more.\n",
|
||||
"\n",
|
||||
"## Requirements\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install -U mlx-lm\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import re\n",
|
||||
"from datetime import datetime\n",
|
||||
"from mlx_lm import load, generate"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load the model\n",
|
||||
"model, tokenizer = load(\"mlx-community/functiongemma-270m-it-bf16\")\n",
|
||||
"print(\"✅ Model loaded\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Function Definitions\n",
|
||||
"\n",
|
||||
"Below are mock implementations of various functions that demonstrate different use cases. In production, these would connect to real APIs and services."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 0: System DateTime\n",
|
||||
"def get_current_datetime() -> dict:\n",
|
||||
" \"\"\"Get current system date and time.\"\"\"\n",
|
||||
" now = datetime.now()\n",
|
||||
" return {\n",
|
||||
" \"datetime\": now.isoformat(),\n",
|
||||
" \"date\": now.strftime(\"%Y-%m-%d\"),\n",
|
||||
" \"time\": now.strftime(\"%H:%M:%S\"),\n",
|
||||
" \"day_of_week\": now.strftime(\"%A\"),\n",
|
||||
" \"timezone\": now.astimezone().tzname()\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"datetime_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"get_current_datetime\",\n",
|
||||
" \"description\": \"Gets the current system date and time\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {},\n",
|
||||
" \"required\": [],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 1: Weather\n",
|
||||
"def get_current_temperature(location: str) -> dict:\n",
|
||||
" \"\"\"Get current temperature for a location.\"\"\"\n",
|
||||
" temps = {\n",
|
||||
" \"London\": 15, \"Paris\": 18, \"Tokyo\": 22,\n",
|
||||
" \"New York\": 12, \"Sydney\": 25\n",
|
||||
" }\n",
|
||||
" return {\n",
|
||||
" \"location\": location,\n",
|
||||
" \"temperature\": temps.get(location, 20),\n",
|
||||
" \"unit\": \"celsius\"\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"weather_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"get_current_temperature\",\n",
|
||||
" \"description\": \"Gets the current temperature for a given location.\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"location\": {\n",
|
||||
" \"type\": \"STRING\",\n",
|
||||
" \"description\": \"The city name, e.g. San Francisco\",\n",
|
||||
" },\n",
|
||||
" },\n",
|
||||
" \"required\": [\"location\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 2: Calendar\n",
|
||||
"def create_calendar_event(title: str, date: str, time: str) -> dict:\n",
|
||||
" \"\"\"Create a calendar event.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"success\": True,\n",
|
||||
" \"event\": {\n",
|
||||
" \"title\": title,\n",
|
||||
" \"date\": date,\n",
|
||||
" \"time\": time,\n",
|
||||
" \"event_id\": f\"evt_{hash(title+date)}\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"calendar_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"create_calendar_event\",\n",
|
||||
" \"description\": \"Creates a new event in the calendar\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"title\": {\"type\": \"STRING\", \"description\": \"Event title\"},\n",
|
||||
" \"date\": {\"type\": \"STRING\", \"description\": \"Event date (YYYY-MM-DD)\"},\n",
|
||||
" \"time\": {\"type\": \"STRING\", \"description\": \"Event time (HH:MM)\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"title\", \"date\", \"time\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 3: Email\n",
|
||||
"def send_email(recipient: str, subject: str, body: str) -> dict:\n",
|
||||
" \"\"\"Send an email.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"success\": True,\n",
|
||||
" \"message_id\": f\"msg_{hash(recipient+subject)}\",\n",
|
||||
" \"sent_to\": recipient\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"email_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"send_email\",\n",
|
||||
" \"description\": \"Sends an email to a recipient\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"recipient\": {\"type\": \"STRING\", \"description\": \"Email address\"},\n",
|
||||
" \"subject\": {\"type\": \"STRING\", \"description\": \"Email subject\"},\n",
|
||||
" \"body\": {\"type\": \"STRING\", \"description\": \"Email body\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"recipient\", \"subject\", \"body\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 4: Database\n",
|
||||
"def search_database(query: str, table: str) -> dict:\n",
|
||||
" \"\"\"Search database.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"results\": [\n",
|
||||
" {\"id\": 1, \"name\": \"Result 1\"},\n",
|
||||
" {\"id\": 2, \"name\": \"Result 2\"}\n",
|
||||
" ],\n",
|
||||
" \"count\": 2,\n",
|
||||
" \"table\": table\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"database_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"search_database\",\n",
|
||||
" \"description\": \"Searches a database table\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"query\": {\"type\": \"STRING\", \"description\": \"Search query\"},\n",
|
||||
" \"table\": {\"type\": \"STRING\", \"description\": \"Table name\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"query\", \"table\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 5: File System\n",
|
||||
"def list_files(directory: str) -> dict:\n",
|
||||
" \"\"\"List files in directory.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"files\": [\"file1.txt\", \"file2.py\", \"file3.md\"],\n",
|
||||
" \"count\": 3,\n",
|
||||
" \"directory\": directory\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"filesystem_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"list_files\",\n",
|
||||
" \"description\": \"Lists files in a directory\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"directory\": {\"type\": \"STRING\", \"description\": \"Directory path\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"directory\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 6: Translation\n",
|
||||
"def translate_text(text: str, target_language: str) -> dict:\n",
|
||||
" \"\"\"Translate text.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"original\": text,\n",
|
||||
" \"translated\": f\"[{target_language.upper()}] {text}\",\n",
|
||||
" \"language\": target_language\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"translation_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"translate_text\",\n",
|
||||
" \"description\": \"Translates text to another language\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"text\": {\"type\": \"STRING\", \"description\": \"Text to translate\"},\n",
|
||||
" \"target_language\": {\"type\": \"STRING\", \"description\": \"Target language (e.g., Spanish, French)\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"text\", \"target_language\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 7: Calculator\n",
|
||||
"def calculate(expression: str) -> dict:\n",
|
||||
" \"\"\"Calculate expression.\"\"\"\n",
|
||||
" try:\n",
|
||||
" result = eval(expression)\n",
|
||||
" return {\"expression\": expression, \"result\": result, \"success\": True}\n",
|
||||
" except Exception as e:\n",
|
||||
" return {\"expression\": expression, \"error\": str(e), \"success\": False}\n",
|
||||
"\n",
|
||||
"calculator_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"calculate\",\n",
|
||||
" \"description\": \"Evaluates a mathematical expression\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"expression\": {\"type\": \"STRING\", \"description\": \"Math expression (e.g., '2+2', '10*5')\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"expression\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 8: Timer\n",
|
||||
"def set_timer(duration_minutes: int, label: str) -> dict:\n",
|
||||
" \"\"\"Set a timer.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"timer_id\": f\"timer_{hash(label)}\",\n",
|
||||
" \"duration_minutes\": duration_minutes,\n",
|
||||
" \"label\": label,\n",
|
||||
" \"status\": \"active\"\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"timer_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"set_timer\",\n",
|
||||
" \"description\": \"Sets a timer with specified duration\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"duration_minutes\": {\"type\": \"NUMBER\", \"description\": \"Duration in minutes\"},\n",
|
||||
" \"label\": {\"type\": \"STRING\", \"description\": \"Timer label\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"duration_minutes\", \"label\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 9: News\n",
|
||||
"def get_news(category: str, limit: int) -> dict:\n",
|
||||
" \"\"\"Get news articles.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"category\": category,\n",
|
||||
" \"articles\": [f\"Article {i+1}\" for i in range(limit)],\n",
|
||||
" \"count\": limit\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"news_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"get_news\",\n",
|
||||
" \"description\": \"Gets news articles by category\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"category\": {\"type\": \"STRING\", \"description\": \"News category (e.g., technology, sports)\"},\n",
|
||||
" \"limit\": {\"type\": \"NUMBER\", \"description\": \"Number of articles\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"category\", \"limit\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Use Case 10: Reminder\n",
|
||||
"def create_reminder(task: str, reminder_time: str) -> dict:\n",
|
||||
" \"\"\"Create a reminder.\"\"\"\n",
|
||||
" return {\n",
|
||||
" \"reminder_id\": f\"rem_{hash(task)}\",\n",
|
||||
" \"task\": task,\n",
|
||||
" \"reminder_time\": reminder_time,\n",
|
||||
" \"status\": \"scheduled\"\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"reminder_schema = {\n",
|
||||
" \"type\": \"function\",\n",
|
||||
" \"function\": {\n",
|
||||
" \"name\": \"create_reminder\",\n",
|
||||
" \"description\": \"Creates a reminder for a task\",\n",
|
||||
" \"parameters\": {\n",
|
||||
" \"type\": \"OBJECT\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"task\": {\"type\": \"STRING\", \"description\": \"Task description\"},\n",
|
||||
" \"reminder_time\": {\"type\": \"STRING\", \"description\": \"Time for reminder (e.g., '2pm tomorrow')\"}\n",
|
||||
" },\n",
|
||||
" \"required\": [\"task\", \"reminder_time\"],\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Function & Schema Registry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ALL_FUNCTIONS = {\n",
|
||||
" \"get_current_datetime\": get_current_datetime,\n",
|
||||
" \"get_current_temperature\": get_current_temperature,\n",
|
||||
" \"create_calendar_event\": create_calendar_event,\n",
|
||||
" \"send_email\": send_email,\n",
|
||||
" \"search_database\": search_database,\n",
|
||||
" \"list_files\": list_files,\n",
|
||||
" \"translate_text\": translate_text,\n",
|
||||
" \"calculate\": calculate,\n",
|
||||
" \"set_timer\": set_timer,\n",
|
||||
" \"get_news\": get_news,\n",
|
||||
" \"create_reminder\": create_reminder\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"ALL_SCHEMAS = {\n",
|
||||
" \"datetime\": datetime_schema,\n",
|
||||
" \"weather\": weather_schema,\n",
|
||||
" \"calendar\": calendar_schema,\n",
|
||||
" \"email\": email_schema,\n",
|
||||
" \"database\": database_schema,\n",
|
||||
" \"filesystem\": filesystem_schema,\n",
|
||||
" \"translation\": translation_schema,\n",
|
||||
" \"calculator\": calculator_schema,\n",
|
||||
" \"timer\": timer_schema,\n",
|
||||
" \"news\": news_schema,\n",
|
||||
" \"reminder\": reminder_schema\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Response Parser\n",
|
||||
"\n",
|
||||
"FunctionGemma uses a specific format for function calls:\n",
|
||||
"```\n",
|
||||
"<start_function_call>call:function_name{key:value,key:value}<end_function_call>\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"String values may be wrapped in `<escape>` tags."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def parse_function_call(response: str):\n",
|
||||
" \"\"\"Parse FunctionGemma's response format.\"\"\"\n",
|
||||
" if \"<start_function_call>\" not in response:\n",
|
||||
" return None, None\n",
|
||||
"\n",
|
||||
" start = response.find(\"<start_function_call>\") + len(\"<start_function_call>\")\n",
|
||||
" end = response.find(\"<end_function_call>\")\n",
|
||||
"\n",
|
||||
" if end == -1:\n",
|
||||
" call_str = response[start:].strip()\n",
|
||||
" else:\n",
|
||||
" call_str = response[start:end].strip()\n",
|
||||
"\n",
|
||||
" # Parse: call:function_name{key:value,key:value}\n",
|
||||
" match = re.match(r'call:([\\w_]+)\\{([^}]*)\\}?', call_str, re.DOTALL)\n",
|
||||
" if not match:\n",
|
||||
" return None, None\n",
|
||||
"\n",
|
||||
" func_name = match.group(1)\n",
|
||||
" args_str = match.group(2).strip()\n",
|
||||
"\n",
|
||||
" # Handle empty parameters\n",
|
||||
" if not args_str:\n",
|
||||
" return func_name, {}\n",
|
||||
"\n",
|
||||
" # Process escape tags\n",
|
||||
" temp = args_str\n",
|
||||
" while '<escape>' in temp:\n",
|
||||
" start_idx = temp.find('<escape>')\n",
|
||||
" end_idx = temp.find('<escape>', start_idx + 8)\n",
|
||||
" if end_idx != -1:\n",
|
||||
" escaped_content = temp[start_idx+8:end_idx]\n",
|
||||
" temp = temp[:start_idx] + escaped_content + temp[end_idx+8:]\n",
|
||||
" else:\n",
|
||||
" temp = temp.replace('<escape>', '')\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
" # Parse key:value pairs\n",
|
||||
" args = {}\n",
|
||||
" for pair in temp.split(','):\n",
|
||||
" if ':' in pair:\n",
|
||||
" key, value = pair.split(':', 1)\n",
|
||||
" key = key.strip()\n",
|
||||
" value = value.strip()\n",
|
||||
"\n",
|
||||
" # Type conversion\n",
|
||||
" try:\n",
|
||||
" if '.' in value:\n",
|
||||
" args[key] = float(value)\n",
|
||||
" else:\n",
|
||||
" args[key] = int(value)\n",
|
||||
" except ValueError:\n",
|
||||
" args[key] = value.strip('\"\\'')\n",
|
||||
"\n",
|
||||
" return func_name, args"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Test Runner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def run_function_call(query: str, schema: dict, verbose: bool = True) -> dict:\n",
|
||||
" \"\"\"\n",
|
||||
" Run a function call with FunctionGemma.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" query: Natural language query from the user\n",
|
||||
" schema: Function schema to make available\n",
|
||||
" verbose: Whether to print detailed output\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" dict with 'success', 'function', 'args', and 'result' keys\n",
|
||||
" \"\"\"\n",
|
||||
" current_dt = get_current_datetime()\n",
|
||||
"\n",
|
||||
" # IMPORTANT: Developer role activates function calling\n",
|
||||
" messages = [\n",
|
||||
" {\n",
|
||||
" \"role\": \"developer\",\n",
|
||||
" \"content\": f\"\"\"You are a model that can do function calling with the following functions.\n",
|
||||
"\n",
|
||||
"Current system information:\n",
|
||||
"- Date: {current_dt['date']} ({current_dt['day_of_week']})\n",
|
||||
"- Time: {current_dt['time']}\n",
|
||||
"- Timezone: {current_dt['timezone']}\"\"\"\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"role\": \"user\",\n",
|
||||
" \"content\": query\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
"\n",
|
||||
" # Apply chat template with tools\n",
|
||||
" prompt = tokenizer.apply_chat_template(\n",
|
||||
" messages,\n",
|
||||
" tools=[schema],\n",
|
||||
" add_generation_prompt=True,\n",
|
||||
" tokenize=False\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Generate response\n",
|
||||
" response = generate(model, tokenizer, prompt=prompt, max_tokens=1024, verbose=False)\n",
|
||||
"\n",
|
||||
" if verbose:\n",
|
||||
" print(f\"Query: {query}\")\n",
|
||||
" print(f\"Response: {response}\")\n",
|
||||
"\n",
|
||||
" # Parse and execute\n",
|
||||
" func_name, func_args = parse_function_call(response)\n",
|
||||
"\n",
|
||||
" if func_name and func_args is not None:\n",
|
||||
" if verbose:\n",
|
||||
" print(f\"\\n✅ Function: {func_name}()\")\n",
|
||||
" print(f\" Arguments: {json.dumps(func_args, indent=2)}\")\n",
|
||||
"\n",
|
||||
" if func_name in ALL_FUNCTIONS:\n",
|
||||
" result = ALL_FUNCTIONS[func_name](**func_args)\n",
|
||||
" if verbose:\n",
|
||||
" print(f\" Result: {json.dumps(result, indent=2)}\")\n",
|
||||
" return {\"success\": True, \"function\": func_name, \"args\": func_args, \"result\": result}\n",
|
||||
"\n",
|
||||
" if verbose:\n",
|
||||
" print(\"\\n❌ No function call detected\")\n",
|
||||
" return {\"success\": False, \"function\": None, \"args\": None, \"result\": None}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Examples\n",
|
||||
"\n",
|
||||
"Let's test each use case:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# DateTime\n",
|
||||
"run_function_call(\"What is the current date and time?\", datetime_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Weather\n",
|
||||
"run_function_call(\"What's the temperature in London?\", weather_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Calendar\n",
|
||||
"run_function_call(\"Create a meeting event for tomorrow at 2pm called Team Sync\", calendar_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Email\n",
|
||||
"run_function_call(\n",
|
||||
" \"Send an email to john@example.com with subject 'Meeting' and body 'See you tomorrow'\",\n",
|
||||
" email_schema\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Database\n",
|
||||
"run_function_call(\"Search the users table for active accounts\", database_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# File System\n",
|
||||
"run_function_call(\"List files in the /home/user directory\", filesystem_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Translation\n",
|
||||
"run_function_call(\"Translate 'Hello World' to Spanish\", translation_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Calculator\n",
|
||||
"run_function_call(\"Calculate 25 * 4 + 10\", calculator_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Timer\n",
|
||||
"run_function_call(\"Set a 5 minute timer for coffee\", timer_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# News\n",
|
||||
"run_function_call(\"Get 3 technology news articles\", news_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Reminder\n",
|
||||
"run_function_call(\"Remind me to call mom at 6pm today\", reminder_schema)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Run All Tests"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"test_cases = [\n",
|
||||
" (\"datetime\", datetime_schema, \"What is the current date and time?\"),\n",
|
||||
" (\"weather\", weather_schema, \"What's the temperature in London?\"),\n",
|
||||
" (\"calendar\", calendar_schema, \"Create a meeting event for tomorrow at 2pm called Team Sync\"),\n",
|
||||
" (\"email\", email_schema, \"Send an email to john@example.com with subject 'Meeting' and body 'See you tomorrow'\"),\n",
|
||||
" (\"database\", database_schema, \"Search the users table for active accounts\"),\n",
|
||||
" (\"filesystem\", filesystem_schema, \"List files in the /home/user directory\"),\n",
|
||||
" (\"translation\", translation_schema, \"Translate 'Hello World' to Spanish\"),\n",
|
||||
" (\"calculator\", calculator_schema, \"Calculate 25 * 4 + 10\"),\n",
|
||||
" (\"timer\", timer_schema, \"Set a 5 minute timer for coffee\"),\n",
|
||||
" (\"news\", news_schema, \"Get 3 technology news articles\"),\n",
|
||||
" (\"reminder\", reminder_schema, \"Remind me to call mom at 6pm today\")\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"successful = 0\n",
|
||||
"for name, schema, query in test_cases:\n",
|
||||
" print(f\"\\n{'='*60}\")\n",
|
||||
" print(f\"USE CASE: {name.upper()}\")\n",
|
||||
" print(f\"{'='*60}\")\n",
|
||||
" result = run_function_call(query, schema)\n",
|
||||
" if result[\"success\"]:\n",
|
||||
" successful += 1\n",
|
||||
"\n",
|
||||
"print(f\"\\n\\n{'='*60}\")\n",
|
||||
"print(f\"SUMMARY: {successful}/{len(test_cases)} tests passed ({successful/len(test_cases)*100:.1f}%)\")\n",
|
||||
"print(f\"{'='*60}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Key Takeaways\n",
|
||||
"\n",
|
||||
"1. **Developer Role**: Use `role: \"developer\"` to activate function calling mode\n",
|
||||
"2. **Schema Format**: Follow the OBJECT/STRING/NUMBER type format in schemas\n",
|
||||
"3. **Response Format**: FunctionGemma uses `<start_function_call>call:name{args}<end_function_call>`\n",
|
||||
"4. **Escaped Strings**: String values may be wrapped in `<escape>` tags\n",
|
||||
"5. **Context**: Providing current datetime helps with time-aware queries"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "mlx",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
12
generation_config.json
Normal file
12
generation_config.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"cache_implementation": "hybrid",
|
||||
"do_sample": true,
|
||||
"eos_token_id": [
|
||||
1,
|
||||
50,
|
||||
106
|
||||
],
|
||||
"top_k": 64,
|
||||
"top_p": 0.95,
|
||||
"transformers_version": "4.57.3"
|
||||
}
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:fb64bf18b2911fcaa59d44c1b7d5842a011a874530be9dc5bc9d307e82b4edee
|
||||
size 536222768
|
||||
244
model.safetensors.index.json
Normal file
244
model.safetensors.index.json
Normal file
@@ -0,0 +1,244 @@
|
||||
{
|
||||
"metadata": {
|
||||
"total_size": 536196352,
|
||||
"total_parameters": 268098176
|
||||
},
|
||||
"weight_map": {
|
||||
"model.embed_tokens.weight": "model.safetensors",
|
||||
"model.layers.0.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.0.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.0.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.0.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.0.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.0.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.0.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.0.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.1.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.1.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.1.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.1.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.1.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.1.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.1.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.1.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.10.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.10.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.10.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.10.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.10.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.10.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.10.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.10.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.11.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.11.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.11.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.11.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.11.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.11.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.11.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.11.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.12.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.12.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.12.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.12.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.12.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.12.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.12.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.12.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.13.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.13.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.13.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.13.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.13.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.13.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.13.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.13.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.14.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.14.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.14.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.14.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.14.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.14.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.14.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.14.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.15.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.15.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.15.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.15.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.15.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.15.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.15.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.15.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.16.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.16.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.16.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.16.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.16.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.16.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.16.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.16.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.17.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.17.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.17.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.17.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.17.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.17.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.17.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.17.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.2.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.2.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.2.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.2.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.2.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.2.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.2.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.2.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.3.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.3.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.3.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.3.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.3.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.3.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.3.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.3.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.4.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.4.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.4.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.4.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.4.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.4.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.4.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.4.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.5.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.5.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.5.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.5.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.5.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.5.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.5.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.5.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.6.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.6.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.6.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.6.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.6.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.6.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.6.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.6.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.7.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.7.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.7.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.7.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.7.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.7.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.7.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.7.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.8.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.8.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.8.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.8.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.8.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.8.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.8.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.8.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.layers.9.input_layernorm.weight": "model.safetensors",
|
||||
"model.layers.9.mlp.down_proj.weight": "model.safetensors",
|
||||
"model.layers.9.mlp.gate_proj.weight": "model.safetensors",
|
||||
"model.layers.9.mlp.up_proj.weight": "model.safetensors",
|
||||
"model.layers.9.post_attention_layernorm.weight": "model.safetensors",
|
||||
"model.layers.9.post_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.9.pre_feedforward_layernorm.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.k_norm.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.k_proj.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.o_proj.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.q_norm.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.q_proj.weight": "model.safetensors",
|
||||
"model.layers.9.self_attn.v_proj.weight": "model.safetensors",
|
||||
"model.norm.weight": "model.safetensors"
|
||||
}
|
||||
}
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3b83627b470a2b3eeb6cbd480490191e50f21549cb3de1d0fcc1a001a48c6c04
|
||||
size 33378493
|
||||
27
tokenizer_config.json
Normal file
27
tokenizer_config.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"additional_special_tokens": null,
|
||||
"backend": "tokenizers",
|
||||
"boi_token": "<start_of_image>",
|
||||
"bos_token": "<bos>",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eoi_token": "<end_of_image>",
|
||||
"eos_token": "<eos>",
|
||||
"image_token": "<image_soft_token>",
|
||||
"is_local": true,
|
||||
"mask_token": "<mask>",
|
||||
"model_max_length": 1000000000000000019884624838656,
|
||||
"model_specific_special_tokens": {
|
||||
"boi_token": "<start_of_image>",
|
||||
"eoi_token": "<end_of_image>",
|
||||
"image_token": "<image_soft_token>",
|
||||
"sfr_token": "<start_function_response>"
|
||||
},
|
||||
"pad_token": "<pad>",
|
||||
"padding_side": "left",
|
||||
"sfr_token": "<start_function_response>",
|
||||
"sp_model_kwargs": null,
|
||||
"spaces_between_special_tokens": false,
|
||||
"tokenizer_class": "GemmaTokenizer",
|
||||
"unk_token": "<unk>",
|
||||
"use_default_system_prompt": false
|
||||
}
|
||||
Reference in New Issue
Block a user