passionweb/open-ai-api

Shows the usage of the OpenAI API. Sends an example request with the entered prompt.

1.0.0 2023-08-25 07:27 UTC

This package is auto-updated.

Last update: 2023-09-25 07:39:33 UTC


README

Shows the integration of the OpenAI API. (TYPO3 CMS)

What does it do?

Adds a plugin to send a prompt to the OpenAI API and displays the generated answer.

Installation

Add via composer:

composer require "passionweb/open-ai-api"
  • Install the extension via composer
  • Flush TYPO3 and PHP Cache

Requirements

This example uses the OpenAI API.

Extension settings

There are the following extension settings available.

openAiApiKey

# cat=API Key; type=string; label=OpenAI Secret Key
openAiApiKey = YOUR_API_KEY

Enter your generated OpenAI API key.

openAiModel

# cat=basic request settings; type=string; label=OpenAI Model
openAiModel = gpt-3.5-turbo

The id of the model which will generate the completion. See models overview for an overview of available models.

openAiTemperature

# cat=basic request settings; type=double+; label=OpenAI Temperature
openAiTemperature = 0.5

What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

openAiMaxTokens

# cat=basic request settings; type=int+; label=OpenAI Max-Tokens
openAiMaxTokens = 275

The token (what are tokens and how to count them) count of your prompt plus max_tokens cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).

openAiTopP

# cat=basic request settings; type=int+; label=OpenAI Top-P
openAiTopP = 1

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.

openAiFrequencyPenalty

# cat=basic request settings; type=double; label=OpenAI Frequency Penalty
openAiFrequencyPenalty = 0.8

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

openAiPresencePenalty

# cat=basic request settings; type=double; label=OpenAI Presence Penalty
openAiPresencePenalty = 0

Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

Troubleshooting and logging

If something does not work as expected take a look at the log file. Every problem is logged to the TYPO3 log (normally found in var/log/typo3_*.log)

Achieving more together or Feedback, Feedback, Feedback

I'm grateful for any feedback! Be it suggestions for improvement, requests or just a (constructive) feedback on how good or crappy this snippet/repo is.

Feel free to send me your feedback to service@passionweb.de or contact me on Slack