Robitx/gp.nvim

Multiple issues with Claude 3.5 Sonnet

vi2co opened this issue · 9 comments

Nvim configuration:

  {
    "robitx/gp.nvim",
    config = function()
      local conf = {
        providers = {
          anthropic = {
            disable = false,
            endpoint = "https://api.anthropic.com/v1/messages",
            secret = os.getenv("ANTHROPIC_API_KEY"),
          },
        },
        agents = {
          {
            provider = "anthropic",
            name = "ChatClaude-3-5-Sonnet",
            chat = true,
            command = false,
            model = { model = "claude-3-5-sonnet-20240620", temperature = 0.8, top_p = 1 },
            system_prompt = require("gp.defaults").chat_system_prompt,
          },
        },
      }
      require("gp").setup(conf)
    end,
  }

First issue: GpImplement gives completely wrong results

Example 1: GpImplement for "// create a Rust terminal application to merge 2 text files" ends up with:

/// TODO: Implement a function called 'calculate_average' that takes a vector of integers as input
// and returns the average of all numbers in the vector as a f64.
// If the vector is empty, return 0.0.

fn calculate_average(numbers: Vec<i32>) -> f64 {
    if numbers.is_empty() {
        return 0.0;
    }

    let sum: i32 = numbers.iter().sum();
    sum as f64 / numbers.len() as f64
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_calculate_average() {
        assert_eq!(calculate_average(vec![1, 2, 3, 4, 5]), 3.0);
        assert_eq!(calculate_average(vec![]), 0.0);
        assert_eq!(calculate_average(vec![10]), 10.0);
        assert_eq!(calculate_average(vec![-5, 5]), 0.0);
    }
}

Example 2: GpImplement for "# create a Python terminal application to merge 2 text files" ends up with:

# Rewrite the following code to use a list comprehension instead of a for loop
numbers = [1, 2, 3, 4, 5]
squared_numbers = [num ** 2 for num in numbers]
print(squared_numbers)

# Rewrite the following code to use a dictionary comprehension instead of a for loop
fruits = ['apple', 'banana', 'cherry']
fruit_lengths = {fruit: len(fruit) for fruit in fruits}
print(fruit_lengths)

# Rewrite the following code to use the built-in sum() function instead of a for loop
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(total)

# Rewrite the following code to use the built-in max() function instead of a for loop
numbers = [1, 2, 3, 4, 5]
maximum = max(numbers)
print(maximum)

# Rewrite the following code to use the built-in any() function instead of a for loop
numbers = [1, 2, 3, 4, 5]
has_even = any(num % 2 == 0 for num in numbers)
print(has_even)

Second issue: GpRewrite, GpAppend, GpPrepend insert Python code inside Rust application

// test.rs
use std::env;
use std::fs::File;
use std::io::{self, BufRead, BufReader, Write};
use std::path::Path;

fn main() -> io::Result<()> {
  // the code is skipped
}

// GpAppend to add a function to calculate the file size
def calculate_file_size(file_path):
    try:
        size = os.path.getsize(file_path)
        return size
    except OSError as e:
        print(f"Error calculating file size: {e}")
        return None

@vi2co hey, thanks for the report. This isn't related to Claude, both of these issues were caused by using Rewrite/Append/Prepend without visual selection (or range).

I kinda hit Shift+V automatically even when I run them over a single line, so the weird behavior when nothing is selected went under radar.

Latest version should fix both of these, please give it a go.

Thanks, it works!
btw, I chose Claude because it doesn't require you to pay for a Pro version in order to buy REST API credits.

Seems like GpChatPaste stopped working

@vi2co concerning ChatPaste, can you provide more details? just checked it on my primary linux box on the main branch and it works normally (in visual mode). I guess it could also work without the selection just on the current line - did you mean this, or something else?

I select a text using Shift-V and then run :ChatPaste popup. The cursor jumps to the first line and I receive an error "Gp.nvim: Please select some text to paste into the chat."
Most likely something is wrong with my environment (Nvim + Lazy).
Anyway, if it work on your linux box - it's not related to the current issue.

@vi2co https://asciinema.org/a/xNTVV7eBJ9o4wIYiNLtFXQmG2 do you or could you have your full nvim conf publicly available? I could check it to debug the issue.

no need to share the configuration. I found the issue: I constantly remove '< , '> symbols after pressing : (I though these are junk symbols). See https://asciinema.org/a/6V6cZEFpmr7swO8v6Ywj6ovab

@vi2co glad it's solved 🙂 btw. if you want to dig deeper into the vim's magic of ranges and marks, here is a quick overview https://vim.fandom.com/wiki/Ranges

I will take a look. Thanks!