Add deepseek support, update Go to 1.23.5 (#3659)

Signed-off-by: yaron2 <schneider.yaron@live.com>
This commit is contained in:
Yaron Schneider 2025-01-29 13:41:28 -08:00 committed by GitHub
parent 2e4fc0bbd9
commit a20547c324
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 168 additions and 8 deletions

View File

@ -1,6 +1,6 @@
module github.com/dapr/components-contrib/build-tools
go 1.23.0
go 1.23.5
require (
github.com/dapr/components-contrib v0.0.0

View File

@ -0,0 +1,109 @@
/*
Copyright 2025 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package deepseek
import (
"context"
"reflect"
"github.com/dapr/components-contrib/conversation"
"github.com/dapr/components-contrib/metadata"
"github.com/dapr/kit/logger"
kmeta "github.com/dapr/kit/metadata"
deepseek_go "github.com/cohesion-org/deepseek-go"
)
type Deepseek struct {
llm *deepseek_go.Client
md DeepseekMetadata
logger logger.Logger
}
func NewDeepseek(logger logger.Logger) conversation.Conversation {
o := &Deepseek{
logger: logger,
}
return o
}
func (d *Deepseek) Init(ctx context.Context, meta conversation.Metadata) error {
md := DeepseekMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &md)
if err != nil {
return err
}
d.llm = deepseek_go.NewClient(md.Key)
d.md = md
return nil
}
func (d *Deepseek) GetComponentMetadata() (metadataInfo metadata.MetadataMap) {
metadataStruct := DeepseekMetadata{}
metadata.GetMetadataInfoFromStructType(reflect.TypeOf(metadataStruct), &metadataInfo, metadata.ConversationType)
return
}
func (d *Deepseek) Converse(ctx context.Context, r *conversation.ConversationRequest) (res *conversation.ConversationResponse, err error) {
messages := make([]deepseek_go.ChatCompletionMessage, 0, len(r.Inputs))
for _, input := range r.Inputs {
messages = append(messages, deepseek_go.ChatCompletionMessage{
Role: string(input.Role),
Content: input.Message,
})
}
request := &deepseek_go.ChatCompletionRequest{
Model: deepseek_go.DeepSeekChat,
Messages: messages,
}
if d.md.MaxTokens > 0 {
request.MaxTokens = d.md.MaxTokens
}
if r.Temperature > 0 {
request.Temperature = float32(r.Temperature)
}
resp, err := d.llm.CreateChatCompletion(ctx, request)
if err != nil {
return nil, err
}
outputs := make([]conversation.ConversationResult, 0, len(resp.Choices))
for i := range resp.Choices {
outputs = append(outputs, conversation.ConversationResult{
Result: resp.Choices[i].Message.Content,
Parameters: r.Parameters,
})
}
res = &conversation.ConversationResponse{
Outputs: outputs,
}
return res, nil
}
func (d *Deepseek) Close() error {
return nil
}

View File

@ -0,0 +1,23 @@
/*
Copyright 2025 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// DeepseekMetadata is a common metadata structure for langchain supported implementations.
package deepseek
type DeepseekMetadata struct {
Key string `json:"key"`
MaxTokens int `json:"maxTokens"`
}

View File

@ -0,0 +1,29 @@
# yaml-language-server: $schema=../../../component-metadata-schema.json
schemaVersion: v1
type: conversation
name: deepseek
version: v1
status: alpha
title: "Deepseek"
urls:
- title: Reference
url: https://docs.dapr.io/reference/components-reference/supported-conversation/setup-deepseek/
authenticationProfiles:
- title: "API Key"
description: "Authenticate using an API key"
metadata:
- name: key
type: string
required: true
sensitive: true
description: |
API key for Deepseek.
example: "**********"
default: ""
metadata:
- name: maxTokens
required: false
description: |
Max tokens for each request
type: int
example: 2048

3
go.mod
View File

@ -1,6 +1,6 @@
module github.com/dapr/components-contrib
go 1.23.0
go 1.23.5
require (
cloud.google.com/go/datastore v1.15.0
@ -56,6 +56,7 @@ require (
github.com/cloudevents/sdk-go/v2 v2.15.2
github.com/cloudwego/kitex v0.5.0
github.com/cloudwego/kitex-examples v0.1.1
github.com/cohesion-org/deepseek-go v1.1.0
github.com/cyphar/filepath-securejoin v0.2.4
github.com/dancannon/gorethink v4.0.0+incompatible
github.com/dapr/kit v0.13.1-0.20240909215017-3823663aa4bb

2
go.sum
View File

@ -443,6 +443,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/cohesion-org/deepseek-go v1.1.0 h1:ejgX+KWSPZg05qV5YJ22TRygElCmHzZoxJtvLN5DNaY=
github.com/cohesion-org/deepseek-go v1.1.0/go.mod h1:je2+GYTRsFGimyZNP4hpAcARQ7dcMaidT5YisexH0w0=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=

View File

@ -1,8 +1,6 @@
module github.com/dapr/components-contrib/tests/certification
go 1.23.0
toolchain go1.23.1
go 1.23.5
require (
cloud.google.com/go/pubsub v1.37.0

View File

@ -1,8 +1,6 @@
module github.com/dapr/components-contrib/tests/e2e/pubsub/jetstream
go 1.23.0
toolchain go1.23.1
go 1.23.5
require (
github.com/dapr/components-contrib v1.10.6-0.20230403162214-9ee9d56cb7ea