Views
No views yet
pip install scalegen-function-calling1from scalegen_function_calling import CustomOpenAIClient
2from openai import OpenAI
3
4tools = [
5 {
6 "type":"function",
7 "function":{
8 "name":"Expense",
9 "description":"",
10 "parameters":{
11 "type":"object",
12 "properties":{
13 "description":{
14 "type":"string"
15 },
16 "net_amount":{
17 "type":"number"
18 },
19 "gross_amount":{
20 "type":"number"
21 },
22 "tax_rate":{
23 "type":"number"
24 },
25 "date":{
26 "type":"string",
27 "format":"date-time"
28 }
29 },
30 "required":[
31 "description",
32 "net_amount",
33 "gross_amount",
34 "tax_rate",
35 "date"
36 ]
37 }
38 }
39 },
40 {
41 "type":"function",
42 "function":{
43 "name":"ReportTool",
44 "description":"",
45 "parameters":{
46 "type":"object",
47 "properties":{
48 "report":{
49 "type":"string"
50 }
51 },
52 "required":[
53 "report"
54 ]
55 }
56 }
57 }
58]
59
60model_name = "ScaleGenAI/Llama3-70B-Function-Calling"
61api_key = "<YOUR_API_KEY>"
62api_endpint = "<YOUR_API_ENDPOINT>"
63
64messages = [
65 {"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'}
66]
67
68client = OpenAI(
69 api_key=api_key,
70 base_url=api_endpoint,
71)
72
73custom_client = CustomOpenAIClient(client) #patch the client
74
75response = custom_client.chat.completions.create(
76 model=model_name,
77 messages=messages,
78 tools=tools,
79 stream=False
80 )