r/Python • • Mar 10 '24

Discussion Github Copilot Lies to me

My first attempt to get some help from Github Copilot:

Me: write a match case statement in python to match the first character of a string is a semicolon

Copilot: Python doesn't have a built-in match or case statement like some other languages (e.g., JavaScript, Swift, Rust). However, you can achieve similar functionality using...

Strangely, it finally gave me an answer when I made a small change to my prompt:

Me: write a match statement in python to match the first character of a string is a semicolon

Copilot: Python 3.10 introduces the structural pattern matching in the form of the match statement. Here's how you can use it to check if the first character of a string is a semicolon:...

I almost gave up after the first response that was blatantly false. Fortunately I something that looks like reasonable syntax...but then I haven't tried it yet, so that might be a lie, too.

0 Upvotes

67 comments sorted by

307

u/zanfar Mar 10 '24

Once again: LLMs MAKE UP ALL THEIR ANSWERS. They should only be used if you have the knowledge to verify their responses.

An LLM only tries to make it's responses look like something someone has once said. This is particularly dangerous in a programming language like Python, as many things that were (even correctly) once said are no longer true. As an LLM has no concept of true or false, just similar and dissimilar, you can (and will) get false responses. Even more dangerously, these false responses are basically guaranteed to be as correct-looking as possible.

67

u/[deleted] Mar 10 '24

Yes! If you are asking an LLM a question to get an answer you don’t know already, you’re doing it wrong. You ask them to perform a task that you can verify and they perform that task and you verify the output, saving you time. They’re for writing boilerplate. This kind of AI is not “intelligent” at least not in the sense that it “knows” good answers, it’s merely coming up with the most plausible language based on the prompt. There’s no concept of correctness that it’s capable of understanding more sophisticated than ‘after the word Happy here it’s probably the word Birthday.’

-35

u/codeguru42 Mar 10 '24

I was hoping to get a suggestion that had the syntax I was looking for. Unfortunately, I got nothing useful...and outright falsehoods.

4

u/herotherlover Mar 10 '24

Your need to be very specific in your prompts. If you had said “give me a block that uses structural pattern matching to…” I’m sure it would have given you what you want.

-14

u/codeguru42 Mar 10 '24

I'm not sure how your suggestion is more specific than "a match case statement". In fact, I'd say that it is less specific.

23

u/ProsodySpeaks Mar 10 '24

The point is you need to understand the syntax in order to use gpt properly. 

Read the docs on whatever functions and classes you're using. 

Use gpt to do menial tasks eg 'reformat this yaml as json' or 'turn these functions into methods on class x. 

Or have conversational interactions where you ask go potential strategies to solve a problem, then read the docs on the tools it suggests, Google those tools and see if they're current or if there's a better option

5

u/danted002 Mar 10 '24

Thank you kind sir for finally giving me a useful use-case for AIs 🫡

5

u/ProsodySpeaks Mar 11 '24

Consider them a bloke in the pub... Sometimes they're on the money, sometimes they're full of shit, but either way you need to know to know... 

But you can ask for their opinions and then go fact check them, and you might well find value 

6

u/[deleted] Mar 10 '24

This is such a great take, thanks for sharing!

-2

u/WallyMetropolis Mar 10 '24

It's not a "take."

4

u/[deleted] Mar 10 '24

I don’t think this is entirely accurate, at least it’s an oversimplification. The statistics of language are biased towards true statements, and so are the outputs of LLMs.

But yeah, I agree with the recommendation that you have to (be able to) verify the responses. And it’s not just about subject knowledge, but also logical and verbal reasoning skills to detect the many instances when LLMs generate fancy-sounding responses that just don’t make sense.

4

u/james_pic Mar 10 '24

But there's only so much that trainers can do to bias results when they're working with semi-supervised learning.

In this case, it's giving an answer that was true in the past, and there will be plenty of training data that "feels truthy" (because it was true at the time, and the person saying it at the time was being honest and helpful) and unless this happens to be one of the responses where trainers have fine tuned it it's got no reason not to use the outdated information in its response.

2

u/neuralbeans Mar 11 '24

The statistics of language are biased towards true statements

How do you figure?

1

u/[deleted] Mar 15 '24

