ChatGPT integration examples?

This forum is meant for examples of X# code.

VR
Posts: 98
Joined: Sun Aug 23, 2020 3:07 pm
Location: Italy

ChatGPT integration examples?

Post by VR »

Hi Robert...

I don't think, that you can "train" ChatGPT. OpenAI announced recently, that they will offer Plugins to allow ChatGPT to access new information.

An interesting alternative project is GPT4All (https://github.com/nomic-ai/gpt4all). It is open source and can be self hosted.

Volkmar
User avatar
Meinhard
Posts: 81
Joined: Thu Oct 01, 2015 4:51 pm

ChatGPT integration examples?

Post by Meinhard »

Hi Robert,

>Does anybody know how to "train" ChatGPT?

was asking this myself, so I asked ChatGpt :):
"How can i teach you a new programming lanugage?"

Answer:

"As an AI language model, I can learn new programming languages, but I require access to high-quality training data and extensive computing resources to do so effectively.

If you have specific resources or materials you would like me to use for learning a new programming language, you can provide them to me, and I can use them to improve my understanding of the language. Additionally, you can provide feedback and corrections as I generate code or answer programming-related questions in the new language.

Keep in mind that my training and capabilities are limited by my current architecture, so I may not be able to learn or perform certain tasks in a new language that is not supported by my architecture."

Looks like a valid answer, but not very helpful though, so let's asks more precisely:

"Which steps do I need to do in order to teach you a programming language?"

Answer:
"To teach me a new programming language, here are some steps you can take:

Gather high-quality training data: The first step in training an AI model like me is to gather high-quality training data. This could include code snippets, code samples, documentation, tutorials, and other resources in the new programming language.

Organize the data: Once you have collected the data, you will need to organize it into a format that can be used to train an AI model. This may involve cleaning and pre-processing the data to remove noise, standardize the format, and prepare it for ingestion into the training pipeline.

Train a model: Once you have prepared the data, you can use it to train a new model or fine-tune an existing one to learn the new programming language.

Evaluate the model: After training, you will need to evaluate the performance of the model to ensure it is accurate and effective at generating code in the new programming language.

Fine-tune the model: Based on the results of the evaluation, you may need to fine-tune the model to improve its performance or to address any issues that arise during testing.

Test the model: Once you have fine-tuned the model, you can test it in a variety of scenarios to ensure it is accurate and effective at generating code in the new programming language.

Provide feedback: As the model generates code or answers programming-related questions in the new programming language, you can provide feedback and corrections to help improve its accuracy and effectiveness.

Please note that this is a high-level overview of the process, and the actual steps involved may vary depending on the specific programming language and training data you are working with."

This looks way more interesting. There are some guides available how to train a model, but I wonder if it is worth the work. Anyway, if you ask for translation :

"Can you translate this c# code to x#:
var request = new RestRequest(Method.POST);
request.Headers.Add("Content-Type", "application/json");"

It already gives you quite good results:

"LOCAL request := RestRequest{Method:=Method.POST}
request.Headers:Add("Content-Type", "application/json")"

Look good but there's a little glitch, the '.' before Headers should be ':'. Let's tell this to ChatGpt and regenerate:

"If request is an object instance and Headers is an instance property it should read request:Headers. Please regenerate"

Answer:
"You're correct, thank you for catching that mistake. Here's the corrected X# code:
LOCAL request := RestRequest{Method:=Method.POST}
request:Headers:Add("Content-Type", "application/json")

In X#, the : syntax is used to access instance members, including properties and methods. In this case, Headers is an instance property of the RestRequest object, so it should be accessed using the : syntax."

Impressive, so it already has a certain understanding of what X# is and looks like :)

Regards
Meinhard
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am

ChatGPT integration examples?

Post by jonhn »

Thanks Wolfgang,
I have set up a paid account and the message has changed! It is exactly what I was expecting but it is definitely progress. I prompted it that my name was Frank and asked if it knew any other Franks, and asked for 5 options.

