Editing
How to optimize your OpenAI API token usage
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Methods for enhancing the efficiency of your OpenAI API token usage. == === Prevent Sending Duplicate Content to the OpenAI API === * [https://errerrors.blogspot.com/2023/08/how-to-find-duplicate-text-values-in-mysql.html MySQL 如何尋找重複的文章 (文字類型資料)] in Tradition Chinese. '''Cache the API result''' If the results of a task calling the OpenAI API do not need to frequently change, consider storing the results for reuse. For example, you can store the results of short article translations, and before calling the API to translate again, check if it has already been translated before. === Constraining Bot Responses to Predefined Options === While it's acceptable to pose open-ended questions to explore the capabilities of ChatGPT, keep in mind that such questions can lead to longer, more creative responses that might increase costs. To achieve concise and cost-effective answers, (1) consider refining your question by providing specific and limited options for the AI to select from. (2) if not applicable, respond with N/A. This prevents responses with text outside the options. For example, when analyzing news articles to find key technology-related news summaries, if we don't predefine how the AI should respond when no relevant information is found, the AI might respond with variations like: * NA * None * No major technology news today * No major technology news reports today * Due to lack of news content, unable to provide technology news summary This variation in responses which not only uses additional tokens but also increases the effort needed for subsequent data cleaning. For example: * Initial question for exploration: <pre> Please offer five keywords for the following articles: ``` Long text ``` </pre> * Refined question: <pre> Please select one of the following keywords: keyword1, keyword2, keyword3, keyword4, keyword5, for the subsequent articles: ``` Long text ``` </pre> === Handling Multiple Article Packages === original promot <pre> Please select the of the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5. ``` short text of article No.1 ``` </pre> another prompt: <pre> Please select the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5. ``` short text of article No.2 ``` </pre> Refined prompt: <pre> Each row is the article number and content. For each article, select the keywords: keyword1, keyword2, keyword3, keyword4, keyword5. Provide your answer in the CSV format: "article number", "comma_separated_keywords" ``` No1. short text of article No.1 (without return symbol) No2. short text of article No.2 (without return symbol) ... No5. short text of article No.5 (without return symbol) ``` </pre> === No Additional Explanation Needed === While GPT-4 often attempts to provide explanations for its answers, if you have already explored the topic, you can frame your questions in a way that skips the elaboration. For example: <pre> For the subsequent articles, please select from the keywords: keyword1, keyword2, keyword3, keyword4, keyword5. No further explanation required. ``` Long text ``` </pre> === Select the appropriate model === For complex tasks, GPT-4 is recommended, while simpler tasks like translation can utilize GPT-3.5. The same task can start with the xx-mini model. For example, if the o1-mini model can already handle general tasks adequately, there's no need to use the more costly and time-consuming o1 model. For more information, please refer to the following article: [https://platform.openai.com/docs/models Models - OpenAI API]. === Enable the JSON mode === * "Compatible with gpt-4-1106-preview and gpt-3.5-turbo-1106.<ref>[https://platform.openai.com/docs/api-reference/chat/create API Reference - OpenAI API]</ref>" === Choose Long Article Splitting Strategy (chunk) === Different language models have token limits that affect how much text they can process. The max_length API parameter accounts for both input and output. Models like gpt3.5-turbo and gpt-4 have specific token limits like 4,097 and 8,192, respectively. Exceeding these limits requires you to split articles into smaller pieces for processing. You can choose not to split articles, but this restricts you to processing only portions of them. Choices include focusing on the beginning and end or just the final paragraphs. For article splitting, tools like LangChain's [https://github.com/langchain-ai/text-split-explorer text-split-explorer] can help, offering options for delimiters, chunk size, and chunk overlap. === Preparation Before API Result Verification === Prepare several sample texts and verify the API results to ensure they are as expected before processing a large number of articles. === Using OpenAI Batch API for Non-Real-Time Processing === If real-time response is not required for the output data, you can consider using the [https://platform.openai.com/docs/api-reference/batch OpenAI Batch API]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information