katsumiok/pyaskit

View on GitHub

Showing 27 of 27 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def convert_messages(messages):
    result = []
    for message in messages:
        role = convert_role(message["role"])
        result.append({"role": role, "message": message["content"]})
Severity: Major
Found in pyaskit/llm_cohere.py and 1 other location - About 3 hrs to fix
pyaskit/llm_claude.py on lines 11..17

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 72.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

def convert_messages(messages):
    result = []
    for message in messages:
        role = convert_role(message["role"])
        result.append({"role": role, "content": message["content"]})
Severity: Major
Found in pyaskit/llm_claude.py and 1 other location - About 3 hrs to fix
pyaskit/llm_cohere.py on lines 11..17

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 72.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function convert_type has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def convert_type(x, memory={}):
    if isinstance(x, t.Type):
        return x
    if x == int:
        return t.int
Severity: Minor
Found in pyaskit/types/converter.py - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function make_examples has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def make_examples(func, tested_func):
    def safe_eval(node_or_string):
        """Safely evaluate Python expressions from AST nodes or strings."""
        try:
            if isinstance(node_or_string, ast.AST):
Severity: Minor
Found in pyaskit/decorator.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function check_args has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def check_args(self, args, kwargs, variables, variableMap):
        for var, arg in zip(variables, args):
            if var in kwargs:
                raise ValueError(f"got multiple values for argument '{var}'")
            variableMap[var] = arg
Severity: Minor
Found in pyaskit/function.py - About 55 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function main has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def main(
Severity: Major
Found in examples/use_llama2.py - About 50 mins to fix

    Function use_llama has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def use_llama(
    Severity: Major
    Found in pyaskit/llm_llama.py - About 50 mins to fix

      Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, answer, answer_type, completion, reason, errors, messages):
      Severity: Minor
      Found in pyaskit/function.py - About 45 mins to fix

        Function defun has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def defun(
        Severity: Minor
        Found in pyaskit/py_askit.py - About 45 mins to fix

          Function make_coding_prompt has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def make_coding_prompt(
          Severity: Minor
          Found in pyaskit/prompt.py - About 45 mins to fix

            Function query has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def query(
            Severity: Minor
            Found in pyaskit/dialog.py - About 35 mins to fix

              Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def __init__(
              Severity: Minor
              Found in pyaskit/function.py - About 35 mins to fix

                Function _check_input has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def _check_input(variables, input):
                    if not isinstance(input, dict):
                        raise ValueError(f"Input must be a dictionary: {input}")
                    for variable in variables:
                        if variable not in input:
                Severity: Minor
                Found in pyaskit/example.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function ask_and_parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def ask_and_parse(return_type, messages):
                    retry = False
                    errors = []
                
                    for _ in range(10):
                Severity: Minor
                Found in pyaskit/dialog.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function get_packages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def get_packages(source_code):
                    tree = ast.parse(source_code)
                    packages = []
                
                    for node in ast.walk(tree):
                Severity: Minor
                Found in pyaskit/code_generator.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Avoid too many return statements within this function.
                Open

                        return t.str
                Severity: Major
                Found in pyaskit/types/converter.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return t.list(convert_type(args[0], memory))
                  Severity: Major
                  Found in pyaskit/types/converter.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return t.tuple(*[convert_type(item_type, memory) for item_type in args])
                    Severity: Major
                    Found in pyaskit/types/converter.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return t.literal(*get_args(x))
                      Severity: Major
                      Found in pyaskit/types/converter.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return t.record(convert_type(args[0], memory), convert_type(args[1], memory))
                        Severity: Major
                        Found in pyaskit/types/converter.py - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language