callgpt¶
- call_gpt(prompt, max_attempts=10, model='gpt-3.5-turbo-16k', max_tokens=None, verbose=True, delay_seconds=2)¶
Calls the OpenAI GPT API with the given prompt.
- Parameters:
prompt (str) – The prompt to send to the GPT API.
max_attempts (int) – The maximum number of attempts to make if the API call fails. Defaults to 10.
model (str) – The GPT model to use. Defaults to “gpt-3.5-turbo-16k”.
max_tokens (int or None) – The maximum number of tokens to generate. If None, uses the value from the ‘.local/openai.json’ file.
verbose (bool) – Whether to print the GPT response. Defaults to True.
delay_seconds (int) – The number of seconds to wait between attempts. Defaults to 2.
- Returns:
The GPT response.
- Return type:
str
- Raises:
Exception – If the API call fails after the maximum number of attempts.
- get_decoded_token_list(input, model='gpt-3.5-turbo-16k')¶
Encodes the given input string into tokens using the specified model’s encoding and then decodes each token back to a string.
- Parameters:
input (str) – The input string to encode.
model (str) – The name of the model whose encoding should be used. Defaults to “gpt-3.5-turbo-16k”.
- Returns:
A list of decoded tokens.
- Return type:
list[str]