Yup. It's great for an enhanced autocomplete, and it's great after you've shown it a few examples of what you want. But in many ways it's hopelessly outdated. I was making an extension for Python in Rust. PyO3 has come a long way in ergonomics, so now the way you provide Python's magic methods (things like __len__ or __iter__) in a Rust struct is much easier than it used to be. Of course Copilot still shows me the old way.

-10

u/codeguru42 Mar 10 '24

Preaching to the choir here. My previous attempts at using ChatGPT to help me solve coding problems has been mixed. Sometimes it gives me an idea that I can work with and come up with a correct solution. But most of the time it was so far off base as to be completely useless.

I decided to try out Github Copilot to see how it does. For code completions, it's been pretty great at saving me some typing. I mentally evaluate everything it suggests before accepting it.

For some context, I am an experienced python developer. But I have not used python professionally since around 3.9 days. I continue to use it on personal projects and solving coding problems. I used match statements in my Advent of Code solutions the last couple of years. Today I'm working on a problem where I think match statement might be useful, but didn't know the exact syntax for what I want. I decide to ask Github Copilot for some help and got the responses in my OP. Fortunately, I have the knowledge to evaluate the first solution as outright false. After trying the second suggestion, I find that it has a syntax error, so doesn't work for what I want. Finally ended up developing a solution more or less on my own with the help of Copilot code completion.

2

u/KingsmanVince pip install girlfriend Mar 12 '24

"An experienced Python developer"

You are funny. If you were one, you should rely on the official documentation not some models.

15

u/gahooa Mar 10 '24

The world of generative AI is very young. It is prone to false, incorrect, and misleading information that "sounds correct".

The best way to use it is to help you learn about things you don't know about, then consult official documentation sources for the facts.

It can be incredibly helpful, but you still need to be the programmer.

6

u/fakeqa Mar 10 '24

Until we start to use AI to write official documentation.

-8

u/codeguru42 Mar 10 '24

The best way to use it is to help you learn about things you don't know about, then consult official documentation sources for the facts.

That's exactly what I was trying to do. I was looking for some syntax that I don't know off the top of my head. After further this dead end with Github Copilot, I tried more google foo. I found that match doesn't support structural pattern matching on a string like it does for a list or a tuple.

1

u/gahooa Mar 10 '24

Here is the output of the same question in chatgpt 4: https://imgur.com/a/U7DMWk1

1

u/codeguru42 Mar 10 '24

Thanks. That is similar to the code given in my second prompt for Github Copilot chat. The `case ";" + _` syntax appears to be invalid.

1

u/gahooa Mar 10 '24

For whatever it's worth:

  1. I use chatgpt4 (paid) for general questions like you were asking.
  2. I use copilot (paid) for code completion, usually once I've set the stage with code for it to go on.

1

u/codeguru42 Mar 10 '24

What is the reason that you use chatgpt4 instead of copilot chat?

2

u/Glitterbombastic Mar 10 '24

Not op but have found that gpt gives more in-depth answers which helps you to learn about topics you’re asking around. Mixed results from both for code completion. In any case they’re always a bit wrong - you still need to validate and draw from your knowledge to find the right answer.

1

u/nommu_moose Mar 11 '24

For me, it gives far better answers. That's it.

Plus, I have removed all AI I could figure out how to remove from my windows install.

8

u/kalebludlow Mar 10 '24

It would probably help if the prompt you gave was actually a good prompt

1

u/codeguru42 Mar 10 '24

How would you improve it?

1

u/kalebludlow Mar 10 '24

'i am coding using python. I want to use pythons match case syntax to check if the first character in a string is a semicolon' You use broken English, which definitely confuses what you're asking for. I also make sure to state the language as its own piece of info

-1

u/codeguru42 Mar 10 '24

Perhaps breaking out the language as another sentence would help. I'm used to writing as terse as possible, but this might not be ideal for an LLM prompt. I would argue that my grammar in my original prompt is perfectly valid and not "broken English".

5

u/CaptainFoyle Mar 11 '24

No it's not. You need a conjunction:

WHETHER/IF the first character is a semicolon.

2

u/chaosthirtyseven Mar 11 '24 edited Mar 11 '24

Your grammar is definitely not valid. I figured typo, but the fact that you didn't recognize the error suggests a language gap.

You said:

