Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -13,6 +13,8 @@ datasets:
|
|
| 13 |
## Quickstart
|
| 14 |
|
| 15 |
### utils for user content.
|
|
|
|
|
|
|
| 16 |
```python
|
| 17 |
xlam_system = (
|
| 18 |
"You are an AI assistant for function calling. "
|
|
@@ -39,17 +41,29 @@ If the given question lacks the parameters required by the function, fill the pa
|
|
| 39 |
|
| 40 |
FORMAT_INSTRUCTION = '''The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
|
| 41 |
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.
|
| 42 |
-
|
| 43 |
{ "tool_calls": [
|
| 44 |
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
|
| 45 |
... (more tool calls as required)
|
| 46 |
] }
|
| 47 |
-
|
| 48 |
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
```
|
| 50 |
|
| 51 |
### inference
|
|
|
|
|
|
|
| 52 |
```python
|
|
|
|
| 53 |
user_msg = '''<instruction>
|
| 54 |
You are an expert in composing functions. You are given a question and a set of possible functions.
|
| 55 |
Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
|
|
@@ -64,12 +78,12 @@ If the given question lacks the parameters required by the function, fill the pa
|
|
| 64 |
<tool format>
|
| 65 |
The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
|
| 66 |
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.
|
| 67 |
-
|
| 68 |
{ "tool_calls": [
|
| 69 |
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
|
| 70 |
... (more tool calls as required)
|
| 71 |
] }
|
| 72 |
-
|
| 73 |
</tool format>
|
| 74 |
|
| 75 |
<query>
|
|
@@ -78,10 +92,7 @@ Check if the username 'ShopMaster123' is available on Shopify.
|
|
| 78 |
|
| 79 |
messages = [dict(role='user', content=user_msg)]
|
| 80 |
label = { "tool_calls": [{"name": "shopify", "arguments": {"username": "ShopMaster123"}}] }
|
| 81 |
-
```
|
| 82 |
|
| 83 |
-
```python
|
| 84 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 85 |
|
| 86 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 87 |
"objects76/qwen2-xlam", trust_remote_code=True)
|
|
|
|
| 13 |
## Quickstart
|
| 14 |
|
| 15 |
### utils for user content.
|
| 16 |
+
- replace [TRIPLE_BACKTICK] to ```
|
| 17 |
+
|
| 18 |
```python
|
| 19 |
xlam_system = (
|
| 20 |
"You are an AI assistant for function calling. "
|
|
|
|
| 41 |
|
| 42 |
FORMAT_INSTRUCTION = '''The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
|
| 43 |
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.
|
| 44 |
+
[TRIPLE_BACKTICK]
|
| 45 |
{ "tool_calls": [
|
| 46 |
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
|
| 47 |
... (more tool calls as required)
|
| 48 |
] }
|
| 49 |
+
[TRIPLE_BACKTICK]
|
| 50 |
'''
|
| 51 |
+
|
| 52 |
+
def get_prompt(xlam_tools:list|dict, query:str ):
|
| 53 |
+
if not isinstance(xlam_tools, str): xlam_tools = json.dumps(xlam_tools)
|
| 54 |
+
prompt = f"<instruction>\n{TASK_INSTRUCTION}\n</instruction>\n\n"
|
| 55 |
+
prompt += f"<available tools>\n{xlam_tools}\n</available tools>\n\n"
|
| 56 |
+
prompt += f"<tool format>\n{FORMAT_INSTRUCTION}\n</tool format>\n\n"
|
| 57 |
+
prompt += f"<query>\n{query.strip()}\n<query>\n\n"
|
| 58 |
+
return prompt
|
| 59 |
+
|
| 60 |
```
|
| 61 |
|
| 62 |
### inference
|
| 63 |
+
- replace [TRIPLE_BACKTICK] to ```
|
| 64 |
+
|
| 65 |
```python
|
| 66 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 67 |
user_msg = '''<instruction>
|
| 68 |
You are an expert in composing functions. You are given a question and a set of possible functions.
|
| 69 |
Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
|
|
|
|
| 78 |
<tool format>
|
| 79 |
The output MUST strictly adhere to the following JSON format, and NO other text MUST be included.
|
| 80 |
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.
|
| 81 |
+
[TRIPLE_BACKTICK]
|
| 82 |
{ "tool_calls": [
|
| 83 |
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
|
| 84 |
... (more tool calls as required)
|
| 85 |
] }
|
| 86 |
+
[TRIPLE_BACKTICK]
|
| 87 |
</tool format>
|
| 88 |
|
| 89 |
<query>
|
|
|
|
| 92 |
|
| 93 |
messages = [dict(role='user', content=user_msg)]
|
| 94 |
label = { "tool_calls": [{"name": "shopify", "arguments": {"username": "ShopMaster123"}}] }
|
|
|
|
| 95 |
|
|
|
|
|
|
|
| 96 |
|
| 97 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 98 |
"objects76/qwen2-xlam", trust_remote_code=True)
|