Skip to content

Commit

Permalink
modify url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
devinyf committed Feb 25, 2024
1 parent b0f65c8 commit f80440b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateCompletion(ctx, req, qwen.URLQwen())
resp, err := cli.CreateCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateVLCompletion(ctx, req, qwen.URLQwenVL())
resp, err := cli.CreateVLCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateAudioCompletion(ctx, req, qwen.URLQwenAudio())
resp, err := cli.CreateAudioCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example/qwen/stream_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateCompletion(ctx, req, qwen.URLQwen())
resp, err := cli.CreateCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example/qwen_audio/stream_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateAudioCompletion(ctx, req, qwen.URLQwenAudio())
resp, err := cli.CreateAudioCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion example/qwen_vl/stream_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
}

ctx := context.TODO()
resp, err := cli.CreateVLCompletion(ctx, req, qwen.URLQwenVL())
resp, err := cli.CreateVLCompletion(ctx, req)
if err != nil {
panic(err)
}
Expand Down
12 changes: 6 additions & 6 deletions tongyiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func newTongyiCLientWithHTTPCli(model string, token string, httpcli httpclient.I
// maybe this can be change in the future.
//
// nolint:lll
func (q *TongyiClient) CreateCompletion(ctx context.Context, payload *qwen.Request[*qwen.TextContent], url string) (*TextQwenResponse, error) {
func (q *TongyiClient) CreateCompletion(ctx context.Context, payload *qwen.Request[*qwen.TextContent]) (*TextQwenResponse, error) {
payload = paylosdPreCheck(q, payload)
return genericCompletion(ctx, payload, q.httpCli, url, q.token)
return genericCompletion(ctx, payload, q.httpCli, qwen.URLQwen(), q.token)
}

//nolint:lll
func (q *TongyiClient) CreateVLCompletion(ctx context.Context, payload *qwen.Request[*qwen.VLContentList], url string) (*VLQwenResponse, error) {
func (q *TongyiClient) CreateVLCompletion(ctx context.Context, payload *qwen.Request[*qwen.VLContentList]) (*VLQwenResponse, error) {
payload = paylosdPreCheck(q, payload)

for _, vMsg := range payload.Input.Messages {
Expand All @@ -61,11 +61,11 @@ func (q *TongyiClient) CreateVLCompletion(ctx context.Context, payload *qwen.Req
}
}

return genericCompletion(ctx, payload, q.httpCli, url, q.token)
return genericCompletion(ctx, payload, q.httpCli, qwen.URLQwenVL(), q.token)
}

//nolint:lll
func (q *TongyiClient) CreateAudioCompletion(ctx context.Context, payload *qwen.Request[*qwen.AudioContentList], url string) (*AudioQwenResponse, error) {
func (q *TongyiClient) CreateAudioCompletion(ctx context.Context, payload *qwen.Request[*qwen.AudioContentList]) (*AudioQwenResponse, error) {
payload = paylosdPreCheck(q, payload)
for _, acMsg := range payload.Input.Messages {
tmpAudioContent, hasAudio := acMsg.Content.PopAudioContent()
Expand All @@ -85,7 +85,7 @@ func (q *TongyiClient) CreateAudioCompletion(ctx context.Context, payload *qwen.
}
}

return genericCompletion(ctx, payload, q.httpCli, url, q.token)
return genericCompletion(ctx, payload, q.httpCli, qwen.URLQwenVL(), q.token)
}

func checkIfNeedUploadFile(ctx context.Context, filepath string, model, token string) (string, bool, error) {
Expand Down
15 changes: 7 additions & 8 deletions tongyiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestBasic(t *testing.T) {
Input: input,
}

resp, err := cli.CreateCompletion(ctx, req, qwen.URLQwen())
resp, err := cli.CreateCompletion(ctx, req)

require.NoError(t, err)
assert.Regexp(t, "hello|hi|how|assist", resp.Output.Choices[0].Message.Content.ToString())
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestStreamingChunk(t *testing.T) {
Input: input,
StreamingFn: streamCallbackFn,
}
resp, err := cli.CreateCompletion(ctx, req, qwen.URLQwen())
resp, err := cli.CreateCompletion(ctx, req)

require.NoError(t, err)
assert.Regexp(t, "hello|hi|how|assist", resp.Output.Choices[0].Message.Content.ToString())
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestVLBasic(t *testing.T) {

req.Parameters = qwen.DefaultParameters()

resp, err := cli.CreateVLCompletion(ctx, req, qwen.URLQwenVL())
resp, err := cli.CreateVLCompletion(ctx, req)

require.NoError(t, err)
assert.Regexp(t, "dog|person|individual|woman|girl", resp.Output.Choices[0].Message.Content.ToString())
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestVLStreamChund(t *testing.T) {
StreamingFn: streamCallbackFn,
}

resp, err := cli.CreateVLCompletion(ctx, req, qwen.URLQwenVL())
resp, err := cli.CreateVLCompletion(ctx, req)

require.NoError(t, err)
assert.Equal(t, output, resp.Output.Choices[0].Message.Content.ToString())
Expand Down Expand Up @@ -231,8 +231,8 @@ func TestMockStreamingChunk(t *testing.T) {
},
}

mockURL := ""
resp, err := cli.CreateCompletion(ctx, req, mockURL)
// mockURL := ""
resp, err := cli.CreateCompletion(ctx, req)

require.NoError(t, err)

Expand All @@ -257,8 +257,7 @@ func TestMockBasic(t *testing.T) {
Input: input,
}

mockURL := ""
resp, err := cli.CreateCompletion(ctx, req, mockURL)
resp, err := cli.CreateCompletion(ctx, req)

require.NoError(t, err)

Expand Down

0 comments on commit f80440b

Please sign in to comment.