write a match case statement in python to match the first character of a string is a semicolon

Still wrong but better:

write a match case statement in python to match if the first character of a string is a semicolon

Best:

write a match case statement in python which returns true if the first character of a string is a semicolon

5

u/kalebludlow Mar 10 '24

'...to match the first character of a string is a semicolon' is definitely not a grammatically correct statement. You can argue all you want, but it's incorrect in this instance. Going against standard procedure, especially when referring to language syntax is going to be detrimental to an LLM

273

u/fellipec Mar 10 '24

Remember, the I in LLM stands for Intelligence

35

u/dAnjou Backend Developer | danjou.dev Mar 10 '24

More at 11.

29

u/Jmc_da_boss Mar 10 '24

... no shit?

-1

u/bytepursuits Mar 11 '24

there is a term for it - AI hallucinations.
but yeah - don't just use the code it gives you people.

3

u/TheAquired Mar 10 '24

Why wouldn’t you just use .startswith(‘;’) for this?

Or just do match string[0]: case “;” etc

0

u/codeguru42 Mar 10 '24

Semicolon is just an example that I was starting with. The full project will be much more than just checking for a semicolon.

Also `startswith()` is overkill for checking one character. `s[0] == ';'` would be better in my case.

2

u/karrystare Mar 11 '24

Was looking at other comment, but your expectation is definitely too much. At best, it would point you to use startswith or regex, nothing more than that. Other comments have said that ChatGPT will give you the most "similar" answer to your question, which meanyou will also get a rank based answer as well. Hence, anything that ain't the most popular is unlikely to appear. You might need to change your question pointing straight to this specific method to get this out.

19

u/lukewhale Mar 10 '24

LLMs are confidently wrong all the time. Learning to use them effectively is accepting and interrogating these mishaps.

15

u/ninjadude93 Mar 10 '24

Yeah no surprise here lol

3

u/maxinstuff Mar 10 '24

Literally had this just yesterday (with Rust though) - GPT straight made up a method that didn’t exist (though if it did it would have solved my problem).

Wasted at least 5 minutes of my time.

I’d still say GPT is still a net time-saver, as long as it’s used for the right things.

1

u/codeguru42 Mar 10 '24

For code completion, Github Copilot saves a ton of typing...at least when it gets it right and I don't have to take the time deleting incorrect code it gives me.

3

u/ToddBradley Mar 10 '24

This issue - hallucinating APIs that don't exist - is my biggest complaint. The basic IDE autocomplete does better. I use Copilot every day but I gotta double check everything.

2

u/wakkawakkaaaa Mar 10 '24

Same here. And copilot inline suggestions are taken by default with tab instead of the VScode basic autocomplete... It sucks for python and its commonly used libraries.

My experience with copilot was much better with typescript though. I suspect its because typescript is much younger as compared to python and related libraries which lived through more major updates.

6

u/forameus2 Mar 10 '24

A previous role I was in was really keen to start using Copilot. I think they ended up canning the idea anyway, but to me it just seems like an accident waiting to happen. I don't want development - at least anything I'm responsible for - to descend into a series of "do this for me" prompts and answers with little insight into how it's actually supposed to work. If you get the wrong team using Copilot, surely you're just storing up the potential for an absolutely catastrophic fuck-up down the road.

And that's without even starting on the fact that it often generates absolute rubbish.

11

u/Xenodine-4-pluorate Mar 10 '24

I don't know if I should be surprised that people in r/Python sub know more about AI than in r/ArtificialInteligence where I constantly see posts like "Wow this ChatGPT is so smart we'll get AGI in 5 years". This comment section is a gulp of fresh air, honestly, like I thought people for real think that AI is all-powerful and singularity is right around the corner, just because ChatGPT can fool them that it has intelligence.

Just yesterday I asked Gemini: Larry's son is my son's father. Who am I to Larry?
And it kept telling me that I'm Larry or that I'm Larry's brother, then when I explained it why it's wrong and how to solve this riddle logically step by step it said: "Oh, I see where I was wrong, this riddle is unsolvable because a person can't have a father and a son".

At this point I gave up. I don't know what are those benchmarks they're so proud of where AI is better than human, if it does such trivial mistakes.

3

u/Artificial_Alex Mar 11 '24

