@@ -28,11 +28,80 @@ class CalendarEvent(BaseModel):
2828)
2929
3030
31- if __name__ == "__main__" :
32- event = completion .choices [0 ].message .parsed
33- print (type (event ))
34- print (event )
31+ def main ():
32+ response = client .chat .completions .create (
33+ model = "gpt-4o-2024-08-06" ,
34+ messages = [
35+ {"role" : "system" , "content" : "You are a helpful math tutor. Guide the user through the solution step by step." },
36+ {"role" : "user" , "content" : "how can I solve 8x + 7 = -23" },
37+ ],
38+ response_format = {
39+ "type" : "json_schema" ,
40+ "json_schema" : {
41+ "name" : "math_response" ,
42+ "schema" : {
43+ "type" : "object" ,
44+ "properties" : {
45+ "steps" : {
46+ "type" : "array" ,
47+ "items" : {
48+ "type" : "object" ,
49+ "properties" : {"explanation" : {"type" : "string" }, "output" : {"type" : "string" }},
50+ "required" : ["explanation" , "output" ],
51+ "additionalProperties" : False ,
52+ },
53+ },
54+ "final_answer" : {"type" : "string" },
55+ },
56+ "required" : ["steps" , "final_answer" ],
57+ "additionalProperties" : False ,
58+ },
59+ "strict" : True ,
60+ },
61+ },
62+ )
63+
64+ print (response .choices [0 ].message .content )
65+
66+
67+ def main2 ():
68+ tools = [
69+ {
70+ "type" : "function" ,
71+ "function" : {
72+ "name" : "get_delivery_date" ,
73+ "description" : "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'" ,
74+ "parameters" : {
75+ "type" : "object" ,
76+ "properties" : {
77+ "order_id" : {
78+ "type" : "string" ,
79+ "description" : "The customer's order ID." ,
80+ },
81+ },
82+ "required" : ["order_id" ],
83+ "additionalProperties" : False ,
84+ },
85+ },
86+ "strict" : True ,
87+ }
88+ ]
3589
90+ messages = [
91+ {"role" : "system" , "content" : "You are a helpful customer support assistant. Use the supplied tools to assist the user." },
92+ {"role" : "user" , "content" : "Hi, can you tell me the delivery date for my order with id 5?" },
93+ ]
3694
37- TraceLog (configuration = LLMInputs (model = 'gpt-4o-2024-08-06' , provider = 'openai' , model_params = ModelParams (temp = 1.0 , top_p = 1.0 , frequency_penalty = 0.0 , presence_penalty = 0.0 , max_length = None , response_format = "<class '__main__.CalendarEvent'>" , safe_prompt = None ), messages = [{'role' : 'system' , 'content' : 'Extract the event information.' }, {'role' : 'user' , 'content' : 'Alice and Bob are going to a science fair on Friday.' }], history = None , functions = [], function_call = None ), inputs = None , output = '{"name":"Science Fair","date":"Friday","participants":["Alice","Bob"]}' , target = None , latency = 1.771622 , time_to_first_token = None , input_tokens = 32 , output_tokens = 17 , total_tokens = 49 , cost = 0.000415 , scores = [], trace_id = 'e894b955-c844-49f5-8480-71b0841f10b5' , parent_trace_id = 'e894b955-c844-49f5-8480-71b0841f10b5' , root_trace_id = 'e894b955-c844-49f5-8480-71b0841f10b5' , start_timestamp = '2024-08-06T20:26:42.365024+00:00' , organization_id = None , project_uuid = None , error = None , status = 'success' , deployment_id = None , cache_hit = False , output_for_eval_metrics = None , evaluation_metric_names = [], apply_eval_frac = 1.0 , feedback_score = None , trace_name = 'llm-openai' , children = ['600b25b7-417a-4409-8f96-afe8dd8fe8cf' ], end_timestamp = '2024-08-06T20:26:44.136646+00:00' , end_user_identifier = None , session_id = None , metadata = None , tags = None , experiment_uuid = None , images = [], comments = None , annotations = None , depth = 0 , execution_order = 0 )
38- D {'configuration' : {'model' : 'gpt-4o-2024-08-06' , 'provider' : 'openai' , 'model_params' : {'temp' : 1.0 , 'top_p' : 1.0 , 'frequency_penalty' : 0.0 , 'presence_penalty' : 0.0 , 'max_length' : None , 'response_format' : "<class '__main__.CalendarEvent'>" , 'safe_prompt' : None }, 'messages' : [{'role' : 'system' , 'content' : 'Extract the event information.' }, {'role' : 'user' , 'content' : 'Alice and Bob are going to a science fair on Friday.' }], 'history' : None , 'functions' : [], 'function_call' : None }, 'inputs' : None , 'output' : '{"name":"Science Fair","date":"Friday","participants":["Alice","Bob"]}' , 'target' : None , 'latency' : 1.771622 , 'time_to_first_token' : None , 'input_tokens' : 32 , 'output_tokens' : 17 , 'total_tokens' : 49 , 'cost' : 0.000415 , 'scores' : [], 'trace_id' : 'e894b955-c844-49f5-8480-71b0841f10b5' , 'parent_trace_id' : 'e894b955-c844-49f5-8480-71b0841f10b5' , 'root_trace_id' : 'e894b955-c844-49f5-8480-71b0841f10b5' , 'start_timestamp' : '2024-08-06T20:26:42.365024+00:00' , 'organization_id' : None , 'project_uuid' : '1c4dfe49-bf84-11ee-92b3-3a9b36099f82' , 'error' : None , 'status' : 'success' , 'deployment_id' : None , 'cache_hit' : False , 'output_for_eval_metrics' : None , 'evaluation_metric_names' : [], 'apply_eval_frac' : 1.0 , 'feedback_score' : None , 'trace_name' : 'llm-openai' , 'children' : ['600b25b7-417a-4409-8f96-afe8dd8fe8cf' ], 'end_timestamp' : '2024-08-06T20:26:44.136646+00:00' , 'end_user_identifier' : None , 'session_id' : None , 'metadata' : None , 'tags' : None , 'experiment_uuid' : None , 'images' : [], 'comments' : None , 'annotations' : None , 'depth' : 0 , 'execution_order' : 0 }
95+ response = client .chat .completions .create (
96+ model = "gpt-4o-2024-08-06" ,
97+ messages = messages ,
98+ tools = tools ,
99+ )
100+ print (response .choices [0 ].message .tool_calls )
101+
102+
103+ if __name__ == "__main__" :
104+ # event = completion.choices[0].message.parsed
105+ # print(event)
106+ # main()
107+ main2 ()
0 commit comments