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

Feat Add headers to openai responses #506

Merged

Conversation

henomis
Copy link
Contributor

@henomis henomis commented Oct 6, 2023

Describe the change
This branch adds headers to all opeanai http responses.

Describe your solution
This was done embedding a struct httpHeader to each response struct. The httpHeader type has attached methods to set and get http.Header. The low level sendRequest uses a Response interface defining the SetHeader method of httpHeader.

Tests
TestChatCompletionsWithHeaders has been added to check a test header.

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #506 (004bcf0) into master (84f77a0) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #506      +/-   ##
==========================================
+ Coverage   97.48%   97.52%   +0.04%     
==========================================
  Files          18       18              
  Lines         836      850      +14     
==========================================
+ Hits          815      829      +14     
  Misses         15       15              
  Partials        6        6              
Files Coverage Δ
audio.go 89.15% <100.00%> (+0.99%) ⬆️
chat.go 100.00% <ø> (ø)
client.go 100.00% <100.00%> (ø)
completion.go 100.00% <ø> (ø)
edits.go 100.00% <ø> (ø)
embeddings.go 100.00% <ø> (ø)
engines.go 100.00% <ø> (ø)
files.go 94.73% <ø> (ø)
fine_tunes.go 100.00% <ø> (ø)
fine_tuning_job.go 100.00% <ø> (ø)
... and 3 more

@sashabaranov
Copy link
Owner

Hey, thank you for the PR! Just out of curiosity: what use cases do you envision for this?

@henomis
Copy link
Contributor Author

henomis commented Oct 6, 2023

The main motivation is because there are some issues related to headers

However there is a documentation that covers headers for rate limits for example, and you may need these information.

And, if you agree, the next PR could be focused to implement specifics methods of httpHeader to have (for example) resp.RatelimitResetRequests() to return specific (and documented) openai headers

@liushuangls
Copy link
Contributor

Thank you for the PR! Is there a way to get the header in steam mode?

@sashabaranov sashabaranov merged commit 8e165dc into sashabaranov:master Oct 9, 2023
3 checks passed
mudler referenced this pull request in mudler/LocalAI Oct 14, 2023
…#1159)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/sashabaranov/go-openai](https://github.com/sashabaranov/go-openai)
| require | minor | `v1.15.4` -> `v1.16.0` |

---

### Release Notes

<details>
<summary>sashabaranov/go-openai
(github.com/sashabaranov/go-openai)</summary>

###
[`v1.16.0`](https://github.com/sashabaranov/go-openai/releases/tag/v1.16.0)

[Compare
Source](https://github.com/sashabaranov/go-openai/compare/v1.15.4...v1.16.0)

#### What's Changed

- Add DotProduct Method and README Example for Embedding Similarity
Search by [@&#8203;ealvar3z](https://github.com/ealvar3z) in
[https://github.com/sashabaranov/go-openai/pull/492](https://github.com/sashabaranov/go-openai/pull/492)
- fix: use any for n_epochs by
[@&#8203;henomis](https://github.com/henomis) in
[https://github.com/sashabaranov/go-openai/pull/499](https://github.com/sashabaranov/go-openai/pull/499)
- Feat Add headers to openai responses by
[@&#8203;henomis](https://github.com/henomis) in
[https://github.com/sashabaranov/go-openai/pull/506](https://github.com/sashabaranov/go-openai/pull/506)
- Support get http header and x-ratelimit-\* headers by
[@&#8203;liushuangls](https://github.com/liushuangls) in
[https://github.com/sashabaranov/go-openai/pull/507](https://github.com/sashabaranov/go-openai/pull/507)

**Full Changelog**:
sashabaranov/go-openai@v1.15.4...v1.16.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/go-skynet/LocalAI).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44LjEiLCJ1cGRhdGVkSW5WZXIiOiIzNy44LjEiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
mauriciovasquezbernal added a commit to mauriciovasquezbernal/go-openai that referenced this pull request Dec 20, 2023
Fixes issue when using non audio formats:

Transcription error: json: cannot unmarshal number into Go value of type openai.audioTextResponse

Fixes: 8e165dc ("Feat Add headers to openai responses (sashabaranov#506)")
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.

3 participants