Procházet zdrojové kódy

fix: vertexai dynamic publishers (#436)

* fix: vertexai dynamic publishers

* fix: ci lint
zijiren před 2 týdny
rodič
revize
b489857386

+ 4 - 1
core/relay/adaptor/anthropic/main.go

@@ -104,12 +104,15 @@ func resetCacheTTLWithContentsNode(contents *ast.Node) error {
 	if contents.Check() != nil {
 		return nil
 	}
+
 	return contents.ForEach(func(_ ast.Sequence, content *ast.Node) bool {
 		cacheControl := content.Get("cache_control")
 		if cacheControl.Check() != nil {
 			return true
 		}
+
 		_, _ = cacheControl.Unset("ttl")
+
 		return true
 	})
 }
@@ -138,7 +141,7 @@ func ConvertRequestBodyToBytes(
 
 	messagesNode := node.Get("messages")
 	if messagesNode.Check() == nil {
-		messagesNode.ForEach(func(_ ast.Sequence, messages *ast.Node) bool {
+		_ = messagesNode.ForEach(func(_ ast.Sequence, messages *ast.Node) bool {
 			_ = resetCacheTTLWithContentsNode(messages.Get("content"))
 			return true
 		})

+ 13 - 4
core/relay/adaptor/vertexai/adaptor.go

@@ -108,13 +108,19 @@ func (a *Adaptor) GetRequestURL(
 		return adaptor.RequestURL{}, err
 	}
 
+	publishers := "google"
+	if strings.Contains(meta.ActualModel, "claude") {
+		publishers = "anthropic"
+	}
+
 	if meta.Channel.BaseURL != "" {
 		if config.ProjectID == "" || config.Region == "" {
 			return adaptor.RequestURL{
 				Method: http.MethodPost,
 				URL: fmt.Sprintf(
-					"%s/v1/publishers/google/models/%s:%s",
+					"%s/v1/publishers/%s/models/%s:%s",
 					meta.Channel.BaseURL,
+					publishers,
 					meta.ActualModel,
 					suffix,
 				),
@@ -124,10 +130,11 @@ func (a *Adaptor) GetRequestURL(
 		return adaptor.RequestURL{
 			Method: http.MethodPost,
 			URL: fmt.Sprintf(
-				"%s/v1/projects/%s/locations/%s/publishers/google/models/%s:%s",
+				"%s/v1/projects/%s/locations/%s/publishers/%s/models/%s:%s",
 				meta.Channel.BaseURL,
 				config.ProjectID,
 				config.Region,
+				publishers,
 				meta.ActualModel,
 				suffix,
 			),
@@ -145,8 +152,9 @@ func (a *Adaptor) GetRequestURL(
 		return adaptor.RequestURL{
 			Method: http.MethodPost,
 			URL: fmt.Sprintf(
-				"https://%s/v1/publishers/google/models/%s:%s",
+				"https://%s/v1/publishers/%s/models/%s:%s",
 				requestDoamin,
+				publishers,
 				meta.ActualModel,
 				suffix,
 			),
@@ -156,10 +164,11 @@ func (a *Adaptor) GetRequestURL(
 	return adaptor.RequestURL{
 		Method: http.MethodPost,
 		URL: fmt.Sprintf(
-			"https://%s/v1/projects/%s/locations/%s/publishers/google/models/%s:%s",
+			"https://%s/v1/projects/%s/locations/%s/publishers/%s/models/%s:%s",
 			requestDoamin,
 			config.ProjectID,
 			config.Region,
+			publishers,
 			meta.ActualModel,
 			suffix,
 		),