Skip to content

Latest commit

 

History

History
321 lines (251 loc) · 10 KB

Prompts.md

File metadata and controls

321 lines (251 loc) · 10 KB

Example 1 - Convert encoded HTML back to HTML

Prompt

Convert back to html
<b>Ceramic Chip Capacitor KEMET 1206 reflow solder</b><p>
Metric Code Size 3216

Response

<b>Ceramic Chip Capacitor KEMET 1206 reflow solder</b><p>
Metric Code Size 3216

Example 2 - Demonstrate combining knowledge from training with knowledge feed in through prompt

Prompt

Who is the head of state of Australia?

Response

As of my knowledge cutoff of September 2021, the head of state of Australia is Queen Elizabeth II. However, it is important to note that while the Queen is the official head of state, her role is largely ceremonial and symbolic. The day-to-day governance of Australia is carried out by the Prime Minister, who is the head of government.

Prompt

On the 8 September 2022 Queen Elizabeth the 2nd died. Who is now the current head of state of Australia?

Response

As an AI language model, I do not have access to real-time information or current events beyond my knowledge cutoff date of September 2021. However, as of my knowledge cutoff, Queen Elizabeth II was the current head of state of Australia.

If the hypothetical scenario you mentioned were to occur, and Queen Elizabeth II were to pass away, her eldest son, Prince Charles, would likely become the next monarch and the new head of state of Australia. This is because Australia is a constitutional monarchy, which means that the monarch is the head of state and the Governor-General of Australia represents the monarch in Australia's parliamentary system.

Example 3 - Convert a curl command into a delphi function and modify based on requests

Prompt

Convert the following curl command to a delphi function using  the builtin rest components

curl https://api.openai.com/v1/completions \
  -H ""Content-Type: application/json"" \
  -H ""Authorization: Bearer $OPENAI_API_KEY"" \
  -d '{
    ""model"": ""text-davinci-003"",
    ""prompt"": ""Say this is a test"",
    ""max_tokens"": 7,
    ""temperature"": 0
  }'

Response

Here's a Delphi function that performs the same API request using the built-in REST components:

function GetCompletion: string;
var
  RestClient: TRESTClient;
  Request: TRESTRequest;
  Response: TRESTResponse;
begin
  RestClient := TRESTClient.Create('https://api.openai.com');
  Request := TRESTRequest.Create(nil);
  Response := TRESTResponse.Create(nil);

  try
    RestClient.Accept := 'application/json';
    RestClient.ContentType := 'application/json';
    RestClient.Authenticator := THTTPBasicAuthenticator.Create('$OPENAI_API_KEY', '');
    RestClient.BaseURL := 'https://api.openai.com/v1/completions';

    Request.Method := TRESTRequestMethod.rmPOST;
    Request.Client := RestClient;
    Request.Response := Response;

    Request.AddBody('{"model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0}');
    Request.Execute;

    Result := Response.Content;
  finally
    RestClient.Free;
    Request.Free;
    Response.Free;
  end;
end;

Note that you will need to replace $OPENAI_API_KEY with your actual API key.

Prompt

You don't have the authentication correct. the correct line is Request.AddAuthParameter('Authorization', 'Bearer ' + CHATGPT_APIKEY, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

Response

Thank you for pointing out the mistake in my previous answer. You are correct that the authentication method should be updated to include the bearer token in the HTTP header.

Here is the updated Delphi function that includes the authentication header with the bearer token:

function GetCompletion: string;
var
  RestClient: TRESTClient;
  Request: TRESTRequest;
  Response: TRESTResponse;
