Skip to content

update with sashabaranov/go-openai/master #1049

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

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
02a1da9
feat: add top_k & repetition_penalty to completion request
skyerus May 13, 2024
d46a189
Merge pull request #1 from lookfirst-io/skye/CompletionRequest
skyerus May 13, 2024
89e8ae3
fix: fork replace
skyerus May 13, 2024
cd804cc
Merge pull request #2 from lookfirst-io/skye/fork-fix
skyerus May 13, 2024
78803c3
feat: disable supported models check
skyerus May 14, 2024
d882fbe
Merge pull request #3 from lookfirst-io/skye/disable-support-check
skyerus May 14, 2024
432d878
adds min_p
akhazr Jun 21, 2024
4abf471
update go mod
akhazr Jun 21, 2024
3b11a00
update go mod
akhazr Jun 24, 2024
693259b
Merge pull request #4 from lookfirst-io/addMinP
akhazr Jun 24, 2024
9dddaf0
add url to stream function
akhazr Jul 12, 2024
4ecab39
Merge pull request #5 from lookfirst-io/streamingURL
akhazr Jul 12, 2024
e8e401e
Revert "add url to stream function"
akhazr Jul 12, 2024
b246702
Merge pull request #6 from lookfirst-io/revert-5-streamingURL
akhazr Jul 12, 2024
07c30f9
Add topk and rep pen to chat completions
manbax Nov 14, 2024
c36233a
Merge pull request #9 from lookfirst-io/manba/add_topk_reppen_chat_co…
manbax Nov 14, 2024
c793536
include reasoning bool
manbax Feb 5, 2025
a2cc3e7
Merge pull request #10 from lookfirst-io/manba/add_reasoningboolean
manbax Feb 5, 2025
e9cdfd7
Add provider control for openrouter
manbax Mar 7, 2025
d560e69
Merge pull request #11 from lookfirst-io/manba/add_provider_control_o…
manbax Mar 7, 2025
2587e68
Add reasoning control openrouter
manbax Mar 7, 2025
89fcddd
Add context url docs
manbax Mar 7, 2025
33e068e
update
manbax Mar 7, 2025
df4b6f0
Merge pull request #12 from lookfirst-io/manba/add_reasoning_control_…
manbax Mar 7, 2025
6a6fc95
Update Provider
manbax Mar 8, 2025
586b866
Merge pull request #13 from lookfirst-io/manba/update_reasoning
manbax Mar 8, 2025
9beaf40
Make reasoning and provider optional
manbax Mar 8, 2025
af9f0a1
Merge pull request #14 from lookfirst-io/manba/optional_field_reasoni…
manbax Mar 8, 2025
9044f62
Reasoning and provider optional in completions
manbax Mar 8, 2025
4f28667
Merge pull request #15 from lookfirst-io/manba/field_optional_complet…
manbax Mar 8, 2025
a4ee76e
Fix: stream reader
manbax Mar 10, 2025
f10fcab
Merge pull request #16 from lookfirst-io/manba/stream_reader_finish
manbax Mar 10, 2025
f37d820
Feat: Add Provider in response
manbax Mar 17, 2025
ca94be7
update
manbax Mar 17, 2025
cec7070
feat: add include reasoning for openrouter model
manbax May 21, 2025
56cdaf3
Merge pull request #18 from lookfirst-io/manba/add_include_reasoning
manbax May 21, 2025
03c92bf
Merge pull request #17 from lookfirst-io/manba/add_provider_response
manbax May 21, 2025
a5698c8
feat: add openrouter provider control : only
manbax May 26, 2025
7333769
Merge pull request #19 from lookfirst-io/manba/addmore_provider_contr…
manbax May 26, 2025
06d6c2b
Adds reasoning enabled (#20)
thihamin Jun 18, 2025
ef513b1
merged with master from https://github.com/sashabaranov/go-openai
thihamin Jul 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# These are supported funding model platforms

github: [sashabaranov, vvatanabe]
github: [lookfirst-io, vvatanabe]
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ assignees: ''
---

Your issue may already be reported!
Please search on the [issue tracker](https://github.com/sashabaranov/go-openai/issues) before creating one.
Please search on the [issue tracker](https://github.com/lookfirst-io/go-openai/issues) before creating one.

**Describe the bug**
A clear and concise description of what the bug is. If it's an API-related bug, please provide relevant endpoint(s).
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ assignees: ''
---

Your issue may already be reported!
Please search on the [issue tracker](https://github.com/sashabaranov/go-openai/issues) before creating one.
Please search on the [issue tracker](https://github.com/lookfirst-io/go-openai/issues) before creating one.

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Expand Down
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
A similar PR may already be submitted!
Please search among the [Pull request](https://github.com/sashabaranov/go-openai/pulls) before creating one.
Please search among the [Pull request](https://github.com/lookfirst-io/go-openai/pulls) before creating one.

If your changes introduce breaking changes, please prefix the title of your pull request with "[BREAKING_CHANGES]". This allows for clear identification of such changes in the 'What's Changed' section on the release page, making it developer-friendly.

Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Contributing Guidelines

## Overview
Thank you for your interest in contributing to the "Go OpenAI" project! By following this guideline, we hope to ensure that your contributions are made smoothly and efficiently. The Go OpenAI project is licensed under the [Apache 2.0 License](https://github.com/sashabaranov/go-openai/blob/master/LICENSE), and we welcome contributions through GitHub pull requests.
Thank you for your interest in contributing to the "Go OpenAI" project! By following this guideline, we hope to ensure that your contributions are made smoothly and efficiently. The Go OpenAI project is licensed under the [Apache 2.0 License](https://github.com/lookfirst-io/go-openai/blob/master/LICENSE), and we welcome contributions through GitHub pull requests.

## Reporting Bugs
If you discover a bug, first check the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to see if the issue has already been reported. If you're reporting a new issue, please use the "Bug report" template and provide detailed information about the problem, including steps to reproduce it.
If you discover a bug, first check the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to see if the issue has already been reported. If you're reporting a new issue, please use the "Bug report" template and provide detailed information about the problem, including steps to reproduce it.

## Suggesting Features
If you want to suggest a new feature or improvement, first check the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to ensure a similar suggestion hasn't already been made. Use the "Feature request" template to provide a detailed description of your suggestion.
If you want to suggest a new feature or improvement, first check the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to ensure a similar suggestion hasn't already been made. Use the "Feature request" template to provide a detailed description of your suggestion.

## Reporting Vulnerabilities
If you identify a security concern, please use the "Report a security vulnerability" template on the [GitHub Issues page](https://github.com/sashabaranov/go-openai/issues) to share the details. This report will only be viewable to repository maintainers. You will be credited if the advisory is published.
If you identify a security concern, please use the "Report a security vulnerability" template on the [GitHub Issues page](https://github.com/lookfirst-io/go-openai/issues) to share the details. This report will only be viewable to repository maintainers. You will be credited if the advisory is published.

## Questions for Users
If you have questions, please utilize [StackOverflow](https://stackoverflow.com/) or the [GitHub Discussions page](https://github.com/sashabaranov/go-openai/discussions).
If you have questions, please utilize [StackOverflow](https://stackoverflow.com/) or the [GitHub Discussions page](https://github.com/lookfirst-io/go-openai/discussions).

## Contributing Code
There might already be a similar pull requests submitted! Please search for [pull requests](https://github.com/sashabaranov/go-openai/pulls) before creating one.
There might already be a similar pull requests submitted! Please search for [pull requests](https://github.com/lookfirst-io/go-openai/pulls) before creating one.

### Requirements for Merging a Pull Request

Expand Down
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Go OpenAI
[![Go Reference](https://pkg.go.dev/badge/github.com/sashabaranov/go-openai.svg)](https://pkg.go.dev/github.com/sashabaranov/go-openai)
[![Go Report Card](https://goreportcard.com/badge/github.com/sashabaranov/go-openai)](https://goreportcard.com/report/github.com/sashabaranov/go-openai)
[![codecov](https://codecov.io/gh/sashabaranov/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/sashabaranov/go-openai)
[![Go Reference](https://pkg.go.dev/badge/github.com/lookfirst-io/go-openai.svg)](https://pkg.go.dev/github.com/lookfirst-io/go-openai)
[![Go Report Card](https://goreportcard.com/badge/github.com/lookfirst-io/go-openai)](https://goreportcard.com/report/github.com/lookfirst-io/go-openai)
[![codecov](https://codecov.io/gh/lookfirst-io/go-openai/branch/master/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/lookfirst-io/go-openai)

This library provides unofficial Go clients for [OpenAI API](https://platform.openai.com/). We support:

Expand All @@ -13,7 +13,7 @@ This library provides unofficial Go clients for [OpenAI API](https://platform.op
## Installation

```
go get github.com/sashabaranov/go-openai
go get github.com/lookfirst-io/go-openai
```
Currently, go-openai requires Go version 1.18 or greater.

Expand All @@ -28,7 +28,7 @@ package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -80,7 +80,7 @@ import (
"errors"
"fmt"
"io"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -133,7 +133,7 @@ package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -166,7 +166,7 @@ import (
"context"
"fmt"
"io"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -215,7 +215,7 @@ import (
"context"
"fmt"

openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -247,7 +247,7 @@ import (
"fmt"
"os"

openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -288,7 +288,7 @@ import (
"context"
"encoding/base64"
"fmt"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
"image/png"
"os"
)
Expand Down Expand Up @@ -436,7 +436,7 @@ config.HTTPClient = &http.Client{
c := openai.NewClientWithConfig(config)
```

See also: https://pkg.go.dev/github.com/sashabaranov/go-openai#ClientConfig
See also: https://pkg.go.dev/github.com/lookfirst-io/go-openai#ClientConfig
</details>

<details>
Expand All @@ -452,7 +452,7 @@ import (
"os"
"strings"

"github.com/sashabaranov/go-openai"
"github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -506,7 +506,7 @@ import (
"context"
"fmt"

openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -552,7 +552,7 @@ package main
import (
"context"
"log"
openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"

)

Expand Down Expand Up @@ -609,7 +609,7 @@ import (
"context"
"fmt"

openai "github.com/sashabaranov/go-openai"
openai "github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -740,7 +740,7 @@ package main
import (
"context"
"fmt"
"github.com/sashabaranov/go-openai"
"github.com/lookfirst-io/go-openai"
)

func main() {
Expand Down Expand Up @@ -888,7 +888,7 @@ Due to the factors mentioned above, different answers may be returned even for t
By adopting these strategies, you can expect more consistent results.

**Related Issues:**
[omitempty option of request struct will generate incorrect request when parameter is 0.](https://github.com/sashabaranov/go-openai/issues/9)
[omitempty option of request struct will generate incorrect request when parameter is 0.](https://github.com/lookfirst-io/go-openai/issues/9)

### Does Go OpenAI provide a method to count tokens?

Expand All @@ -899,15 +899,15 @@ For counting tokens, you might find the following links helpful:
- [How to count tokens with tiktoken](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb)

**Related Issues:**
[Is it possible to join the implementation of GPT3 Tokenizer](https://github.com/sashabaranov/go-openai/issues/62)
[Is it possible to join the implementation of GPT3 Tokenizer](https://github.com/lookfirst-io/go-openai/issues/62)

## Contributing

By following [Contributing Guidelines](https://github.com/sashabaranov/go-openai/blob/master/CONTRIBUTING.md), we hope to ensure that your contributions are made smoothly and efficiently.
By following [Contributing Guidelines](https://github.com/lookfirst-io/go-openai/blob/master/CONTRIBUTING.md), we hope to ensure that your contributions are made smoothly and efficiently.

## Thank you

We want to take a moment to express our deepest gratitude to the [contributors](https://github.com/sashabaranov/go-openai/graphs/contributors) and sponsors of this project:
We want to take a moment to express our deepest gratitude to the [contributors](https://github.com/lookfirst-io/go-openai/graphs/contributors) and sponsors of this project:
- [Carson Kahn](https://carsonkahn.com) of [Spindle AI](https://spindleai.com)

To all of you: thank you. You've helped us achieve more than we ever imagined possible. Can't wait to see where we go next, together!
6 changes: 3 additions & 3 deletions api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"os"
"testing"

"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/sashabaranov/go-openai/jsonschema"
"github.com/lookfirst-io/go-openai"
"github.com/lookfirst-io/go-openai/internal/test/checks"
"github.com/lookfirst-io/go-openai/jsonschema"
)

func TestAPI(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions assistant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package openai_test
import (
"context"

openai "github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
openai "github.com/lookfirst-io/go-openai"
"github.com/lookfirst-io/go-openai/internal/test/checks"

"encoding/json"
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"os"

utils "github.com/sashabaranov/go-openai/internal"
utils "github.com/lookfirst-io/go-openai/internal"
)

// Whisper Defines the models provided by OpenAI to use when processing audio with OpenAI.
Expand Down
6 changes: 3 additions & 3 deletions audio_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"strings"
"testing"

"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/lookfirst-io/go-openai"
"github.com/lookfirst-io/go-openai/internal/test"
"github.com/lookfirst-io/go-openai/internal/test/checks"
)

// TestAudio Tests the transcription and translation endpoints of the API using the mocked server.
Expand Down
34 changes: 34 additions & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"errors"
"net/http"

"github.com/sashabaranov/go-openai/jsonschema"

Check failure on line 9 in chat.go

View workflow job for this annotation

GitHub Actions / Sanity check

no required module provides package github.com/sashabaranov/go-openai/jsonschema; to add it:
)

// Chat message role defined by the OpenAI API.
Expand Down Expand Up @@ -262,6 +262,9 @@
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
MinP float32 `json:"min_p,omitempty"`
TopK int32 `json:"top_k,omitempty"`
RepetitionPenalty float64 `json:"repetition_penalty,omitempty"`
N int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
Stop []string `json:"stop,omitempty"`
Expand Down Expand Up @@ -309,6 +312,35 @@
ChatTemplateKwargs map[string]any `json:"chat_template_kwargs,omitempty"`
// Specifies the latency tier to use for processing the request.
ServiceTier ServiceTier `json:"service_tier,omitempty"`

Provider *PostOpenrouterProviderRequest `json:"provider,omitempty"`

IncludeReasoning bool `json:"include_reasoning,omitempty"` // Whether to include reasoning in the response for OpenRouter
Reasoning *PostOpenrouterReasoningRequest `json:"reasoning,omitempty"`
}

type PostOpenrouterProviderRequest struct {
Sort string `json:"sort,omitempty"` // Sort providers by price or throughput. (e.g. "price" or "throughput")
Quantizations []string `json:"quantizations,omitempty"` // List of quantization levels to filter by (e.g. ["int4", "int8"])
Ignore []string `json:"ignore,omitempty"` // List of provider names to skip for this request.
DataCollection string `json:"data_collection,omitempty"` // Control whether to use providers that may store data. "deny" or "allow"
RequireParameters bool `json:"require_parameters,omitempty"` // Only use providers that support all parameters in your request.
AllowFallbacks bool `json:"allow_fallbacks,omitempty"` // Whether to allow backup providers when the primary is unavailable.
Order []string `json:"order,omitempty"` // List of provider names to try in order
Only []string `json:"only,omitempty"` // List of provider slugs to allow for this request.
}

// context : https://openrouter.ai/docs/use-cases/reasoning-tokens
type PostOpenrouterReasoningRequest struct {
// One of the following (not both):
Effort string `json:"effort,omitempty"` // Can be "high", "medium", or "low" (OpenAI-style)
MaxTokens int `json:"max_tokens,omitempty"` // Specific token limit (Anthropic-style)

// Optional: Default is false. All models support this.
Exclude bool `json:"exclude"` // // Set to true to exclude reasoning tokens from response

// Or enable reasoning with the default parameters:
Enabled bool `json:"enabled"` // Default: inferred from `effort` or `max_tokens`
}

type StreamOptions struct {
Expand Down Expand Up @@ -435,6 +467,8 @@
PromptFilterResults []PromptFilterResult `json:"prompt_filter_results,omitempty"`
ServiceTier ServiceTier `json:"service_tier,omitempty"`

Provider string `json:"provider"`

httpHeader
}

Expand Down
2 changes: 2 additions & 0 deletions chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type ChatCompletionStreamResponse struct {
// When present, it contains a null value except for the last chunk which contains the token usage statistics
// for the entire request.
Usage *Usage `json:"usage,omitempty"`

Provider string `json:"provider"`
}

// ChatCompletionStream
Expand Down
4 changes: 2 additions & 2 deletions chat_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strconv"
"testing"

"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/lookfirst-io/go-openai"
"github.com/lookfirst-io/go-openai/internal/test/checks"
)

func TestChatCompletionsStreamWrongModel(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"testing"
"time"

"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/sashabaranov/go-openai/jsonschema"
"github.com/lookfirst-io/go-openai"
"github.com/lookfirst-io/go-openai/internal/test/checks"
"github.com/lookfirst-io/go-openai/jsonschema"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/url"
"strings"

utils "github.com/sashabaranov/go-openai/internal"
utils "github.com/lookfirst-io/go-openai/internal"
)

// Client is OpenAI GPT-3 API client.
Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"reflect"
"testing"

"github.com/sashabaranov/go-openai/internal/test"
"github.com/sashabaranov/go-openai/internal/test/checks"
"github.com/lookfirst-io/go-openai/internal/test"
"github.com/lookfirst-io/go-openai/internal/test/checks"
)

var errTestRequestBuilderFailed = errors.New("test request builder failed")
Expand Down
Loading
Loading