Skip to content

Commit a20547c

Browse files
authored
Add deepseek support, update Go to 1.23.5 (#3659)
Signed-off-by: yaron2 <[email protected]>
1 parent 2e4fc0b commit a20547c

File tree

8 files changed

+168
-8
lines changed

8 files changed

+168
-8
lines changed

.build-tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/dapr/components-contrib/build-tools
22

3-
go 1.23.0
3+
go 1.23.5
44

55
require (
66
github.com/dapr/components-contrib v0.0.0

conversation/deepseek/deepseek.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Copyright 2025 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package deepseek
17+
18+
import (
19+
"context"
20+
"reflect"
21+
22+
"github.com/dapr/components-contrib/conversation"
23+
"github.com/dapr/components-contrib/metadata"
24+
"github.com/dapr/kit/logger"
25+
kmeta "github.com/dapr/kit/metadata"
26+
27+
deepseek_go "github.com/cohesion-org/deepseek-go"
28+
)
29+
30+
type Deepseek struct {
31+
llm *deepseek_go.Client
32+
md DeepseekMetadata
33+
34+
logger logger.Logger
35+
}
36+
37+
func NewDeepseek(logger logger.Logger) conversation.Conversation {
38+
o := &Deepseek{
39+
logger: logger,
40+
}
41+
42+
return o
43+
}
44+
45+
func (d *Deepseek) Init(ctx context.Context, meta conversation.Metadata) error {
46+
md := DeepseekMetadata{}
47+
err := kmeta.DecodeMetadata(meta.Properties, &md)
48+
if err != nil {
49+
return err
50+
}
51+
52+
d.llm = deepseek_go.NewClient(md.Key)
53+
d.md = md
54+
return nil
55+
}
56+
57+
func (d *Deepseek) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
58+
metadataStruct := DeepseekMetadata{}
59+
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.ConversationType)
60+
return
61+
}
62+
63+
func (d *Deepseek) Converse(ctx context.Context, r *conversation.ConversationRequest) (res *conversation.ConversationResponse, err error) {
64+
messages := make([]deepseek_go.ChatCompletionMessage, 0, len(r.Inputs))
65+
66+
for _, input := range r.Inputs {
67+
messages = append(messages, deepseek_go.ChatCompletionMessage{
68+
Role: string(input.Role),
69+
Content: input.Message,
70+
})
71+
}
72+
73+
request := &deepseek_go.ChatCompletionRequest{
74+
Model: deepseek_go.DeepSeekChat,
75+
Messages: messages,
76+
}
77+
78+
if d.md.MaxTokens > 0 {
79+
request.MaxTokens = d.md.MaxTokens
80+
}
81+
82+
if r.Temperature > 0 {
83+
request.Temperature = float32(r.Temperature)
84+
}
85+
86+
resp, err := d.llm.CreateChatCompletion(ctx, request)
87+
if err != nil {
88+
return nil, err
89+
}
90+
91+
outputs := make([]conversation.ConversationResult, 0, len(resp.Choices))
92+
93+
for i := range resp.Choices {
94+
outputs = append(outputs, conversation.ConversationResult{
95+
Result: resp.Choices[i].Message.Content,
96+
Parameters: r.Parameters,
97+
})
98+
}
99+
100+
res = &conversation.ConversationResponse{
101+
Outputs: outputs,
102+
}
103+
104+
return res, nil
105+
}
106+
107+
func (d *Deepseek) Close() error {
108+
return nil
109+
}

conversation/deepseek/metadata.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2025 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
// DeepseekMetadata is a common metadata structure for langchain supported implementations.
17+
18+
package deepseek
19+
20+
type DeepseekMetadata struct {
21+
Key string `json:"key"`
22+
MaxTokens int `json:"maxTokens"`
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# yaml-language-server: $schema=../../../component-metadata-schema.json
2+
schemaVersion: v1
3+
type: conversation
4+
name: deepseek
5+
version: v1
6+
status: alpha
7+
title: "Deepseek"
8+
urls:
9+
- title: Reference
10+
url: https://docs.dapr.io/reference/components-reference/supported-conversation/setup-deepseek/
11+
authenticationProfiles:
12+
- title: "API Key"
13+
description: "Authenticate using an API key"
14+
metadata:
15+
- name: key
16+
type: string
17+
required: true
18+
sensitive: true
19+
description: |
20+
API key for Deepseek.
21+
example: "**********"
22+
default: ""
23+
metadata:
24+
- name: maxTokens
25+
required: false
26+
description: |
27+
Max tokens for each request
28+
type: int
29+
example: 2048

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/dapr/components-contrib
22

3-
go 1.23.0
3+
go 1.23.5
44

55
require (
66
cloud.google.com/go/datastore v1.15.0
@@ -56,6 +56,7 @@ require (
5656
github.com/cloudevents/sdk-go/v2 v2.15.2
5757
github.com/cloudwego/kitex v0.5.0
5858
github.com/cloudwego/kitex-examples v0.1.1
59+
github.com/cohesion-org/deepseek-go v1.1.0
5960
github.com/cyphar/filepath-securejoin v0.2.4
6061
github.com/dancannon/gorethink v4.0.0+incompatible
6162
github.com/dapr/kit v0.13.1-0.20240909215017-3823663aa4bb

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
443443
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
444444
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
445445
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
446+
github.com/cohesion-org/deepseek-go v1.1.0 h1:ejgX+KWSPZg05qV5YJ22TRygElCmHzZoxJtvLN5DNaY=
447+
github.com/cohesion-org/deepseek-go v1.1.0/go.mod h1:je2+GYTRsFGimyZNP4hpAcARQ7dcMaidT5YisexH0w0=
446448
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
447449
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
448450
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=

tests/certification/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/dapr/components-contrib/tests/certification
22

3-
go 1.23.0
4-
5-
toolchain go1.23.1
3+
go 1.23.5
64

75
require (
86
cloud.google.com/go/pubsub v1.37.0

tests/e2e/pubsub/jetstream/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/dapr/components-contrib/tests/e2e/pubsub/jetstream
22

3-
go 1.23.0
4-
5-
toolchain go1.23.1
3+
go 1.23.5
64

75
require (
86
github.com/dapr/components-contrib v1.10.6-0.20230403162214-9ee9d56cb7ea

0 commit comments

Comments
 (0)