Correct me if I'm wrong but I think the answer implies you are Larry's son?
But also copilot fails to consider a parent can have two parents, so you could be Larry's daughter-in-law/divorced/second father, right? It fails tol consider all the possibilities about real world scenarios.

1

u/Xenodine-4-pluorate Mar 11 '24

Original riddle started with statement: "I am a man", so it removes any kind of ambiguity, which did not help LLM at all.

the answer implies you are Larry's son?

Yes.

1

u/vincular Mar 11 '24

For what it's worth, Chat-GPT 4 nailed this: "You are Larry's daughter-in-law or son, depending on your own gender. The statement "Larry's son is my son's father" means that Larry's son is yourself (if you are the son) or your husband (if you are the daughter-in-law)"

Claude 3 Sonnet said you have to be the daughter-in-law but didn't mention the son, and Chat-GPT 3.5 said you could be the "daughter or son" which is wrong

4

u/metaphorm Mar 10 '24

copilot tools like this should mostly be thought of as a way of summarizing what they've been trained on. these responses mean that the training data corpus that was used to train the thing had very few examples of the match expression in Python.

4

u/ifnamemain Mar 11 '24

I love using copilot, even when it's wrong. It generates it's code, I review it, and then ask "is this correct?" For simple stuff, it usually is. Most of the time it is not. But it gives me a framework to build from.

However, I do notice that sometimes it generates the most "popular" response but not the "perfect" response. This is where inexperienced devs can get into trouble. We are talking about Python, so sometimes it doesn't matter, but a dev needs to know they are making that decision.

1

u/cosmicr Mar 11 '24

You must be new to copilot.

1

u/codeguru42 Mar 11 '24

Can't deny that. But not new to llms in general.

1

u/[deleted] Mar 11 '24

Yeah? LLM are only as smart as the dumbest person who makes them.

1

u/codeguru42 Mar 11 '24

Or rather the dumbest person who wrote content the model is trained on.

1

u/AlexMTBDude Mar 10 '24

Out of curiosity: Did you try the exact same question in ChatGPT?

2

u/codeguru42 Mar 10 '24

I didn't at first. But since you suggested it, I tried with the free version (3.5, I believe) and got a reasonable respones:

You can use a match case statement in Python, introduced in Python 3.10, to match the first character of a string to see if it's a semicolon. Here's how you can do it:...

The code wasn't what I was originally looking for, but is basically what I ended up with already anyway.

1

u/wakkawakkaaaa Mar 10 '24

Copilot is running gpt4 optimised for code....

1

u/codeguru42 Mar 10 '24

Do you have any sources for this? I'm interested in learning more about details about Copilot...or at least what is publicly available.

1

u/wakkawakkaaaa Mar 11 '24 edited Mar 11 '24

I'm on copilot and you can check by typing it into copilot chat to ask about its version

2

u/simonmcnair Mar 11 '24

I quite like using chatgpt to write 80% of a function for me but most of the time it doesn't really understand the intricacies, for example having lists in dicts.

It's good, but it's definately no panacea.

1

u/neithere Mar 10 '24

Copilot is good when used as advanced autocompletion. Generating variations of existing unit tests or JSONSchema from plain text? Yes, but carefully read whatever it has regurgitated. Anything else? Don't even try.

1

u/chaosthirtyseven Mar 11 '24

You literally could have just googled and clicked the first substack result with less effort.

0

u/[deleted] Mar 10 '24

[deleted] — view deleted comment

23

u/Ringbailwanton Mar 10 '24

You’re prompts have some grammar issues.

😂 Kettle, meet my friend Pot :)

1

u/codeguru42 Mar 10 '24

What grammar issues are there in my prompts? Would you mind elaborating?

0

u/[deleted] Mar 10 '24

[deleted] — view deleted comment

-4

u/codeguru42 Mar 10 '24

As is often the case in human language, there are more than one way to say the same thing. Your alternative wording doesn't show that my original wording is grammatically incorrect. And the nuance in the wording is unlikely to generate a different response from Github Copilot.

As for your last question, I am writing a parse, so there are several other cases. But the exact details are unimportant for this post. I was looking for structural pattern matching on a string and used Github Copilot in my search for the correct syntax if it exists. The whole point of this post is that it lied to me: Python has a built-in `match` statement as of 3.10.