k8sgpt-ai / k8sgpt

Giving Kubernetes Superpowers to everyone
http://k8sgpt.ai
Apache License 2.0
5.93k stars 689 forks source link

[Bug]: analyze`s --backend arg error #902

Closed JuHyung-Son closed 8 months ago

JuHyung-Son commented 9 months ago

Checklist

Affected Components

K8sGPT Version

No response

Kubernetes Version

No response

Host OS and its Version

No response

Steps to reproduce

2 problems.

  1. set default backend as none openai and give -b openai -> use default backend not openai

    > ./bin/k8sgpt analyze -f Service -n default -c -e -b openai
    0% |                                                                                                                                                                                                                                                                                | (0/8, 0 it/hr) [0s:0s]
    Error: failed while calling AI provider localai: error, status code: 404, message: %!s(<nil>)
  2. set any default backend and run analyze with -b arg -> only use default backend not provided arg. (i think this is bug)

    > ./bin/k8sgpt auth default -p noopai
    Default provider set to noopai
    > ./bin/k8sgpt analyze -f Service -n default -e -c localai
    100% |███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| (7/7, 2693 it/s)
    AI Provider: noopai

Expected behaviour

ai provider should be provided --backend even openai is given.

Actual behaviour

No response

Additional Information

No response

VaibhavMalik4187 commented 9 months ago

Hi, can I work on this?

JuHyung-Son commented 9 months ago

@VaibhavMalik4187 sure

VaibhavMalik4187 commented 9 months ago

It looks like this behaviour is intentional and was introduced by @AlexsJones in the commit cbe2fb4a4c160a0a24b3fb4602cae8e5eebd6aa0.

@AlexsJones, in https://github.com/k8sgpt-ai/k8sgpt/pull/427#discussion_r1194874035, I don't think that the code matches the reasoning. Like, in this case, the backend has been specified as openai and the default backend is also set. But the default backend is being used because it satisfies the following condition and sets the backend to use the default backend:

    if configAI.DefaultProvider != "" && backend == "openai" {
        backend = configAI.DefaultProvider
    }
VaibhavMalik4187 commented 9 months ago

Changing the default value of the backend flag to "" and updating the if condition to:

    if configAI.DefaultProvider == "" && backend == "" {
        backend = "openai"
        } else if configAI.DefaultProvider != "" && backend == "" {
        backend = configAI.DefaultProvider
        }

Fixes the issue, would like to know your thoughts on this @AlexsJones, @JuHyung-Son. Thanks!