@@ -5,27 +5,34 @@ import (
55 "github.com/rainu/ask-mai/internal/config/model/common"
66 iAnthropic "github.com/rainu/ask-mai/internal/llms/anthropic"
77 llmCommon "github.com/rainu/ask-mai/internal/llms/common"
8+ "github.com/rainu/go-yacl"
89 "github.com/tmc/langchaingo/llms/anthropic"
910)
1011
1112type AnthropicConfig struct {
1213 Token common.Secret `yaml:"api-key,omitempty" usage:"API Key"`
1314 BaseUrl string `yaml:"base-url,omitempty" usage:"BaseUrl"`
1415 Model string `yaml:"model,omitempty" usage:"Model"`
16+
17+ Cache AnthropicCache `yaml:"disable-cache,omitempty" usage:"disable "`
1518}
1619
17- func (c * AnthropicConfig ) AsOptions () (opts []anthropic.Option ) {
18- if v := c .Token .GetOrPanicWithDefaultTimeout (); v != nil {
19- opts = append (opts , anthropic .WithToken (string (v )))
20+ type AnthropicCache struct {
21+ SystemMessage * bool `yaml:"system-message,omitempty" usage:"system message cache"`
22+ Tools * bool `yaml:"tools,omitempty" usage:"tools cache"`
23+ Chat * bool `yaml:"chat,omitempty" usage:"chat cache"`
24+ }
25+
26+ func (c * AnthropicCache ) SetDefaults () {
27+ if c .SystemMessage == nil {
28+ c .SystemMessage = yacl .P (false )
2029 }
21- if c .BaseUrl != "" {
22- opts = append ( opts , anthropic . WithBaseURL ( c . BaseUrl ) )
30+ if c .Tools == nil {
31+ c . Tools = yacl . P ( false )
2332 }
24- if c .Model != "" {
25- opts = append ( opts , anthropic . WithModel ( c . Model ) )
33+ if c .Chat == nil {
34+ c . Chat = yacl . P ( false )
2635 }
27-
28- return
2936}
3037
3138func (c * AnthropicConfig ) SetDefaults () {
@@ -45,6 +52,29 @@ func (c *AnthropicConfig) Validate() error {
4552 return nil
4653}
4754
55+ func (c * AnthropicConfig ) AsOptions () (opts []anthropic.Option ) {
56+ if v := c .Token .GetOrPanicWithDefaultTimeout (); v != nil {
57+ opts = append (opts , anthropic .WithToken (string (v )))
58+ }
59+ if c .BaseUrl != "" {
60+ opts = append (opts , anthropic .WithBaseURL (c .BaseUrl ))
61+ }
62+ if c .Model != "" {
63+ opts = append (opts , anthropic .WithModel (c .Model ))
64+ }
65+ if c .Cache .SystemMessage != nil && ! * c .Cache .SystemMessage {
66+ opts = append (opts , anthropic .WithCacheSystemMessage ())
67+ }
68+ if c .Cache .Tools != nil && ! * c .Cache .Tools {
69+ opts = append (opts , anthropic .WithCacheTools ())
70+ }
71+ if c .Cache .Chat != nil && ! * c .Cache .Chat {
72+ opts = append (opts , anthropic .WithCacheChat ())
73+ }
74+
75+ return
76+ }
77+
4878func (c * AnthropicConfig ) BuildLLM () (llmCommon.Model , error ) {
4979 return iAnthropic .New (c .AsOptions ())
5080}
0 commit comments