FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/examples/responses_input_tokens.py at main · hironow/openai-python · GitHub
hironow
openai-python
Repository navigation
Code
Pull requests
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openai-python
/
examples
/
responses_input_tokens.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (47 loc) · 1.62 KB
Breadcrumbs
openai-python
/
examples
/
responses_input_tokens.py
Copy path
File metadata and controls
54 lines (47 loc) · 1.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
typing
import
List
from
openai
import
OpenAI
from
openai
.
types
.
responses
.
tool_param
import
ToolParam
from
openai
.
types
.
responses
.
response_input_item_param
import
ResponseInputItemParam
def
main
()
->
None
:
client
=
OpenAI
()
tools
:
List
[
ToolParam
]
=
[
{
"type"
:
"function"
,
"name"
:
"get_current_weather"
,
"description"
:
"Get current weather in a given location"
,
"parameters"
: {
"type"
:
"object"
,
"properties"
: {
"location"
: {
"type"
:
"string"
,
"description"
:
"City and state, e.g. San Francisco, CA"
,
},
"unit"
: {
"type"
:
"string"
,
"enum"
: [
"c"
,
"f"
],
"description"
:
"Temperature unit to use"
,
},
},
"required"
: [
"location"
,
"unit"
],
"additionalProperties"
:
False
,
},
"strict"
:
True
,
}
]
input_items
:
List
[
ResponseInputItemParam
]
=
[
{
"type"
:
"message"
,
"role"
:
"user"
,
"content"
: [{
"type"
:
"input_text"
,
"text"
:
"What's the weather in San Francisco today?"
}],
}
]
response
=
client
.
responses
.
input_tokens
.
count
(
model
=
"gpt-5"
,
instructions
=
"You are a concise assistant."
,
input
=
input_items
,
tools
=
tools
,
tool_choice
=
{
"type"
:
"function"
,
"name"
:
"get_current_weather"
},
)
print
(
f"input tokens:
{
response
.
input_tokens
}
"
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL