File size: 1,993 Bytes
e5128b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: llama3
---
## Usage From Our SDK


``` python
pip install scalegen-function-calling
```


``` python
from  scalegen_function_calling import CustomOpenAIClient
from openai import OpenAI

tools = [
   {
      "type":"function",
      "function":{
         "name":"Expense",
         "description":"",
         "parameters":{
            "type":"object",
            "properties":{
               "description":{
                  "type":"string"
               },
               "net_amount":{
                  "type":"number"
               },
               "gross_amount":{
                  "type":"number"
               },
               "tax_rate":{
                  "type":"number"
               },
               "date":{
                  "type":"string",
                  "format":"date-time"
               }
            },
            "required":[
               "description",
               "net_amount",
               "gross_amount",
               "tax_rate",
               "date"
            ]
         }
      }
   },
   {
      "type":"function",
      "function":{
         "name":"ReportTool",
         "description":"",
         "parameters":{
            "type":"object",
            "properties":{
               "report":{
                  "type":"string"
               }
            },
            "required":[
               "report"
            ]
         }
      }
   }
]

model_name = "ScaleGenAI/Llama3-70B-Function-Calling"
api_key = "<YOUR_API_KEY>"
api_endpint = "<YOUR_API_ENDPOINT>"

messages = [
    {"role":"user", "content": 'I have spend 5$ on a coffee today please track my expense. The tax rate is 0.2. plz add to expense'}
]

client = OpenAI(
    api_key=api_key,
    base_url=api_endpoint,
)

custom_client = CustomOpenAIClient(client) #patch the client

response = custom_client.chat.completions.create(
            model=model_name,
            messages=messages,
            tools=tools,
            stream=False
        )
```