Skip to content

Commit

Permalink
remove get_usage_status
Browse files Browse the repository at this point in the history
  • Loading branch information
roryl23 committed Sep 28, 2024
1 parent b0ba988 commit bd3ed8e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### 0.10.0

* Removed deprecated features `create_edit` and `get_usage_statistics`
* Removed deprecated features `create_edit` and `get_usage_status`

### 0.9.1

Expand Down
88 changes: 5 additions & 83 deletions src/OpenAI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ Create embeddings
To get embeddings for multiple inputs in a single request, pass an array of strings
or array of token arrays. Each input must not exceed 8192 tokens in length.
- `model_id::String`: Model id. Defaults to $DEFAULT_EMBEDDING_MODEL_ID.
# Keyword Arguments:
- `http_kwargs::NamedTuple`: Optional. Keyword arguments to pass to HTTP.request.
For additional details about the endpoint, visit <https://platform.openai.com/docs/api-reference/embeddings>
"""
function create_embeddings(api_key::String,
Expand All @@ -421,7 +421,7 @@ end
"""
Create images
# Arguments:
# Arguments:
- `api_key::String`: OpenAI API key
- `prompt`: The input text to generate the image(s) for, as String or array of tokens.
- `n::Integer`: Optional. The number of images to generate. Must be between 1 and 10.
Expand All @@ -433,8 +433,8 @@ Create images
For additional details about the endpoint, visit <https://platform.openai.com/docs/api-reference/images/create>
# once the request is made,
download like this:
# once the request is made,
download like this:
`download(r.response["data"][begin]["url"], "image.png")`
"""
function create_images(api_key::String,
Expand All @@ -451,83 +451,6 @@ function create_images(api_key::String,
kwargs...)
end

"""
get_usage_status(provider::OpenAIProvider; numofdays::Int=99)
NOTE: currently this endpoint can only be used from the browser. See https://github.com/JuliaML/OpenAI.jl/issues/46
Get usage status for the last `numofdays` days.
# Arguments:
- `provider::OpenAIProvider`: OpenAI provider object.
- `numofdays::Int`: Optional. Defaults to 99. The number of days to get usage status for.
Note that the maximum `numofdays` is 99.
# Returns:
- `quota`: The total quota for the subscription.(unit: USD)
- `usage`: The total usage for the subscription.(unit: USD)
- `daily_costs`: The daily costs for the subscription.
Each element of `daily_costs` looks like this:
```
{
"timestamp": 1681171200,
"line_items": [
{
"name": "Instruct models",
"cost": 0
},
{
"name": "Chat models",
"cost": 0
},
{
"name": "GPT-4",
"cost": 0
},
{
"name": "Fine-tuned models",
"cost": 0
},
{
"name": "Embedding models",
"cost": 0
},
{
"name": "Image models",
"cost": 0
},
{
"name": "Audio models",
"cost": 0
}
]
}
```
"""
function get_usage_status(provider::OpenAIProvider; numofdays::Int = 99)
(; base_url, api_key) = provider
isempty(api_key) && throw(ArgumentError("api_key cannot be empty"))
numofdays > 99 && throw(ArgumentError("numofdays cannot be greater than 99"))

# Get total quota from subscription_url
subscription_url = "$base_url/dashboard/billing/subscription"
subscrip = HTTP.get(subscription_url, headers = auth_header(provider))
resp = OpenAIResponse(subscrip.status, JSON3.read(subscrip.body))
# TODO: catch error
quota = resp.response.hard_limit_usd

# Get usage status from billing_url
start_date = today()
end_date = today() + Day(numofdays)
billing_url = "$base_url/dashboard/billing/usage?start_date=$(start_date)&end_date=$(end_date)"
billing = HTTP.get(billing_url, headers = auth_header(provider))
resp = OpenAIResponse(billing.status, JSON3.read(billing.body))
usage = resp.response.total_usage / 100
daily_costs = resp.response.daily_costs
return (; quota, usage, daily_costs)
end

include("assistants.jl")

export OpenAIResponse
Expand All @@ -537,7 +460,6 @@ export create_chat
export create_completion
export create_embeddings
export create_images
export get_usage_status

# Assistant exports
export list_assistants
Expand Down
17 changes: 0 additions & 17 deletions test/usage.jl

This file was deleted.

2 comments on commit bd3ed8e

@roryl23
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116225

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" bd3ed8ee504a8a25be93ead925a5fd43461aa8a1
git push origin v0.10.0

Please sign in to comment.