@@ -24,8 +24,6 @@ import (
2424 "net/http"
2525 "time"
2626
27- "github.com/openai/openai-go/option"
28- "github.com/openai/openai-go/responses"
2927 "github.com/volcengine/volcengine-go-sdk/service/arkruntime"
3028 "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
3129
@@ -246,32 +244,41 @@ func buildResponsesAPIChatModel(config *ChatModelConfig) (*responsesAPIChatModel
246244 return nil , err
247245 }
248246 }
247+ var opts []arkruntime.ConfigOption
249248
250- var opts []option.RequestOption
249+ if config .Region == "" {
250+ opts = append (opts , arkruntime .WithRegion (defaultRegion ))
251+ } else {
252+ opts = append (opts , arkruntime .WithRegion (config .Region ))
253+ }
251254
252255 if config .Timeout != nil {
253- opts = append (opts , option . WithRequestTimeout (* config .Timeout ))
256+ opts = append (opts , arkruntime . WithTimeout (* config .Timeout ))
254257 } else {
255- opts = append (opts , option . WithRequestTimeout (defaultTimeout ))
258+ opts = append (opts , arkruntime . WithTimeout (defaultTimeout ))
256259 }
257260 if config .HTTPClient != nil {
258- opts = append (opts , option .WithHTTPClient (config .HTTPClient ))
261+ opts = append (opts , arkruntime .WithHTTPClient (config .HTTPClient ))
259262 }
260263 if config .BaseURL != "" {
261- opts = append (opts , option . WithBaseURL (config .BaseURL ))
264+ opts = append (opts , arkruntime . WithBaseUrl (config .BaseURL ))
262265 } else {
263- opts = append (opts , option . WithBaseURL (defaultBaseURL ))
266+ opts = append (opts , arkruntime . WithBaseUrl (defaultBaseURL ))
264267 }
265268 if config .RetryTimes != nil {
266- opts = append (opts , option . WithMaxRetries (* config .RetryTimes ))
269+ opts = append (opts , arkruntime . WithRetryTimes (* config .RetryTimes ))
267270 } else {
268- opts = append (opts , option .WithMaxRetries (defaultRetryTimes ))
269- }
270- if config .APIKey != "" {
271- opts = append (opts , option .WithAPIKey (config .APIKey ))
271+ opts = append (opts , arkruntime .WithRetryTimes (defaultRetryTimes ))
272272 }
273273
274- client := responses .NewResponseService (opts ... )
274+ var client * arkruntime.Client
275+ if len (config .APIKey ) > 0 {
276+ client = arkruntime .NewClientWithApiKey (config .APIKey , opts ... )
277+ } else if config .AccessKey != "" && config .SecretKey != "" {
278+ client = arkruntime .NewClientWithAkSk (config .AccessKey , config .SecretKey , opts ... )
279+ } else {
280+ return nil , fmt .Errorf ("new arkruntime client fail, missing credentials: set 'APIKey' or both 'AccessKey' and 'SecretKey'" )
281+ }
275282
276283 cm := & responsesAPIChatModel {
277284 client : client ,
@@ -285,22 +292,15 @@ func buildResponsesAPIChatModel(config *ChatModelConfig) (*responsesAPIChatModel
285292 cache : config .Cache ,
286293 serviceTier : config .ServiceTier ,
287294 }
288-
289295 return cm , nil
290296}
291297
292298func checkResponsesAPIConfig (config * ChatModelConfig ) error {
293- if config .Region != "" {
294- return fmt .Errorf ("'Region' is not supported by ResponsesAPI" )
295- }
296- if config .APIKey == "" {
297- if config .AccessKey != "" {
298- return fmt .Errorf ("'AccessKey' is not supported by ResponsesAPI" )
299- }
300- if config .SecretKey != "" {
301- return fmt .Errorf ("'SecretKey' is not supported by ResponsesAPI" )
302- }
299+
300+ if config .APIKey == "" && (config .AccessKey == "" && config .SecretKey == "" ) {
301+ return fmt .Errorf ("missing credentials: set 'APIKey' or both 'AccessKey' and 'SecretKey'" )
303302 }
303+
304304 if len (config .Stop ) > 0 {
305305 return fmt .Errorf ("'Stop' is not supported by ResponsesAPI" )
306306 }
@@ -505,10 +505,9 @@ func (cm *ChatModel) IsCallbacksEnabled() bool {
505505//
506506// Note:
507507// - It is unavailable for doubao models of version 1.6 and above.
508- // - Currently, only supports calling by ContextAPI.
509- func (cm * ChatModel ) CreatePrefixCache (ctx context.Context , prefix []* schema.Message , ttl int ) (info * CacheInfo , err error ) {
508+ func (cm * ChatModel ) CreatePrefixCache (ctx context.Context , prefix []* schema.Message , ttl int , opts ... fmodel.Option ) (info * CacheInfo , err error ) {
510509 if cm .respChatModel .cache != nil && ptrFromOrZero (cm .respChatModel .cache .APIType ) == ResponsesAPI {
511- return nil , fmt . Errorf ( "CreatePrefixCache is not supported by ResponsesAPI" )
510+ return cm . respChatModel . createPrefixCacheByResponseAPI ( ctx , prefix , ttl , opts ... )
512511 }
513512 return cm .createContextByContextAPI (ctx , prefix , ttl , model .ContextModeCommonPrefix , nil )
514513}
0 commit comments