SilasMarvin / lsp-ai

LSP-AI is an open-source language server that serves as a backend for AI-powered functionality, designed to assist and empower software engineers, not replace them.
MIT License
1.82k stars 55 forks source link

The code generated using the above prompt needs to be deleted before it can be used. Is there any good way to directly delete it? #24

Closed fxcl closed 1 week ago

fxcl commented 2 weeks ago
"lsp-ai.serverConfiguration": {
        "memory": {
            "file_store": {}
          },
          "models": {
            "model1": {
              "type": "open_ai",
              "chat_endpoint": "https://api.openai.com/v1/chat/completions",
              "model": "gpt-4o",
              "auth_token": "sk-xxxxxxxxxxxxxx"
            }
          },
          "completion": {
            "model": "model1",
            "parameters": {
              "max_context": 2048,
              "max_tokens": 128,
              "messages": [
                {
                  "role": "system",
                  "content": "Instructions:\n- You are an AI programming assistant.\n- Given a piece of code with the cursor location marked by \"<CURSOR>\", replace \"<CURSOR>\" with the correct code or comment.\n- First, think step-by-step.\n- Describe your plan for what to build in pseudocode, written out in great detail.\n- Then output the code replacing the \"<CURSOR>\"\n- Ensure that your completion fits within the language context of the provided code snippet (e.g., Python, JavaScript, Rust).\n\nRules:\n- Only respond with code or comments.\n- Only replace \"<CURSOR>\"; do not include any previously written code.\n- Never include \"<CURSOR>\" in your response\n- If the cursor is within a comment, complete the comment meaningfully.\n- Handle ambiguous cases by providing the most contextually appropriate completion.\n- Be consistent with your responses."
                },
                {
                  "role": "user",
                  "content": "def greet(name):\n    print(f\"Hello, {<CURSOR>}\")"
                },
                {
                  "role": "assistant",
                  "content": "name"
                },
                {
                  "role": "user",
                  "content": "function sum(a, b) {\n    return a + <CURSOR>;\n}"
                },
                {
                  "role": "assistant",
                  "content": "b"
                },
                {
                  "role": "user",
                  "content": "fn multiply(a: i32, b: i32) -> i32 {\n    a * <CURSOR>\n}"
                },
                {
                  "role": "assistant",
                  "content": "b"
                },
                {
                  "role": "user",
                  "content": "# <CURSOR>\ndef add(a, b):\n    return a + b"
                },
                {
                  "role": "assistant",
                  "content": "Adds two numbers"
                },
                {
                  "role": "user",
                  "content": "# This function checks if a number is even\n<CURSOR>"
                },
                {
                  "role": "assistant",
                  "content": "def is_even(n):\n    return n % 2 == 0"
                },
                {
                  "role": "user",
                  "content": "{CODE}"
                }
              ]
            }
          }
    },

The code generated using the above prompt needs to be deleted before it can be used. Is there any good way to directly delete it?

def TreeNode:```python

Binary tree node definition

def __init__(self, value=0, left=None, right=None):
    self.value = value
    self.left = left
    self.right = right
# Function to create a binary tree from a list
def create_binary_tree(lst, index=0):
    if index < len(lst):
        node = TreeNode(lst[index])
        node.left = create_binary_tree(lst, 2 * index + 1)
        node.right = create_binary_tree(lst, 2 * index + 2)
        return node
    return None
```python
# Example usage
if __name__ == "__main__":
    elements = [1, 2, 3, 4, 5, 6, 7]
    root = create_binary_tree(elements)
    print(root.value)  # Output: 1
```python
```python
print(root.left.value)  # Output: 2
```print(root.right.value)  # Output: 3
SilasMarvin commented 2 weeks ago

Sorry I don't think I fully understand what is going on. Are you showing output from LSP-AI here? It might be helpful to take a video or breakdown step by step what is going on.

Also note that you can play around with prompts if you don't like the output you are getting. If you want to code in just Python, it may be worth adjusting the few shot prompts to be only in Python. These could be some fun experiments worth testing.

fxcl commented 2 weeks ago

image In the code generated using LSP AI, there will be a markdown code syntax as shown in the figure, but I only want to keep the code, and other code syntax does not need to be displayed in cursor.

SilasMarvin commented 1 week ago

This is a mixture of not the best prompt, and a limitation of LLMs. Its really difficult to get them to do code completion correctly, and that prompt that I came up with is definitely not the best. You are welcome to play around with the prompt, or try a FIM model like Codestral