{"id":"cmpl-7C2oXIPLI0jsTFvGOjsX0OJ1RoBuC","object":"text_completion","created":1683105109,"model":"text-davinci-002","choices":[{"text":"nnHello Frank, I do not know of any other Franks.","index":0,"logprobs":null,"finish_reason":"stop"},{"text":"nnYes, I know a few other Franks.","index":1,"logprobs":null,"finish_reason":"stop"},{"text":"nnHello, Frank. I do not know any other Franks.","index":2,"logprobs":null,"finish_reason":"stop"},{"text":"nnNo, but I'm sure there are other people out there with the same name.","index":3,"logprobs":null,"finish_reason":"stop"},{"text":"nnYes, I know a few other Franks.","index":4,"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":18,"completion_tokens":69,"total_tokens":87}}
User avatar
robert
Posts: 4255
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ChatGPT integration examples?

Post by robert »

Meinhard,
Meinhard post=26132 userid=300 wrote: Impressive, so it already has a certain understanding of what X# is and looks like :)
I am sure that if many of us try this and help it to correct mistakes, then it will quickly learn and improve.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
IKavanagh

ChatGPT integration examples?

Post by IKavanagh »

robert post=26136 userid=253 wrote:Meinhard,
Meinhard post=26132 userid=300 wrote: Impressive, so it already has a certain understanding of what X# is and looks like :)
I am sure that if many of us try this and help it to correct mistakes, then it will quickly learn and improve.

Robert
I used ChatGPT to write X# code back in February but it's not as helpful as having GitHub Copilot write X#, C#, etc.. I've been using GitHub Copilot since it was released, it's X# knowledge was non-existent at the start but now it is context aware within our codebase and suggestions are getting much better even if it is just finishing an IF with ENDIF.

Arguably, training ChatGPT to be able to write X# isn't as useful as training GitHub Copilot, Codeium or any of the other programming specific "AI"s.
User avatar
wriedmann
Posts: 3655
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

ChatGPT integration examples?

Post by wriedmann »

Hi Ian,
thank you very much for sharing your experience!

Hi Robert, hi Chris (XIDE, do you know it?),

IMHO that would be an idea to check out that and provide some AI as helper when writing code....

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4255
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ChatGPT integration examples?

Post by robert »

Ian,
IKavanagh post=26267 userid=4736 wrote:
robert post=26136 userid=253 wrote:Meinhard,
Meinhard post=26132 userid=300 wrote: Impressive, so it already has a certain understanding of what X# is and looks like :)
I am sure that if many of us try this and help it to correct mistakes, then it will quickly learn and improve.

Robert
I used ChatGPT to write X# code back in February but it's not as helpful as having GitHub Copilot write X#, C#, etc.. I've been using GitHub Copilot since it was released, it's X# knowledge was non-existent at the start but now it is context aware within our codebase and suggestions are getting much better even if it is just finishing an IF with ENDIF.

Arguably, training ChatGPT to be able to write X# isn't as useful as training GitHub Copilot, Codeium or any of the other programming specific "AI"s.
Are you planning to come to Memmingen in October?
Are you willing to do a session to demonstrate how CoPilot works?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

ChatGPT integration examples?

Post by info@task.si »

Hi all !
I will also join the conversation with some of my impressions. First of all, I managed to build a MAUI application that connects to the ChatGPT 3.5 transformer engine via the OpenAI API. I even used ChatGPT to help me build this application, screen grabs of which are attached in the appendix. After my unsuccessful 4 hour attempt to enter the correct command line, I asked ChatGPT and got the correct answer. Having been learning Blazor for three years now, I have to admit that if I had this generator, it would have saved me at least a year of learning. Because it would have guided me on the right path.
All my claims below are based on the fact that I am accessing the OpenAI platform directly, not using Microsoft Bing or other portals.
a) Since ChatGPT is AI you have to allow it to self-correct on an ongoing basis, for the duration of your session. So. if you notice that he has given the wrong answer, you have to point it out to him and they will move to a new level, to a new level of correspondancy.
I have also noticed that he may answer the same question slightly differently.
b) I also have GPT-4, which gives different answers to the same question you ask ChatGPT 3.5. Of course, if it is a professional question, not a "what's the weather like today" question. This is of course because ChatGPT 3.5 is based on knowledge and learning until 2021.
c) In the future, I will also work a lot on Machine Learning (probably a way to teach GPT), as I would like to build good models for predictive maintenance based on big data.
d) On the screen grabs take a look and the difference between two of my questions.
e) For those who are interested. My app is running on MAUI platform, this means also on smartphones.

Regards, Andrej
Attachments
ChatGPT_2023_06.png
ChatGPT_2023_06.png (129.06 KiB) Viewed 1350 times
ChatGPT_2023_04.png
ChatGPT_2023_04.png (91.82 KiB) Viewed 1350 times
jonhn
Posts: 86
Joined: Thu Feb 01, 2018 8:04 am

ChatGPT integration examples?

Post by jonhn »

Here is what I ended up with for my experiment / test - just using a simple Winform with two text boxes, one for the query to be entered and one for the response. It works well but as Wolfgang says there is some more work to handle errors and add the finishing touches. Getting the prompt tuned properly for what I was trying to automate in my application is more complex and it might not ever be used, but but it is nice now having an AI window available in the Help menu.

USING Newtonsoft.Json.Linq
USING RestSharp

METHOD PBOpenAIClick(sender AS System.Object , e AS System.EventArgs) AS VOID
LOCAL json, cBody, MyPrompt AS STRING

VAR client := RestSharp.RestClient{ "https://api.openai.com/v1" }
VAR request := RestSharp.RestRequest{ "engines/text-davinci-002/completions", Restsharp.Method.POST }

request:RequestFormat := RestSharp.DataFormat.Json
request:AddHeader("Authorization", "Bearer sk-<Your ChatGPT key>")
request:AddHeader("Content-Type", "application/json")

MyPrompt := AllTrim(SELF:oTextBoxPrompt:Text)

text TO cBody
{ "prompt" : %s, "max_tokens" : 1000, "n" : 1 }
endtext

cBody := StrTran(cBody, "%s", '"' + MyPrompt + '"')
request:AddJsonBody( cBody )

VAR response := client:Execute(request)
VAR content := response:Content

LOCAL responseObj AS JObject
responseObj := JObject.Parse(response:Content)

// get the "text" value from the first element of the "choices" array
VAR text := (STRING)responseObj["choices"][0]["text"]

SELF:oTextBox1:Text :=text
info@task.si
Posts: 31
Joined: Mon Nov 02, 2015 2:08 pm

ChatGPT integration examples?

Post by info@task.si »

Hi

Congratulations, Jonathan. I see you have made a lot of progress with X# since last November. If you look at my screen grab #2, you actually followed the ChatGPT instructions, using the X# language of course. This is a good example of how AI can be very useful to us as programmers.
I didn't use the RestSharp assembly in my application, I followed theOpenAI web site instruction and therefore used the OpenAI-DotNet (6.7.3) NuGet package, because I'm working in the .NET 7 framework.
But your idea that you could use AI technology directly in your business is feasible. I'm currently working on this myself. I am exploring how to orchestrate ChatGPT within an application, or use "fine tuning" (prompt execution of app commands).
Regards, Andrej
Post Reply