---
license: other
license_name: microsoft-research-license
license_link: >-
https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2/blob/main/LICENSE
---
# Phi-2 function calling
This is a merged model of the https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2 and sft function calling lora [here](https://huggingface.co/Yhyu13/dolphin-2_6-phi-2-sft-glaive-function-calling-v2-ep1-lora)
The sft dataset is https://huggingface.co/datasets/Yhyu13/glaive-function-calling-v2-llama-factory-convert, which I converted for llama_factory from original dataset https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2
The function calling is wrapped in simple xml tag for eaiser identification.
```
{\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'}
```
that can be extracted like this
```
import re
import json
input_str = " {\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'} "
# Define the pattern to match the JSON string within the functioncall tags
pattern = r'(.*?)'
# Use re.search to find the matched pattern
match = re.search(pattern, input_str, re.DOTALL)
if match:
json_str = match.group(1)
# Remove the single quotes surrounding the inner JSON string
json_str = json_str.replace("'", "")
# Load the JSON string into a Python dictionary
json_data = json.loads(json_str)
print(json_data)
else:
print("No match found.")
```
Hopefully, this model can be a drop-in replacement for apps (e.g. memgpt) that require function calling ability from LLMs.
# Result
Prompt:
```
SYSTEM: You are a helpful assistant with access to the following functions. Use them if required -\n{\n \"name\": \"get_news_headlines\",\n \"description\": \"Get the latest news headlines\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"country\": {\n \"type\": \"string\",\n \"description\": \"The country for which to fetch news\"\n }\n },\n \"required\": [\n \"country\"\n ]\n }\n}\n\nWhat date is it today?"
```
