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

Support get http header and x-ratelimit-* headers #507

Merged
merged 10 commits into from
Oct 10, 2023

Conversation

liushuangls
Copy link
Contributor

@liushuangls liushuangls commented Oct 9, 2023

Describe the change
Support get http header and x-ratelimit-* headers

Issue:

Compare that to #506 this PR support stream mode and x-ratelimit-* headers

@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Merging #507 (e61d41f) into master (8e165dc) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #507      +/-   ##
==========================================
+ Coverage   97.52%   97.58%   +0.05%     
==========================================
  Files          18       19       +1     
  Lines         850      871      +21     
==========================================
+ Hits          829      850      +21     
  Misses         15       15              
  Partials        6        6              
Files Coverage Δ
client.go 100.00% <100.00%> (ø)
ratelimit.go 100.00% <100.00%> (ø)
stream_reader.go 100.00% <ø> (ø)

@sashabaranov
Copy link
Owner

@liushuangls thanks for the PR! Got some conflicts after merging #506, let's settle them and roll a new release with this one merged.

@liushuangls
Copy link
Contributor Author

@liushuangls thanks for the PR! Got some conflicts after merging #506, let's settle them and roll a new release with this one merged.

Done.

@henomis
Copy link
Contributor

henomis commented Oct 10, 2023

@liushuangls @sashabaranov I just sumbitted my PR on the (more or less) same topic, I only saw this PR after submbitted mine. However:

@liushuangls just some suggestions:

  • do not reimplement Header() for stream, simply embed httpHeader (see my PR).
  • ResetRequests and ResetTokens could be both time.Duration without parsing methods.

@sashabaranov let me know how we can handle this duplicate. My personal idea is to go ahead with Liu's PR (with the above suggestions) and use my PR to add headers on streams (with embedded httpHeader) and documentation. The merging order will be first Liu's PR then mine.

@liushuangls
Copy link
Contributor Author

@liushuangls @sashabaranov I just sumbitted my PR on the (more or less) same topic, I only saw this PR after submbitted mine. However:

@liushuangls just some suggestions:

  • do not reimplement Header() for stream, simply embed httpHeader (see my PR).
  • ResetRequests and ResetTokens could be both time.Duration without parsing methods.

@sashabaranov let me know how we can handle this duplicate. My personal idea is to go ahead with Liu's PR (with the above suggestions) and use my PR to add headers on streams (with embedded httpHeader) and documentation. The merging order will be first Liu's PR then mine.

@henomis Thanks for your suggestion, the relevant code has been modified

@liushuangls
Copy link
Contributor Author

@liushuangls @sashabaranov I just sumbitted my PR on the (more or less) same topic, I only saw this PR after submbitted mine. However:

@liushuangls just some suggestions:

  • do not reimplement Header() for stream, simply embed httpHeader (see my PR).
  • ResetRequests and ResetTokens could be both time.Duration without parsing methods.

@sashabaranov let me know how we can handle this duplicate. My personal idea is to go ahead with Liu's PR (with the above suggestions) and use my PR to add headers on streams (with embedded httpHeader) and documentation. The merging order will be first Liu's PR then mine.

@henomis The reason why the ResetRequests and ResetTokens fields are not directly using time.Duration is that I want to preserve the original values outputted by OpenAI. I believe this approach may help identify some issues. However, if this is unnecessary, I can make modifications accordingly.

@henomis
Copy link
Contributor

henomis commented Oct 10, 2023

Ok @liushuangls I understand. And what about aliasing ResetRequests and ResetTokens as string and attaching ToTime() or Time() method?

type ResetRequests string

func (r *ResetRequest) Time() time.Time {
   // implement here the parser
}

func (r *ResetRequest) String() string{
   // implement here stringer
}

@liushuangls
Copy link
Contributor Author

Ok @liushuangls I understand. And what about aliasing ResetRequests and ResetTokens as string and attaching ToTime() or Time() method?

type ResetRequests string

func (r *ResetRequest) Time() time.Time {
   // implement here the parser
}

func (r *ResetRequest) String() string{
   // implement here stringer
}

Very good suggestion, code has been modified.

@henomis
Copy link
Contributor

henomis commented Oct 10, 2023

I've just closed my PR, since I think this is a good implementation now.

models.go Outdated Show resolved Hide resolved
@sashabaranov sashabaranov merged commit b77d01e into sashabaranov:master Oct 10, 2023
3 checks passed
@liushuangls liushuangls deleted the main branch October 11, 2023 00:18
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>
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