-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fully moved streaming to streams package
- Loading branch information
1 parent
9a4016f
commit a6ec956
Showing
10 changed files
with
132 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,65 @@ | ||
package groq_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/conneroisu/groq-go" | ||
"github.com/conneroisu/groq-go/pkg/models" | ||
"github.com/conneroisu/groq-go/pkg/test" | ||
"github.com/conneroisu/groq-go/pkg/tools" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestChat(t *testing.T) { | ||
groq.NewClient("dfasf") | ||
ctx := context.Background() | ||
a := assert.New(t) | ||
ts := test.NewTestServer() | ||
returnObj := groq.ChatCompletionResponse{ | ||
ID: "chatcmpl-123", | ||
Object: "chat.completion.chunk", | ||
Created: 1693721698, | ||
Model: "llama3-groq-70b-8192-tool-use-preview", | ||
Choices: []groq.ChatCompletionChoice{ | ||
{ | ||
Index: 0, | ||
Message: groq.ChatCompletionMessage{ | ||
Role: groq.ChatMessageRoleAssistant, | ||
Content: "Hello!", | ||
}, | ||
}, | ||
}, | ||
} | ||
ts.RegisterHandler("/v1/chat/completions", func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
jsval, err := json.Marshal(returnObj) | ||
a.NoError(err) | ||
_, err = w.Write(jsval) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
testS := ts.GroqTestServer() | ||
testS.Start() | ||
client, err := groq.NewClient( | ||
test.GetTestToken(), | ||
groq.WithBaseURL(testS.URL+"/v1"), | ||
) | ||
a.NoError(err) | ||
resp, err := client.CreateChatCompletion(ctx, groq.ChatCompletionRequest{ | ||
Model: models.ModelLlama3Groq70B8192ToolUsePreview, | ||
Messages: []groq.ChatCompletionMessage{ | ||
{ | ||
Role: groq.ChatMessageRoleUser, | ||
Content: "Hello!", | ||
}, | ||
}, | ||
MaxTokens: 2000, | ||
Tools: []tools.Tool{}, | ||
}) | ||
a.NoError(err) | ||
a.NotEmpty(resp.Choices[0].Message.Content) | ||
} |
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
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 @@ | ||
// Package moderation contains the types for content moderation. | ||
package moderation |
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