So glad to see these responses! I was stuck in an airport and haven't been able to check until now. As for Pascal code generation. It's hit and miss. This is what I got when I asked it to generate a quiz application in Pascal just in the chat window, no api call (I couldn't get that to work).
program quizzer;
{$mode objfpc}{$H+}
uses
Sysutils, Classes, Crt;
type
TQuizQuestion = record
question: string;
answers: array[1..4] of string;
correctAnswer: char;
explanation: string;
end;
const
NUM_QUESTIONS = 10;
var
quiz: array[1..NUM_QUESTIONS] of TQuizQuestion;
i: integer;
f: TextFile;
answer: char;
tryagain: char;
Begin
AssignFile(f, 'quiz.txt');
try
Reset(f);
for i := 1 to NUM_QUESTIONS do
begin
ReadLn(f, quiz[i].question);
ReadLn(f, quiz[i].answers[1]);
ReadLn(f, quiz[i].answers[2]);
ReadLn(f, quiz[i].answers[3]);
ReadLn(f, quiz[i].answers[4]);
ReadLn(f, quiz[i].correctAnswer);
ReadLn(f, quiz[i].explanation);
end;
finally
CloseFile(f);
end;
repeat
ClrScr;
for i := 1 to NUM_QUESTIONS do
begin // Present the question and answers to the user
WriteLn(quiz[i].question);
WriteLn('1. ', quiz[i].answers[1]);
WriteLn('2. ', quiz[i].answers[2]);
WriteLn('3. ', quiz[i].answers[3]);
WriteLn('4. ', quiz[i].answers[4]);
// Get the user's answer
Write('Enter your answer: ');
ReadLn(answer);
// Check the user's answer
if answer = quiz[i].correctAnswer then
begin
WriteLn('Correct!');
WriteLn('Explanation: ', quiz[i].explanation);
end
else
begin
WriteLn('Incorrect.');
WriteLn('Correct answer: ', quiz[i].correctAnswer);
WriteLn('Explanation: ', quiz[i].explanation);
end;
end;
ClrScr;
Write('The Quiz is over. Do you want to try again? (y/n)?');
ReadLn(tryagain);
until tryagain <> 'y';
ClrScr;
End.
The format of your quiz.txt file must be as follows:
Question 1
Answer 1
Answer 2
Answer 3
Answer 4
3 (correct answer)
Explanation for correct answer
Question 2
Answer 1
Answer 2
Answer 3
Answer 4
1 (correct answer)
Explanation for correct answer
Question 3
Answer 1
Answer 2
Answer 3
Answer 4
2 (correct answer)
The correct answer is only a suggestion. Let me know if there is more I can help you with.
-----------------
I added {$mode objfpc}{$H+} compiled it and it ran.
I asked it to write out an Eliza program as well. That was pretty bad. I had to adjust the Respond method so that it would at least close properly. I did this about a week ago. Again, I had to add the compiler directives and I wanted the Crt unit.
program Eliza;
{$mode objfpc}{$H+}
uses
SysUtils, Classes, Crt;
const
GREETING = 'Hello! My name is Eliza. How are you feeling today?';
FAREWELL = 'Thank you for talking with me. Goodbye!';
var
input: string;
function GetInput: string;
begin
write('> ');
readln(Result);
end;
function IsGoodbye(input: string): boolean;
begin
Result := (input = 'goodbye') or (input = 'bye') or (input = 'quit');
end;
procedure Respond(input: string);
begin
case input of
'i feel': writeln('Why do you feel that way?');
'i am': writeln('Why are you feeling that way?');
'you': writeln('Why do you bring me up?');
'my': writeln('Tell me more about your situation.');
'i': writeln('Why do you say that?');
else
writeln('Please go on.');
end;
end;
begin
ClrScr;
writeln(GREETING);
repeat
input := GetInput;
Respond(Lowercase(input));
until IsGoodbye(Lowercase(input));
writeln(FAREWELL);
readln;
end.
Thanks to Thaddy for getting the api working. I also want to try and use codex. Getting to the api functionality now...