Skip to content

Commit

Permalink
Fix query parameter (#64)
Browse files Browse the repository at this point in the history
* Fix query parameter

* update changelog
  • Loading branch information
svilupp authored Sep 26, 2024
1 parent 762daad commit 38d6c93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 0.9.1

* Fixed a bug in `request_body` that prevented `query` argument from being passed to `HTTP.jl`.
* Updated completion model in the unit tests suite (`ada` series has been deprecated).
* Added warnings to `create_edit` that it's deprecated by OpenAI. Disabled tests for `get_usage_status` and `create_edit` functions, as they cannot be tested via API.

### 0.9.0

* Added OpenAI Assistants API

### 0.8.7

* disable `test/usage.jl` in `test/runtests.jl` to close issue: https://github.com/JuliaML/OpenAI.jl/issues/46
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OpenAI"
uuid = "e9f21f70-7185-4079-aca2-91159181367c"
authors = ["Rory Linehan @rory-linehan", "Marius Fersigan @algunion", "RexWzh @RexWzh", "Thatcher Chamberlin @ThatcherC", "Nicu Stiurca @nstiurca", "Peter @chengchingwen", "Stefan Wojcik @stefanjwojcik", "J S @svilupp", "Logan Kilpatrick @logankilpatrick", "Jerry Ling @Moelf"]
version = "0.9.0"
version = "0.9.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
4 changes: 3 additions & 1 deletion src/OpenAI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ end

function request_body(url, method; input, headers, query, kwargs...)
input = isnothing(input) ? [] : input
query = isnothing(query) ? [] : query

resp = HTTP.request(method,
url;
Expand Down Expand Up @@ -393,6 +392,8 @@ end
"""
Create edit
Note: This functionality is not accessible via API anymore -- see https://platform.openai.com/docs/deprecations
# Arguments:
- `api_key::String`: OpenAI API key
- `model_id::String`: Model id (e.g. "text-davinci-edit-001")
Expand All @@ -410,6 +411,7 @@ function create_edit(api_key::String,
instruction::String;
http_kwargs::NamedTuple = NamedTuple(),
kwargs...)
@warn "This functionality is not accessible via API anymore -- see https://platform.openai.com/docs/deprecations"
return openai_request("edits",
api_key;
method = "POST",
Expand Down
21 changes: 12 additions & 9 deletions test/completion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
@test false
end
r = create_completion(ENV["OPENAI_API_KEY"],
"text-ada-001";
"gpt-3.5-turbo-instruct";
prompt = "Say \"this is a test\"")
println(r.response["choices"][begin]["text"])
if !=(r.status, 200)
@test false
end
end

@testset "create edit" begin
r = create_edit(ENV["OPENAI_API_KEY"],
"text-davinci-edit-001",
"Fix this piece of text for grammatical errors",
input = "I hav ben riting sence i wuz 5")
println(r.response["choices"][begin]["text"])
if !=(r.status, 200)
@test false
# This functionality is not accessible via API anymore -- see https://platform.openai.com/docs/deprecations
@test_skip begin
@testset "create edit" begin
r = create_edit(ENV["OPENAI_API_KEY"],
"gpt-3.5-turbo-instruct",
"Fix this piece of text for grammatical errors",
input = "I hav ben riting sence i wuz 5")
println(r.response["choices"][begin]["text"])
if !=(r.status, 200)
@test false
end
end
end
25 changes: 14 additions & 11 deletions test/usage.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Get usage status of an api

# See https://github.com/JuliaML/OpenAI.jl/issues/46
@testset "usage information" begin
provider = OpenAI.OpenAIProvider(ENV["OPENAI_API_KEY"], "https://api.openai.com/v1", "")
(; quota, usage, daily_costs) = get_usage_status(provider, numofdays = 5)
@test quota > 0
@test usage >= 0
@test length(daily_costs) == 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")
end
# This functionality is not accessible via API anymore -- see https://platform.openai.com/docs/api-reference/administration
@test_skip begin
@testset "usage information" begin
provider = OpenAI.OpenAIProvider(ENV["OPENAI_API_KEY"], "https://api.openai.com/v1", "")
(; quota, usage, daily_costs) = get_usage_status(provider, numofdays = 5)
@test quota > 0
@test usage >= 0
@test length(daily_costs) == 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")
end
end

2 comments on commit 38d6c93

@roryl23
Copy link
Collaborator

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/116051

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.9.1 -m "<description of version>" 38d6c936579c9306bff8f6f276a68f1485d2c9ce
git push origin v0.9.1

Please sign in to comment.