-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: analyzer and ai interfacing (#200)
* chore: analyzer and ai interfacing Signed-off-by: Thomas Schuetz <[email protected]> * fix: backend variable for aiProvider in cmd Signed-off-by: Thomas Schuetz <[email protected]> * fix: changed folders for analyzers Signed-off-by: Thomas Schuetz <[email protected]> * chore: renamed analyzers Signed-off-by: Thomas Schuetz <[email protected]> * fix: fixed ingress tests after rebase Signed-off-by: Thomas Schuetz <[email protected]> * fix: fixed ingress tests after rebase Signed-off-by: Thomas Schuetz <[email protected]> --------- Signed-off-by: Thomas Schuetz <[email protected]>
- Loading branch information
Showing
18 changed files
with
274 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
package ai | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
) | ||
|
||
type IAI interface { | ||
Configure(token string, language string) error | ||
GetCompletion(ctx context.Context, prompt string) (string, error) | ||
Parse(ctx context.Context, prompt []string, nocache bool) (string, error) | ||
} | ||
|
||
func NewClient(provider string) IAI { | ||
switch provider { | ||
case "openai": | ||
return &OpenAIClient{} | ||
default: | ||
return &OpenAIClient{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package analysis | ||
|
||
import ( | ||
"context" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/ai" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/analyzer" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Analysis struct { | ||
Context context.Context | ||
Filters []string | ||
Client *kubernetes.Client | ||
AIClient ai.IAI | ||
Results []analyzer.Result | ||
Namespace string | ||
NoCache bool | ||
Explain bool | ||
} | ||
|
||
func (a *Analysis) RunAnalysis() error { | ||
|
||
activeFilters := viper.GetStringSlice("active_filters") | ||
|
||
analyzerMap := analyzer.GetAnalyzerMap() | ||
|
||
analyzerConfig := analyzer.Analyzer{ | ||
Client: a.Client, | ||
Context: a.Context, | ||
Namespace: a.Namespace, | ||
AIClient: a.AIClient, | ||
} | ||
|
||
// if there are no filters selected and no active_filters then run all of them | ||
if len(a.Filters) == 0 && len(activeFilters) == 0 { | ||
for _, analyzer := range analyzerMap { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
return nil | ||
} | ||
|
||
// if the filters flag is specified | ||
if len(a.Filters) != 0 { | ||
for _, filter := range a.Filters { | ||
if analyzer, ok := analyzerMap[filter]; ok { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// use active_filters | ||
for _, filter := range activeFilters { | ||
if analyzer, ok := analyzerMap[filter]; ok { | ||
results, err := analyzer.Analyze(analyzerConfig) | ||
if err != nil { | ||
return err | ||
} | ||
a.Results = append(a.Results, results...) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.