Delphi-PRAXiS
Seite 3 von 15     123 4513     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Werkzeuge (https://www.delphipraxis.net/63-sonstige-werkzeuge/)
-   -   Programme bzw. Funktionen von KI schreiben lassen (OpenAI) (https://www.delphipraxis.net/212082-programme-bzw-funktionen-von-ki-schreiben-lassen-openai.html)

himitsu 15. Dez 2022 20:04

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
"schreib ein Programm, was Dieses und Jenes macht"

"erstelle ein Betriebssystem in Delphi"

geht nicht, weil

Zitat:

Whoa there! You might need to wait a bit.

Currently we are receiving more requests than we are are comfortable with! To try your request again, come back in a short while and reload this page.

Harry Stahl 15. Dez 2022 22:42

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Also ich fand, die Sache ist es wert, mal wieder ein kurzes Video zu machen.

Dort bin ich auch mal der Frage nachgegangen, ob man auch .dfm Dateien oder auch passende Projekt-Dateien direkt von der AI erstellen lassen kann.

Was dabei herausgekommen ist, könnt Ihr Euch hier ansehen: https://youtu.be/d9TZ6LUWqOs

API 16. Dez 2022 09:26

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Me: Create a Delphi console application that implements a chatbot

Chatbot: Sure! Here is an example of how you can create a simple chatbot in Delphi using the console application:

Delphi-Quellcode:
program Chatbot;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  input: string;

begin
  WriteLn('Hello, I am a chatbot. How can I help you today?');

  while True do
  begin
    Write('You: ');
    ReadLn(input);

    if input = 'exit' then
      Break;

    case input of
      'hi', 'hello':
        WriteLn('Chatbot: Hi there! How are you doing?');
      'how are you':
        WriteLn('Chatbot: I am just a computer program, so I don''t have feelings. But I am here to assist you.');
      'what can you do':
        WriteLn('Chatbot: I can answer questions, provide information, and carry out simple tasks. Is there anything specific you would like to know or do?');
      else
        WriteLn('Chatbot: I am sorry, I didn''t understand your question. Could you please rephrase it or ask for something else?');
    end;
  end;
end.
This chatbot will greet the user and then enter into a loop where it will continually read the user's input and respond with a predefined message. The chatbot can understand and respond to a few specific phrases, such as "hi", "hello", "how are you", and "what can you do". If the user enters any other phrase, the chatbot will respond with a default message.

To exit the chatbot, the user can type "exit".

I hope this helps! Let me know if you have any questions or need further assistance.

Me: Now let's add a functionality to the chatbot so it will be able to do some simple math operations.


Chatbot:

Sure! Here is an example of how you can modify the chatbot to perform simple math operations:

Delphi-Quellcode:
program Chatbot;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

var
  input: string;
  num1, num2: Integer;
  result: Real;

begin
  WriteLn('Hello, I am a chatbot. How can I help you today?');

  while True do
  begin
    Write('You: ');
    ReadLn(input);

    if input = 'exit' then
      Break;

    case input of
      'hi', 'hello':
        WriteLn('Chatbot: Hi there! How are you doing?');
      'how are you':
        WriteLn('Chatbot: I am just a computer program, so I don''t have feelings. But I am here to assist you.');
      'what can you do':
        WriteLn('Chatbot: I can answer questions, provide information, and carry out simple tasks. Is there anything specific you would like to know or do?');
      'add', 'sum':
        begin
          Write('Enter the first number: ');
          ReadLn(num1);
          Write('Enter the second number: ');
          ReadLn(num2);
          result := num1 + num2;
          WriteLn('Chatbot: The sum of the two numbers is ', result);
        end;
      'subtract', 'difference':
        begin
          Write('Enter the first number: ');
          ReadLn(num1);
          Write('Enter the second number: ');
          ReadLn(num2);
          result := num1 - num2;
          WriteLn('Chatbot: The difference of the two numbers is ', result);
        end;
      'multiply', 'product':
        begin
          Write('Enter the first number: ');
          ReadLn(num1);
          Write('Enter the second number: ');
          ReadLn(num2);
          result := num1 * num2;
          WriteLn('Chatbot: The product of the two numbers is ', result);
        end;
      'divide', 'quotient':
        begin
          Write('Enter the first number: ');
          ReadLn(num1);
          Write('Enter the second number: ');
          ReadLn(num2);
          if num2 = 0 then
            WriteLn('Chatbot: Cannot divide by zero!')
          else
          begin
            result := num1 / num2;
            WriteLn('Chatbot: The quotient of the two numbers is ', result);
          end;
        end;
      else
        WriteLn('Chatbot: I am sorry, I didn''t understand your question. Could you please rephrase it or ask for something else?');
    end;
  end;
end

API 16. Dez 2022 09:30

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Fortsetzung:

Me:

Are you able to refractor your code by moving redundant parts into functions?

Chatbot:

Sure! Here is an example of how you can refactor the chatbot to move the redundant parts into functions:

Delphi-Quellcode:
program Chatbot;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

function GetNumber(prompt: string): Integer;
var
  num: Integer;
begin
  Write(prompt);
  ReadLn(num);
  Result := num;
end;

function PerformOperation(op: string): Real;
var
  num1, num2: Integer;
begin
  num1 := GetNumber('Enter the first number: ');
  num2 := GetNumber('Enter the second number: ');
  case op of
    'add', 'sum':
      Result := num1 + num2;
    'subtract', 'difference':
      Result := num1 - num2;
    'multiply', 'product':
      Result := num1 * num2;
    'divide', 'quotient':
      if num2 = 0 then
        Result := NaN
      else
        Result := num1 / num2;
  else
    Result := NaN;
  end;
end;

var
  input: string;
  result: Real;

begin
  WriteLn('Hello, I am a chatbot. How can I help you today?');

  while True do
  begin
    Write('You: ');
    ReadLn(input);

    if input = 'exit' then
      Break;

    case input of
      'hi', 'hello':
        WriteLn('Chatbot: Hi there! How are you doing?');
      'how are you':
        WriteLn('Chatbot: I am just a computer program, so I don''t have feelings. But I am here to assist you.');
      'what can you do':
        WriteLn('Chatbot: I can answer questions, provide information, and carry out simple tasks. Is there anything specific you would like to know or do?');
      'add', 'sum':
        begin
          result := PerformOperation(input);
          if IsNaN(result) then
            WriteLn('Chatbot: Invalid input!')
          else
            WriteLn('Chatbot: The sum of the two numbers is ', result);
        end;
      'subtract', 'difference':
        begin
          result := PerformOperation(input);
          if IsNaN(result) then
            WriteLn('Chatbot: Invalid input!')
          else
            WriteLn('Chatbot: The difference of the two numbers is ', result);
        end;
      'multiply', 'product':
        begin

      // usw......
Me: It it looks like we could do some further refactoring

Chatbot macht dann weitere Verbesserungen..

DeddyH 16. Dez 2022 10:11

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Seit wann funktioniert case mit Strings (in Delphi, woanders geht das)?

himitsu 16. Dez 2022 10:34

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Jo, geil ... die KI kennt die Zukunft







nächstes Jahrtausend

API 16. Dez 2022 10:48

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Zitat:

Zitat von DeddyH (Beitrag 1516295)
Seit wann funktioniert case mit Strings (in Delphi, woanders geht das)?

Was das geht nicht resp. immer noch nicht? (Habe schon x Jahre lange nicht mehr in Delphi programmiert)

himitsu 16. Dez 2022 10:55

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
ja, kann leider immernoch nur Ordinal :cry:

Sherlock 16. Dez 2022 11:57

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Der spannende Teil wäre dann dem Bot die Fehlermeldung zu geben und ihn bitten, den Code zu korrigieren. Wie ich gehört und gelesen habe, soll das auch gehen.

Sherlock

Ralf Kaiser 16. Dez 2022 12:11

AW: Programme bzw. Funktionen von KI schreiben lassen (OpenAI)
 
Man kann mit ChatGPT sozusagen über den Code diskutieren und es ändert den Code dann entsprechend ab. Ich hatte mal verschiedene Aufgaben aus dem Bereich Netzwerkprogrammierung gestellt. Die Lösung war eine Funktion die mit Indy arbeitete.

Ich hab dann eingegeben "How would that function look if i do not want to use indy?" ind ChatGPT hat den Code geändert, so dass er mit System.Net Funktionen arbeitete.

Man kann sich also an die gewünschte Lösung heran tasten ("Do not use strings in the code", Ergebnis: ChatGPT hat alles auf die Benutzung von PChars geändert). Ist wirklich interessant.


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:00 Uhr.
Seite 3 von 15     123 4513     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz