Skip to content

Commit

Permalink
#67: Moved resiliency and client packages on higher level out of prov…
Browse files Browse the repository at this point in the history
…iders & routers
  • Loading branch information
roma-glushko committed Jun 24, 2024
1 parent b861ffa commit 27347ec
Show file tree
Hide file tree
Showing 64 changed files with 106 additions and 137 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions pkg/providers/anthropic/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"time"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/api/schemas"
"go.uber.org/zap"
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/providers/anthropic/chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package anthropic

import (
"context"

"github.com/EinStack/glide/pkg/providers/clients"
clients2 "github.com/EinStack/glide/pkg/clients"

"github.com/EinStack/glide/pkg/api/schemas"
)
Expand All @@ -12,6 +11,6 @@ func (c *Client) SupportChatStream() bool {
return false
}

func (c *Client) ChatStream(_ context.Context, _ *schemas.ChatParams) (clients.ChatStream, error) {
return nil, clients.ErrChatStreamNotImplemented
func (c *Client) ChatStream(_ context.Context, _ *schemas.ChatParams) (clients2.ChatStream, error) {
return nil, clients2.ErrChatStreamNotImplemented
}
3 changes: 1 addition & 2 deletions pkg/providers/anthropic/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package anthropic

import (
"github.com/EinStack/glide/pkg/clients"
"net/http"
"net/url"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/anthropic/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package anthropic
import (
"context"
"encoding/json"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/api/schemas"

"github.com/EinStack/glide/pkg/telemetry"
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/anthropic/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package anthropic

import (
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
"go.uber.org/zap"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/azureopenai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/providers/openai"

"github.com/EinStack/glide/pkg/api/schemas"
Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/azureopenai/chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"encoding/json"
"fmt"
clients2 "github.com/EinStack/glide/pkg/clients"
"io"
"net/http"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/openai"

"github.com/EinStack/glide/pkg/providers/clients"
"github.com/r3labs/sse/v2"

"go.uber.org/zap"
Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *ChatStream) Recv() (*schemas.ChatStreamChunk, error) {
// if err is io.EOF, this still means that the stream is interrupted unexpectedly
// because the normal stream termination is done via finding out streamDoneMarker

return nil, clients.ErrProviderUnavailable
return nil, clients2.ErrProviderUnavailable
}

s.tel.L().Debug(
Expand All @@ -91,7 +91,7 @@ func (s *ChatStream) Recv() (*schemas.ChatStreamChunk, error) {
zap.ByteString("rawChunk", rawEvent),
)

event, err := clients.ParseSSEvent(rawEvent)
event, err := clients2.ParseSSEvent(rawEvent)

if bytes.Equal(event.Data, openai.StreamDoneMarker) {
s.tel.L().Info(
Expand Down Expand Up @@ -155,7 +155,7 @@ func (c *Client) SupportChatStream() bool {
return true
}

func (c *Client) ChatStream(ctx context.Context, params *schemas.ChatParams) (clients.ChatStream, error) {
func (c *Client) ChatStream(ctx context.Context, params *schemas.ChatParams) (clients2.ChatStream, error) {
// Create a new chat request
httpRequest, err := c.makeStreamReq(ctx, params)
if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions pkg/providers/azureopenai/chat_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azureopenai
import (
"context"
"encoding/json"
clients2 "github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -14,14 +15,12 @@ import (

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/stretchr/testify/require"
)

func TestAzureOpenAIClient_ChatStreamSupported(t *testing.T) {
providerCfg := DefaultConfig()
clientCfg := clients.DefaultClientConfig()
clientCfg := clients2.DefaultClientConfig()

client, err := NewClient(providerCfg, clientCfg, telemetry.NewTelemetryMock())
require.NoError(t, err)
Expand Down Expand Up @@ -64,7 +63,7 @@ func TestAzureOpenAIClient_ChatStreamRequest(t *testing.T) {

ctx := context.Background()
providerCfg := DefaultConfig()
clientCfg := clients.DefaultClientConfig()
clientCfg := clients2.DefaultClientConfig()

providerCfg.BaseURL = AzureopenAIServer.URL

Expand Down Expand Up @@ -132,7 +131,7 @@ func TestAzureOpenAIClient_ChatStreamRequestInterrupted(t *testing.T) {

ctx := context.Background()
providerCfg := DefaultConfig()
clientCfg := clients.DefaultClientConfig()
clientCfg := clients2.DefaultClientConfig()

providerCfg.BaseURL = openAIServer.URL

Expand All @@ -153,7 +152,7 @@ func TestAzureOpenAIClient_ChatStreamRequestInterrupted(t *testing.T) {
for {
chunk, err := stream.Recv()
if err != nil {
require.ErrorIs(t, err, clients.ErrProviderUnavailable)
require.ErrorIs(t, err, clients2.ErrProviderUnavailable)
return
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/azureopenai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package azureopenai

import (
"fmt"
"github.com/EinStack/glide/pkg/clients"
"net/http"
"time"

"github.com/EinStack/glide/pkg/providers/openai"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/azureopenai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package azureopenai
import (
"context"
"encoding/json"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/api/schemas"

"github.com/EinStack/glide/pkg/telemetry"
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/azureopenai/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package azureopenai

import (
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
"go.uber.org/zap"
)

Expand Down
7 changes: 3 additions & 4 deletions pkg/providers/bedrock/chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package bedrock

import (
"context"

"github.com/EinStack/glide/pkg/providers/clients"
clients2 "github.com/EinStack/glide/pkg/clients"

"github.com/EinStack/glide/pkg/api/schemas"
)
Expand All @@ -12,6 +11,6 @@ func (c *Client) SupportChatStream() bool {
return false
}

func (c *Client) ChatStream(_ context.Context, _ *schemas.ChatParams) (clients.ChatStream, error) {
return nil, clients.ErrChatStreamNotImplemented
func (c *Client) ChatStream(_ context.Context, _ *schemas.ChatParams) (clients2.ChatStream, error) {
return nil, clients2.ErrChatStreamNotImplemented
}
3 changes: 1 addition & 2 deletions pkg/providers/bedrock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package bedrock
import (
"context"
"errors"
"github.com/EinStack/glide/pkg/clients"
"net/http"
"net/url"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/bedrockruntime"
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/bedrock/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/api/schemas"

"github.com/EinStack/glide/pkg/telemetry"
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/cohere/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"time"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/EinStack/glide/pkg/api/schemas"

"go.uber.org/zap"
Expand Down
7 changes: 3 additions & 4 deletions pkg/providers/cohere/chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"context"
"encoding/json"
"fmt"
clients2 "github.com/EinStack/glide/pkg/clients"
"io"
"net/http"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"

"go.uber.org/zap"

"github.com/EinStack/glide/pkg/api/schemas"
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *ChatStream) Recv() (*schemas.ChatStreamChunk, error) {

// if io.EOF occurred in the middle of the stream, then the stream was interrupted

return nil, clients.ErrProviderUnavailable
return nil, clients2.ErrProviderUnavailable
}

s.tel.L().Debug(
Expand Down Expand Up @@ -178,7 +177,7 @@ func (c *Client) SupportChatStream() bool {
return true
}

func (c *Client) ChatStream(ctx context.Context, params *schemas.ChatParams) (clients.ChatStream, error) {
func (c *Client) ChatStream(ctx context.Context, params *schemas.ChatParams) (clients2.ChatStream, error) {
// Create a new chat request
httpRequest, err := c.makeStreamReq(ctx, params)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/cohere/chat_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cohere
import (
"context"
"encoding/json"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -14,8 +15,6 @@ import (

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/stretchr/testify/require"
)

Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/cohere/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cohere

import (
"github.com/EinStack/glide/pkg/clients"
"net/http"
"net/url"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
)

const (
Expand Down
3 changes: 1 addition & 2 deletions pkg/providers/cohere/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cohere
import (
"context"
"encoding/json"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -15,8 +16,6 @@ import (

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"

"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/cohere/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package cohere

import (
"fmt"
"github.com/EinStack/glide/pkg/clients"
"io"
"net/http"
"time"

"github.com/EinStack/glide/pkg/telemetry"

"github.com/EinStack/glide/pkg/providers/clients"
"go.uber.org/zap"
)

Expand Down
Loading

0 comments on commit 27347ec

Please sign in to comment.