-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#60: reduce complexity of toModel func and lint
- Loading branch information
1 parent
63272b0
commit 6d78447
Showing
9 changed files
with
277 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package anthropic | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"glide/pkg/providers/clients" | ||
|
||
"glide/pkg/api/schemas" | ||
|
||
"glide/pkg/telemetry" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOpenAIClient_ChatRequest(t *testing.T) { | ||
// Anthropic Messages API: https://docs.anthropic.com/claude/reference/messages_post | ||
AnthropicMock := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
rawPayload, _ := io.ReadAll(r.Body) | ||
|
||
var data interface{} | ||
// Parse the JSON body | ||
err := json.Unmarshal(rawPayload, &data) | ||
if err != nil { | ||
t.Errorf("error decoding payload (%q): %v", string(rawPayload), err) | ||
} | ||
|
||
chatResponse, err := os.ReadFile(filepath.Clean("./testdata/chat.success.json")) | ||
if err != nil { | ||
t.Errorf("error reading openai chat mock response: %v", err) | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
_, err = w.Write(chatResponse) | ||
|
||
if err != nil { | ||
t.Errorf("error on sending chat response: %v", err) | ||
} | ||
}) | ||
|
||
AnthropicServer := httptest.NewServer(AnthropicMock) | ||
defer AnthropicServer.Close() | ||
|
||
ctx := context.Background() | ||
providerCfg := DefaultConfig() | ||
clientCfg := clients.DefaultClientConfig() | ||
|
||
providerCfg.BaseURL = AnthropicServer.URL | ||
|
||
client, err := NewClient(providerCfg, clientCfg, telemetry.NewTelemetryMock()) | ||
require.NoError(t, err) | ||
|
||
request := schemas.UnifiedChatRequest{Message: schemas.ChatMessage{ | ||
Role: "human", | ||
Content: "What's the biggest animal?", | ||
}} | ||
|
||
response, err := client.Chat(ctx, &request) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "msg_013Zva2CMHLNnXjNJJKqJ2EF", response.ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"model": "claude-instant-1.2", | ||
"messages": [ | ||
{ | ||
"role": "human", | ||
"content": "What's the biggest animal?" | ||
} | ||
], | ||
"temperature": 1, | ||
"top_p": 0, | ||
"max_tokens": 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF", | ||
"type": "message", | ||
"model": "claude-2.1", | ||
"role": "assistant", | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "Blue is often seen as a calming and soothing color." | ||
} | ||
], | ||
"stop_reason": "end_turn", | ||
"stop_sequence": null | ||
} |
Oops, something went wrong.