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 ) : 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.

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

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

the Open API token, you can have it here.

_model (optional)

Default: "gpt-3.5-turbo". 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).