Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite methods relate to the api #35

Merged
merged 3 commits into from
Apr 30, 2023
Merged

Rewrite methods relate to the api #35

merged 3 commits into from
Apr 30, 2023

Conversation

RexWzh
Copy link
Contributor

@RexWzh RexWzh commented Apr 19, 2023

Hi there!
I've made some backward-compatible changes to several functions that I think would be more Julian. Additionally, I've added a new feature for api_key initialization. Please let me know if you have any issues or concerns about these changes.

@RexWzh
Copy link
Contributor Author

RexWzh commented Apr 19, 2023

This error might be caused by failed access to secrets.OPENAI_API_KEY. The tests are passing successfully here.

@RexWzh
Copy link
Contributor Author

RexWzh commented Apr 20, 2023

Add new funciton get_usage_status:

provider = OpenAI.OpenAIProvider(ENV["OPENAI_API_KEY"], "https://api.openai.com/v1", "")
(; quota, usage, daily_costs) = get_usage_status(provider, numofdays=5)
println("Total quota: $quota")
println("Total usage: $usage")
costs = [sum(item["cost"] for item in day.line_items) for day in daily_costs]
println("Recent costs(5 days): $costs")

Output:

Total quota: 5.00004
Total usage: 0.0003299
Recent costs(5 days): Real[0.03299, 0, 0, 0, 0]

It is a wrapper of

curl -H "Content-Type: application/json" \
     -H "Authorization: Bearer $api_key" \
     -X GET \
     https://api.openai.com/v1/dashboard/billing/usage\?start_date\=$start_date\&end_date\=$end_date

curl -H "Content-Type: application/json" \
     -H "Authorization: Bearer $api_key" \
     -X GET \
     https://api.openai.com/v1/dashboard/billing/subscription

@roryl23
Copy link
Collaborator

roryl23 commented Apr 30, 2023

This looks good to me, thank you for the PR!

@roryl23 roryl23 merged commit e259a45 into JuliaML:main Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants