File tree Expand file tree Collapse file tree 5 files changed +13
-29
lines changed Expand file tree Collapse file tree 5 files changed +13
-29
lines changed Original file line number Diff line number Diff line change
1
+ import json
1
2
from typing import List , Optional
2
3
import instructor
3
4
from pydantic import BaseModel , Field
@@ -33,7 +34,4 @@ class AvailabilityRequest(BaseModel):
33
34
],
34
35
)
35
36
36
- print (response .personIds )
37
- print (response .numberOfConsecutiveDays )
38
-
39
- print (response )
37
+ print (response .model_dump_json (indent = 3 ))
Original file line number Diff line number Diff line change
1
+ import json
1
2
from typing import List , Optional
2
- import instructor
3
- from pydantic import BaseModel , Field
4
- from openai import OpenAI
5
3
4
+ from openai import OpenAI
6
5
from prompts import extraction_system_message
6
+ from pydantic import BaseModel , Field
7
7
8
+ import instructor
8
9
9
10
# --------------------------------------------------------------
10
11
# Instructor with Maybe pattern
11
12
# --------------------------------------------------------------
12
13
13
- client = instructor .from_openai (OpenAI ())
14
- MODEL = "gpt-4o-2024-08-06"
14
+ api_url = "https://api.openai.com/v1/" #http://localhost:11434/v1
15
+ MODEL = "gpt-4o-2024-08-06" # qwen2.5:7b-instruct-fp16
16
+
17
+ client = instructor .from_openai (OpenAI (base_url = api_url ))
18
+
15
19
16
20
class AvailabilityRequest (BaseModel ):
17
21
personIds : List [int ] = Field (description = "List of person IDs to check availability for" )
@@ -43,9 +47,4 @@ def __bool__(self):
43
47
],
44
48
)
45
49
46
- print (response .error )
47
- print (response .message )
48
- print (response .result .personIds )
49
- print (response .result .numberOfConsecutiveDays )
50
-
51
- print (response )
50
+ print (response .model_dump_json (indent = 3 ))
Original file line number Diff line number Diff line change 28
28
)
29
29
30
30
message = response .choices [0 ].message .content
31
- type (message )
32
-
33
31
print (message )
34
32
35
33
60
58
)
61
59
62
60
message = response .choices [0 ].message .content
63
- type (message )
64
61
65
62
message_dict = json .loads (message )
66
-
67
- type (message_dict )
68
63
message_dict .keys ()
69
64
70
65
message_dict ["lastName" ]
Original file line number Diff line number Diff line change 34
34
)
35
35
36
36
message = response .choices [0 ].message .content
37
- type (message )
38
-
39
37
message_json = json .loads (message )
40
- type (message_json )
41
38
42
39
print (message_json )
43
40
Original file line number Diff line number Diff line change 71
71
)
72
72
73
73
tool_call = response .choices [0 ].message .tool_calls [0 ]
74
- type (
75
- tool_call
76
- ) # openai.types.chat.chat_completion_message_tool_call.ChatCompletionMessageToolCall
77
-
78
74
function_args = json .loads (tool_call .function .arguments )
79
- type (function_args ) # dict
80
75
81
- print (function_args [ "lastName" ] )
76
+ print (tool_call )
82
77
print (function_args )
83
78
84
79
You can’t perform that action at this time.
0 commit comments