From f80440bf11ad782242ac2a3e3cc00101050cb0da Mon Sep 17 00:00:00 2001 From: "devin.yf" Date: Sun, 25 Feb 2024 11:16:29 +0800 Subject: [PATCH] modify url parameter --- README.md | 6 +++--- example/qwen/stream_call.go | 2 +- example/qwen_audio/stream_call.go | 2 +- example/qwen_vl/stream_call.go | 2 +- tongyiclient.go | 12 ++++++------ tongyiclient_test.go | 15 +++++++-------- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b2d4416..c0800d6 100644 --- a/README.md +++ b/README.md @@ -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) } @@ -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) } @@ -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) } diff --git a/example/qwen/stream_call.go b/example/qwen/stream_call.go index bc0f8eb..db548ce 100644 --- a/example/qwen/stream_call.go +++ b/example/qwen/stream_call.go @@ -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) } diff --git a/example/qwen_audio/stream_call.go b/example/qwen_audio/stream_call.go index 28a29c8..1668216 100644 --- a/example/qwen_audio/stream_call.go +++ b/example/qwen_audio/stream_call.go @@ -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) } diff --git a/example/qwen_vl/stream_call.go b/example/qwen_vl/stream_call.go index 81a4625..f9cf5e8 100644 --- a/example/qwen_vl/stream_call.go +++ b/example/qwen_vl/stream_call.go @@ -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) } diff --git a/tongyiclient.go b/tongyiclient.go index 1920981..6d72448 100644 --- a/tongyiclient.go +++ b/tongyiclient.go @@ -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 { @@ -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() @@ -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) { diff --git a/tongyiclient_test.go b/tongyiclient_test.go index 65045ed..0369ee3 100644 --- a/tongyiclient_test.go +++ b/tongyiclient_test.go @@ -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()) @@ -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()) @@ -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()) @@ -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()) @@ -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) @@ -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)