Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Generation failure while using Amazon Q #5638

Open
vaibha-v opened this issue Sep 19, 2024 · 1 comment
Open

Code Generation failure while using Amazon Q #5638

vaibha-v opened this issue Sep 19, 2024 · 1 comment
Labels
amazonq bug We can reproduce the issue and confirmed it is a bug. codewhisperer

Comments

@vaibha-v
Copy link

vaibha-v commented Sep 19, 2024

Problem

Code generation failed when i asked the Gen AI Amazon Q to change my code
"can you add LRU caching logic in the selected code?"

Steps to reproduce the issue

Ask the above question to the AI and error will be seen by you

selected code -
import os
from collections import defaultdict

responses = defaultdict(lambda: "data Not Valid")

def create_map():
with open("/xyz/Python/data.txt", "r") as dialogs:
for line in dialogs:
key, value = line.strip().split("\t", 1)
responses[key] = value

def chatbot_response(message):
message = message.lower().strip() # Convert the message to lowercase and remove leading/trailing whitespace
return responses[message] if message in responses else responses['default'] # Return the response for the given message, or the default response if no match is found

print("Chatbot: Hello! I'm a simple chatbot. You can ask me simple questions or greetings.")
create_map()

while True:
user_input = input("You: ")
response = chatbot_response(user_input)
print("Chatbot:", response)

Ran the command -
can you add LRU caching logic in the selected code

Generated Code -
import os
from collections import OrderedDict

class TrieNode:
def init(self):
self.children = {}
self.is_end = False
self.response = None

class Trie:
def init(self):
self.root = TrieNode()

def insert(self, word, response):
    node = self.root
    for char in word:
        if char not in node.children:
            node.children[char] = TrieNode()
        node = node.children[char]
    node.is_end = True
    node.response = response

def search(self, word):
    node = self.root
    for char in word:
        if char not in node.children:
            return None
        node = node.children[char]
    return node.response if node.is_end else None

class LRUCache:
def init(self, capacity):
self.cache = OrderedDict()
self.capacity = capacity

def get(self, key):
    if key not in self.cache:
        return None
    self.cache.move_to_end(key)
    return self.cache[key]

def put(self, key, value):
    if key in self.cache:
        self.cache.move_to_end(key)
    self.cache[key] = value
    if len(self.cache) > self.capacity:
        self.cache.popitem(last=False)

trie = Trie()
cache = LRUCache(100) # Adjust the capacity as needed

def create_trie():
with open("/xyz/Python/data.txt", "r") as dialogs:
for line in dialogs:
plit("\t", 1)
trie.insert(key.lower(), value)

def chatbot_response(message):
message = message.lower().strip()

# Check cache first
cached_response = cache.get(message)
if cached_response:
    return cached_response

# If not in cache, search in trie
response = trie.search(message)
if response:
    # Add to cache
    cache.put(message, response)
    return response

return "Data Not Valid"

print("Chatbot: Hello! I'm a simple chatbot. You can ask me simple questions or greetings.")
create_trie()

while True:
user_input = input("You: ")
response = chatbot_response(user_input)
print("Chatbot:", response)

Issue -
In the function create trie generation has failed.
plit("\t", 1)

Expected behavior

Code generation should be proper.

I want amazon dev team help to correct this for amazon q product chatbot, i dont have any problem with generated code i can correct myself , i tested found the issue and reported

System details (run AWS: About and/or Amazon Q: About)

  • OS: Mac OS
  • Visual Studio Code version: Latest
  • AWS Toolkit version: Latest
  • Amazon Q version: Latest
@vaibha-v vaibha-v added the bug We can reproduce the issue and confirmed it is a bug. label Sep 19, 2024
@andrewyuq
Copy link
Contributor

Hi, service team returned back saying that we can’t reproduce the issue. If you still see the problem, we will need the problematic examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amazonq bug We can reproduce the issue and confirmed it is a bug. codewhisperer
Projects
None yet
Development

No branches or pull requests

3 participants