How to optimize your OpenAI API token usage: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
(Created page with " == Prevent Sending Duplicate Content to the OpenAI API == * [https://errerrors.blogspot.com/2023/08/how-to-find-duplicate-text-values-in-mysql.html MySQL 如何尋找重複...")
 
No edit summary
Line 1: Line 1:
How to optimize your OpenAI API token usage


== Prevent Sending Duplicate Content to the OpenAI API  ==
== Prevent Sending Duplicate Content to the OpenAI API  ==
Line 32: Line 33:


<pre>
<pre>
Please select one of the following keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
Please select the of the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
```
```
Long text of article No.1
short text of article No.1
```  
```  
</pre>
</pre>
Line 40: Line 41:
another prompt:
another prompt:
<pre>
<pre>
Please select one of the following keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
Please select the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
```
```
Long text of article No.2
short text of article No.2
```  
```  
</pre>
</pre>
Line 48: Line 49:
Refined prompt:
Refined prompt:
<pre>
<pre>
Each row is the article number and content. For each article, select one of the keywords: keyword1, keyword2, keyword3, keyword4, keyword5. Provide your answer in the CSV format: "article number", "comma_separated_keywords"
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. Long text of article No.1 (without return symbol)
No1. short text of article No.1 (without return symbol)
No2. Long text of article No.2 (without return symbol)
No2. short text of article No.2 (without return symbol)
...
...
No3. Long text of article No.3 (without return symbol)
No5. short text of article No.5 (without return symbol)
```  
```  
</pre>
</pre>
Line 61: Line 62:


Prepare several sample texts and verify the API results to ensure they are as expected before processing a large number of articles.
Prepare several sample texts and verify the API results to ensure they are as expected before processing a large number of articles.
== 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. For more information, please refer to the following article: [OpenAI API Models](https://platform.openai.com/docs/models).


== Related pages ==
== Related pages ==
* [[Troubleshooting of OpenAI API]]
* [[Troubleshooting of OpenAI API]]
== Further reading ==
* [https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api Best practices for prompt engineering with OpenAI API | OpenAI Help Center]


[[Category:OpenAI]]
[[Category:OpenAI]]

Revision as of 11:20, 13 August 2023

How to optimize your OpenAI API token usage

Prevent Sending Duplicate Content to the OpenAI API

Streamlining Questions and Responses

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, consider refining your question by providing specific and limited options for the AI to select from.

For example:

  • Initial question for exploration:
Please offer five keywords for the following articles:

```
Long text
``` 
  • Refined question:
Please select one of the following keywords: keyword1, keyword2, keyword3, keyword4, keyword5, for the subsequent articles:

```
Long text
``` 


Handling Multiple Article Packages

original promot

Please select the of the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
```
short text of article No.1
``` 

another prompt:

Please select the keywords for the subsequent articles: keyword1, keyword2, keyword3, keyword4, keyword5.
```
short text of article No.2
``` 

Refined prompt:

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)
``` 

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.

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:

For the subsequent articles, please select from the keywords: keyword1, keyword2, keyword3, keyword4, keyword5. No further explanation required.
```
Long text
``` 


Select the appropriate model

For complex tasks, GPT-4 is recommended, while simpler tasks like translation can utilize GPT-3.5. For more information, please refer to the following article: [OpenAI API Models](https://platform.openai.com/docs/models).


Related pages

Further reading