Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Discussion Positive use cases for Chat GPT in helping with code/dev

Discussion in 'General Discussion' started by andyz, Jul 20, 2023.

Thread Status:
Not open for further replies.
  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,128
    So apart from asking Chat GPT (ideally 4) for how to code something with varying results, how else have you found it helpful in little or big ways?

    For instance I wanted to get an isolated list of case values (strings!! :/) in a large switch statement - I can edit some text to get it but I just asked ChatGPT "I have a C# switch statement, could you make me a list of just the case values?" It asked for the code so I pasted and it compiled a neat list.
    It even said "Please note that I excluded the commented out case statements. If you want those included as well, please let me know!"

    That seems kind of cool even to a sceptic...
     
    Last edited: Jul 20, 2023
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,556
    Generally finding it useful in terms of doing initial research on given topic.
    However, I always validate responses with relevant topic. This is important.

    Even in none English language, I found answers quicker, than trying to go through list of data. Use case example on governmental websites.

    Helping out to write simple C# functions, of the syntax I forgot of top of my head, but that I know terms.

    In fact, ChatGPT gave me in number of occasions results, of functions which I would need to go through docs.

    Helping investigate other API integration into Unity and getting answers, which are not prominent in search engine.

    Finding answers to C# parameters meaning of methods and examples of use cases. Often officially not well, or undocumented.

    Using ChatGPT for assisting in structuring various of documents, with positive outcome after documents were finalized.


    In the end, I am saving hrs on researching subjects and accelerating, prototyping and integration.
    I wouldn't however rely on production ready code. That is out of scope for ChatGPT.


    Additionally:
    See this Unity post for relevance.
    What generative AI tools are you currently using in your workflow?

    Also I will post this quote as it is good, for understanding what we deal with.

     
    andyz likes this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,317
    Useful programming queries I ran into:

    "Give me an example/overview of language X" or "Provide sample implementation of X in language Y".

    "Review this regexp". (it actually managed to optimize regexp, which was surprising)

    "What is this function doing/verify algorithm"

    Like Antypodish said, the best application is initial research. I've also stumbled upon unknown syntax bits by accident when chatting with it.

    Trying to make it program or trying to replace a human programmer with it, however, is not a very good idea.
     
  4. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    590
    You may find copilot to be even better for stuff like that since you can do it inline your IDE and many times it will give the suggestions without you prompting for it!
     
  5. Taro_FFG

    Taro_FFG

    Joined:
    Jun 24, 2022
    Posts:
    57
    Refactors within a single file using CodeGPT plugin for Rider with GPT-4 model.

    For example splitting big functions into proper pieces or refactor an existing function when adding a new parameter that requires some logic changes, for example requiring backwards collection iteration, applying a refactor to a class to switch container types in a class, for example change from List to LinkedList requires using different access operators.

    Create mapping objects, for example map a c# code enum for language selection settings to unity locales or map networking serialization objects to runtime objects.

    Creating prototype solutions to a feature I want to add.
    In some cases it is much faster for me to work or reject an approach based on a simple first draft implementation.

    In general it should work for you, not think for you.
     
  6. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,128
    GitHub Copilot?
    Visual Studio is very good at suggesting lines of code now - when it works (can be bit buggy VS...). I have not tried copilot so not sure what it provides on top
     
  7. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    1,754
    Have you also evaluated Copilot/CopilotX? I wonder how that compares to CodeGPT.
     
    DragonCoder likes this.
  8. Taro_FFG

    Taro_FFG

    Joined:
    Jun 24, 2022
    Posts:
    57
    I'm using Copilot as well, Copilot is really only usefull for simple code completion tasks because you can not direct it.
    But for the completion tasks it is typically faster to work with.

    CodeGPT and CopilotX fill the same nieche meaning directed more long form tasks.
    With the CodeGPT plugin you mark sections of your code and add a query to GPT-4 to answer with something.

    I did test CopilotX as well. Felt roughly similar to me in effective output to CodeGPT but a bit less directed because it seems Github is pulling more sections than just current files/code blocks which can be positive but also misslead the text generator.
    Latest version of CodeGPT has a button to replace current selected code with code blocks generated from GPT4 so if you ask it "Refactor me this function to do X/follow Y pattern" and you like the response you can just click a button and it is in your project.

    Having to use VSCode and especially the nightly version is a big no-no for me so I wouldn't use it unless they also bring it to Rider.
    In the long run CopilotX is probably going to outperform CodeGPT since the latter is really only a small UI wrapper for GPT4 API and no automated context handling.
     
  9. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,128
    Maybe you all use Rider but VS has/has IntelliCode for line completion: uses a large scale transformer model, trained on around half a million public open-source repos from GitHub (GPT-C code-based model).

    But I actually don't know what happened...
    Edit: Ah this is optional install - was missing on new pc. Do install it for free help - really speeds up some work!
     
    Last edited: Jul 21, 2023
  10. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    590
    Yeah, Github Copilot. It is better than the normal "intellisense" in generating larger blocks of codes. For example if you add a comment to a class signature it can generate the whole class (similar to asking chat gpt to create classes), however it can do it in-line in the editor.

    Obviously generating an entire class produces lower quality results as it doesn't know exactly what you want, but you can do the same for methods or blocks of code (i.e. write a small comment and have it generate the code).

    I like that it's better than auto complete in many situations, especially for writing boilerplate code or creating code for standard C.R.U.D. stuff (such as setting UI element values for TMP, images, etc). It's not super 'smart' but I find it saves me a lot more time than $10/month.
     
    DragonCoder and andyz like this.
  11. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,955
Thread Status:
Not open for further replies.