gptQuestion

gptQuestion ( string decription , string _api_key , string _model , float _temperature , int _maxTokens , int[default:300sec] _timeout , bool[default:false] _debug , float[default:1] _delayBetweenRequests , int[default:2] _maxGenerations ) : string

Generate answers with artificial intelligence. You can ask any kind of question. The model is very convincing and the answers are of high quality. Use the Playground to make some tests.

Pricing

To control your costs, please consult this page: https://openai.com/api/pricing/. The API is really cheap. You buy "tokens" for about $0.002 / 1000 tokens in gpt3.5-turbo. 1,000 tokens is about 750 words. In general a question query is between 20 and 200 words, so the price is between $0.04 and $0.4 per thousand questions. You can see here your usage.

idIA Tech provides you with an OpenIA fee calculator to help you size up your projects.

The OpenIA API is chargeable from the first prompt. To use it, open an OpenIA account, then add a credit card in Billing. You also need to activate the automatic top-up (e.g. add €30 if you have less than €5 credit) and pre-load the account with a little credit.

Example

console( gptQuestion("""Create a description for a product for an e-commerce site with the following characteristics:
Category: Chainsaws
Name : MS 180
Technical characteristics :
Displacement 31.8 cm3
Power 1,4 kW
Weight 4,1 kg 1)
Bar length 35 cm
CO2 859 g/kWh""","sk-CymZ59RdjCiNwSzGAVndgbkFJJGwhAtt5jqhcaW7gBFj", "text-davinci-003", 0.3) )
/*
The MS 180 chainsaw is a powerful and lightweight saw that is perfect for a variety of tasks. It has a displacement of 31.8 cm3 and a power of 1.4 kW. It also has a bar length of 35 cm and a weight of 4.1 kg.
*/

console( gptQuestion("""Create a variation of this product description for an e-commerce site:
The BR 550 backpack blower offers an excellent power to comfort ratio. With 4-MIX® motor, anti-vibration system for long working sequences and ergonomic top of the range harness for maximum comfort.""","sk-CymZ59RdjCiNwSzdVncT3BlbkFJfddfAtAr5jq7caW7gBFj") )
/*
The BR 550 backpack blower is a great choice for those who want a powerful blower with a comfortable design. The 4-MIX® motor provides plenty of power, while the anti-vibration system ensures that you won't get tired while using it. The ergonomic top of the range harness ensures maximum comfort while you're working.
*/
Simple rule to protect your request against too big prompt:
maxModelToken = 4096
prompt = """Create a variation of this text $text"""
maxPromptLenght = (count(prompt) / 0.75) - 500 //(count(prompt) / 0.75) is the number of tokens of the prompt and we keep 500 tokens for the completion
myVariation = gptQuestion(substring(maxPromptLenght, 0, maxPromptLenght), api_key, myModel)


Debugging tip

Track requests with HttpToolkit

Advice

On Prestashop, it has been found that the backoffice can be buggy due to the absence of HTML or <p> tags surrounding the description. Add these elements correctly.
description = "<p>"+nl2br(gptQuestion("$promp_gpt_description_ : $origianl_description", gptApiKey))+"</p>"

Parameters

decription

A question, a sentence to complete, an equation to solve, a computer code to create. Speak here as if you were a human being.

_api_key (optional)

the OpenIA API token, you can have it here.
Instead of the OpenIA token, you can use a Cloud idIA Tech code to avoid having to open several accounts. In this case, fill in your Cloud code in the usual way and set _api_key to null. You can also explicitly declare your Cloud code in the _api_key argument with a prefix in the form "idiatech_12345678" where 12345678 is your Cloud code.

_model (optional)

Default: "gpt-4o-mini". The artificial intelligence model that will understand what you write. Chose a model (only the templates listed in /v1/completions or in /v1/chat/completions can be used). Some popular models: "gpt-4", "gpt-4-32k", "gpt-3.5-turbo", "text-davinci-003". As far as costs are concerned, all these models cost about the same (around $2 per million tokens), but there is one exception, switching to gpt4 models multiplies the cost by 20! This is still generally low in terms of operational costs, however.

_temperature (optional)

The temperature controls the amount of randomness in the output. It conditions the level of originality allowed. Set it to the range 0 (unoriginal) to 1 (very permissive). Default value : 0.5

_maxTokens (optional)

If you leave the default value, the maximum number of tokens in the model is budgeted (minus the estimated number of tokens of description). One token corresponds to approximately one word or about 4 letters. This setting allows you to control your expenses, as you are billed per token. For each request, you spend the number of tokens and the response plus the number of the request..

_timeout (optional)

In seconds. Maximum response time from OpenIA.

_debug (optional)

Use it to see JSON response from the API.

_delayBetweenRequests (optional)

Delay in seconds between OpenIA requests (to avoid timeouts). You must respect the recommendations for your account, which are given here. Pay particular attention to the RPM (Requests per minute).

_maxGenerations (optional)

It may happen that your prompts require a very long response from the model. But the maximum number of tokens often interrupts the response in this case. It is then possible to continue generation on a new message and attach it. _maxGeneration defines the maximum number of times this operation is allowed. For example, if _maxGeneration = 2, the first generation will be carried out, followed by 2 generations of continuation messages.