openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Is there a way to detect source code in ChatGPT responses ?

Open anhhtca opened this issue 2 years ago • 0 comments

Describe the feature or improvement you're requesting

Hello,

Is there a way to detect source code in ChatGPT responses ?

Example:

  • Prompt: how to write hello world using c#
  • Reposnse:
{
    "id": "cmpl-xxx",
    "object": "text_completion",
    "created": 1675398039,
    "model": "text-davinci-003",
    "choices": [
        {
            "text": "\n\nThis code below will print the phrase \"Hello world\" to the screen using the C# language.:\n\nusing System;\n\nnamespace HelloWorld\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Console.WriteLine(\"Hello World!\");\n        }\n    }\n}",
            "index": 0,
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 123,
        "completion_tokens": 123,
        "total_tokens": 123
    }
}

I need to parse and format the source code in `text', like that:

================================================= This code below will print the phrase "Hello world" to the screen using the C# language:

using System;

public class HelloWorld 
{ 
    public static void Main() 
    { 
        Console.WriteLine("Hello World!"); 
    } 
}

================================================= Thanks in advanced !

Additional context

No response

anhhtca avatar Feb 03 '23 04:02 anhhtca