File size: 6,078 Bytes
035ded0
 
 
 
 
97d47bd
035ded0
 
 
 
 
 
 
 
 
 
 
 
857f8a3
 
 
b5f2816
 
857f8a3
 
 
 
 
 
 
 
 
 
 
 
9b69d01
 
857f8a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45c1b29
857f8a3
 
 
 
45c1b29
857f8a3
 
 
 
 
 
 
 
 
 
 
dfdf0d6
 
 
857f8a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
---
library_name: transformers
tags:
- trl
- sft
base_model: Qwen/Qwen2.5-3B-Instruct
---

# Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->



## Model Details

### Model Description

This models fine-tuning for function calling task, and communicate

Training time: more than 1 hour

Steps: 200 (16)

### Usage:
```
import json
from typing import Any, Dict, List
from transformers import AutoModelForCausalLM, AutoTokenizer

models = [
    'beyoru/Neeru'
]
model_name = models[-1]
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16
)
tokenizer = AutoTokenizer.from_pretrained(model_name)


SYSTEM_PROMPT = """You are a helpful assistant with access to the following functions. Use them if required

You may call one or more functions to assist with the user query.

Before calling a function, ensure that all required parameters are provided. If any required parameter is missing, ask the user for the missing information before proceeding.

You are provided with function:

{tools}

For each function call, return a json object with function name and arguments:

[{{"name": "<function-name>", "arguments": <args-json-object>}}]
"""
TOOL_PROMPT = "{tool_text}"

get_weather_api = {
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "str",
                    "description": "The city and state",
                },
                "unit": {
                    "type": "str",
                    "enum": ["celsius", "fahrenheit"],
                    "description": "The unit of temperature to return",
                },
            },
            "required": ["location"],
        },
    },
}


get_search_api = {
    "type": "function",
    "function": {
        "name": "get_search",
        "description": "Search the web for a query",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search query"
                }
            },
            "required": ["query"]
        }
    }
}

TOOL_PROMPT = "{tool_text}"

get_weather_api = {
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "The city and state"},
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return"},
            },
            "required": ["location"],
        },
    },
}

get_search_api = {
    "type": "function",
    "function": {
        "name": "get_search",
        "description": "Search the web for a query",
        "parameters": {
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "The search query"}
            },
            "required": ["query"],
        },
    },
}

get_warehouse_api = {
    "type": "function",
    "function": {
        "name": "get_warehouse_info",
        "description": "Get warehouse information based on multiple parameters",
        "parameters": {
            "type": "object",
            "properties": {
                "warehouse_id": {
                    "type": "string",
                    "description": "Unique identifier of the warehouse"
                },
                "location": {
                    "type": "string",
                    "description": "Location of the warehouse"
                },
                "status": {
                    "type": "string",
                    "enum": ["active", "inactive", "under maintenance"],
                    "description": "Operational status of the warehouse"
                },
                "capacity": {
                    "type": "integer",
                    "description": "Total storage capacity of the warehouse"
                },
                "current_stock": {
                    "type": "integer",
                    "description": "Current stock available in the warehouse"
                },
                "manager": {
                    "type": "string",
                    "description": "Name of the warehouse manager"
                },
                "contact": {
                    "type": "string",
                    "description": "Contact details of the warehouse"
                },
                "operating_hours": {
                    "type": "string",
                    "description": "Operating hours of the warehouse"
                }
            },
            "required": ["warehouse_id", "location", "status"],
        },
    },
}



TOOLS = [get_search_api, get_weather_api, get_warehouse_api]

def convert_tools(tools: List[Dict[str, Any]]) -> str:
    return json.dumps(tools, indent=2)


def format_prompt(tools: List[Dict[str, Any]]) -> str:
    tool_text = convert_tools(tools)
    return f"{SYSTEM_PROMPT.format(tools=tool_text)}"


system_prompt = format_prompt(TOOLS)

# print(system_prompt)

"""
Simple loop for conversations

"""

while True:
    user_input = input("User: ")
    messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_input},
    ]

    inputs = tokenizer.apply_chat_template(
        messages, add_generation_prompt=True, return_tensors="pt" 
    ) # You can added more history conversations here

    outputs = model.generate(
        inputs,
        max_new_tokens=2048,
        top_p=0.95,
        temperature=0.7,
    ) # Suggest parameters

    response_text = tokenizer.decode(outputs[0][len(inputs[0]) :], skip_special_tokens=True)

    print("Assistant:", response_text)
```

### Config
```
all_linear layers
r = 64
alpha = 512
```