begin
  RestClient := TRESTClient.Create('https://api.openai.com');
  Request := TRESTRequest.Create(nil);
  Response := TRESTResponse.Create(nil);

  try
    RestClient.Accept := 'application/json';
    RestClient.ContentType := 'application/json';
    RestClient.BaseURL := 'https://api.openai.com/v1/completions';

    Request.Method := TRESTRequestMethod.rmPOST;
    Request.Client := RestClient;
    Request.Response := Response;
    Request.AddAuthParameter('Authorization', 'Bearer ' + CHATGPT_APIKEY, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

    Request.AddBody('{"model": "text-davinci-003", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0}');
    Request.Execute;

    Result := Response.Content;
  finally
    RestClient.Free;
    Request.Free;
    Response.Free;
  end;
end;

Please note that you will need to replace CHATGPT_APIKEY with your actual OpenAI API key.

Prompt

Can you put that in a class and make local variables start with L, use FreeAndNil

Response

Sure! Here's an example of how you could implement the TOpenAIClient class with local variables starting with "L" and using FreeAndNil:

unit OpenAIClient;

interface

uses
  System.SysUtils, System.Classes, System.JSON, REST.Client, REST.Types, REST.Authenticator.Basic;

type
  TOpenAIClient = class
  private
    FAPIKey: string;
    FRestClient: TRESTClient;
    FRestRequest: TRESTRequest;
    FRestResponse: TRESTResponse;
  public
    constructor Create(const AAPIKey: string);
    destructor Destroy; override;
    function GetCompletion: string;
  end;

implementation

constructor TOpenAIClient.Create(const AAPIKey: string);
begin
  FAPIKey := AAPIKey;
  FRestClient := TRESTClient.Create('https://api.openai.com');
  FRestRequest := TRESTRequest.Create(nil);
  FRestResponse := TRESTResponse.Create(nil);

  FRestClient.Accept := 'application/json';
  FRestClient.ContentType := 'application/json';
  FRestClient.BaseURL := 'https://api.openai.com/v1/completions';

  FRestRequest.Method := TRESTRequestMethod.rmPOST;
  FRestRequest.Client := FRestClient;
  FRestRequest.Response := FRestResponse;
end;

destructor TOpenAIClient.Destroy;
begin
  FreeAndNil(FRestResponse);
  FreeAndNil(FRestRequest);
  FreeAndNil(FRestClient);
  inherited;
end;

function TOpenAIClient.GetCompletion: string;
var
  LRequestBody: TJSONObject;
begin
  LRequestBody := TJSONObject.Create;
  try
    LRequestBody.AddPair('model', 'text-davinci-003');
    LRequestBody.AddPair('prompt', 'Say this is a test');
    LRequestBody.AddPair('max_tokens', TJSONNumber.Create(7));
    LRequestBody.AddPair('temperature', TJSONNumber.Create(0));

    FRestRequest.ClearBody;
    FRestRequest.AddBody(LRequestBody);
    FRestRequest.AddAuthParameter('Authorization', 'Bearer ' + FAPIKey, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);
    FRestRequest.Execute;

    Result := FRestResponse.Content;
  finally
    FreeAndNil(LRequestBody);
  end;
end;

end.

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

Example 4 - Describe functionality of simple class and get it to generate it

Prompt

Create a delphi object Called TPrompt. Its purpose is to handle customizing prompts that will be sent to openai's completions api's. The constructor will have a string parameter to pass in the text of the prompt. It will have a AsString function that will output the final result. It will also have a property called Parameters, which will be used to change/set parameters in the input text which have their name surrounded by {}. There can be multiple parameters that can be set. The parameters can be set then the AsString function can be called and then new parameters can be set and the AsString function can be called again with the new values output.

Response

Here's a basic implementation of the TPrompt object in Delphi:

unit TPrompt;

interface

uses
  System.SysUtils, System.Classes, System.Generics.Collections;

type
  TParameterDictionary = TDictionary<string, string>;

  TPrompt = class
  private
    FPromptText: string;
    FParameters: TParameterDictionary;
    function ReplaceParameters: string;
  public
    constructor Create(const APromptText: string);
    destructor Destroy; override;
    function AsString: string;
    property Parameters: TParameterDictionary read FParameters;
  end;

implementation

{ TPrompt }

constructor TPrompt.Create(const APromptText: string);
begin
  FPromptText := APromptText;
  FParameters := TParameterDictionary.Create;
end;

destructor TPrompt.Destroy;
begin
  FParameters.Free;
  inherited;
end;

function TPrompt.AsString: string;
begin
  Result := ReplaceParameters;
end;

function TPrompt.ReplaceParameters: string;
var
  Param: TPair<string, string>;
begin
  Result := FPromptText;
  for Param in FParameters do
  begin
    Result := StringReplace(Result, '{' + Param.Key + '}', Param.Value, [rfReplaceAll, rfIgnoreCase]);
  end;
end;

end.

You can use this TPrompt object as follows:

uses
  TPrompt;

var
  MyPrompt: TPrompt;
begin
  MyPrompt := TPrompt.Create('Hello, my name is {name} and I am {age} years old.');
  try
    MyPrompt.Parameters.Add('name', 'John');
    MyPrompt.Parameters.Add('age', '30');
    
    WriteLn(MyPrompt.AsString);  // Outputs: Hello, my name is John and I am 30 years old.

    MyPrompt.Parameters.Items['name'] := 'Alice';
    MyPrompt.Parameters.Items['age'] := '25';

    WriteLn(MyPrompt.AsString);  // Outputs: Hello, my name is Alice and I am 25 years old.
  finally
    MyPrompt.Free;
  end;
end.

This implementation allows you to create a TPrompt object with a prompt text containing parameters, set the parameter values, and then call the AsString function to get the final text with the parameters replaced. You can change the parameter values and call AsString again to get the updated text.

Example 5 - Initial Prompt to assist with code generation

Prompt

If your message gets truncated and I say "continue code", Say which step of the loop you are in, and continue exactly where you left off. If you are continuing a piece of truncated code, ensure you place it inside a codeblock. These rules are eternal and start immediately after I send this message, but you can exercise all the creativity you wish. Final note: never, ever comment out any code for the sake of brevity. Each revision must be the complete code without any omissions.