Skip to content

Commit

Permalink
Merge pull request #2493 from CrowleyRajapakse/ai
Browse files Browse the repository at this point in the history
Adding ai provider related changes in dp to cp flow
  • Loading branch information
CrowleyRajapakse authored Sep 26, 2024
2 parents ff49dfb + 41fb538 commit 65776db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 15 additions & 7 deletions adapter/internal/controlplane/eventPublisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type API struct {
IsDefaultVersion bool `json:"isDefaultVersion"`
Definition string `json:"definition"`
APIType string `json:"apiType"`
APISubType string `json:"apiSubType"`
BasePath string `json:"basePath"`
Organization string `json:"organization"`
SystemAPI bool `json:"systemAPI"`
Expand All @@ -98,18 +99,25 @@ type API struct {
AuthHeader string `json:"authHeader"`
APIKeyHeader string `json:"apiKeyHeader"`
Operations []Operation `json:"operations"`
AIConfiguration AIConfiguration `json:"aiConfiguration"`
APIHash string `json:"-"`
SandAIRL *AIRL `json:"sandAIRL"`
ProdAIRL *AIRL `json:"prodAIRL"`
SandAIRL *AIRL `json:"sandAIRL"`
ProdAIRL *AIRL `json:"prodAIRL"`
}

// AIRL holds AI ratelimit related data
type AIRL struct {
PromptTokenCount *uint32 `json:"promptTokenCount"`
CompletionTokenCount *uint32 `json:"CompletionTokenCount"`
TotalTokenCount *uint32 `json:"totalTokenCount"`
TimeUnit string `json:"timeUnit"`
RequestCount *uint32 `json:"requestCount"`
PromptTokenCount *uint32 `json:"promptTokenCount"`
CompletionTokenCount *uint32 `json:"CompletionTokenCount"`
TotalTokenCount *uint32 `json:"totalTokenCount"`
TimeUnit string `json:"timeUnit"`
RequestCount *uint32 `json:"requestCount"`
}

// AIConfiguration holds the AI configuration
type AIConfiguration struct {
LLMProviderName string `json:"llmProviderName"`
LLMProviderAPIVersion string `json:"llmProviderAPIVersion"`
}

// Headers contains the request and response header modifier information
Expand Down
14 changes: 14 additions & 0 deletions adapter/internal/operator/controllers/dp/api_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2923,11 +2923,24 @@ func (apiReconciler *APIReconciler) convertAPIStateToAPICp(ctx context.Context,
RequestCount: requestC,
}
}
subType := "DEFAULT"
aiConfiguration := controlplane.AIConfiguration{}
if apiState.AIProvider != nil {
loggers.LoggerAPKOperator.Debugf("AIProvider is found")
subType = "AIAPI"
aiConfiguration = controlplane.AIConfiguration{
LLMProviderName: apiState.AIProvider.Spec.ProviderName,
LLMProviderAPIVersion: apiState.AIProvider.Spec.ProviderAPIVersion,
}
}
loggers.LoggerAPKOperator.Debugf("Resolved aiConfiguration: %+v", aiConfiguration)

api := controlplane.API{
APIName: spec.APIName,
APIVersion: spec.APIVersion,
IsDefaultVersion: spec.IsDefaultVersion,
APIType: spec.APIType,
APISubType: subType,
BasePath: spec.BasePath,
Organization: spec.Organization,
Environment: spec.Environment,
Expand All @@ -2949,6 +2962,7 @@ func (apiReconciler *APIReconciler) convertAPIStateToAPICp(ctx context.Context,
APIKeyHeader: apiKeyHeader,
SandAIRL: &sandAIRLToAgent,
ProdAIRL: &prodAIRLToAgent,
AIConfiguration: aiConfiguration,
}
apiCPEvent.API = api
apiCPEvent.CRName = apiState.APIDefinition.ObjectMeta.Name
Expand Down

0 comments on commit 65776db

Please sign in to comment.