1. Summarizing and editing text
Let's now explore the types of tasks that can be completed by DeepSeek models.
2. Recap...
So far, we've used DeepSeek's chat model to answer questions and follow simple instructions.
Now, let's use these models to transform text, with text editing and summarization.
3. Text editing
First, let's explore text editing.
Let's use a chat model to update the name, pronouns, and job title in a biography.
Notice that the prompt starts with the instruction, then the text to edit.
We've also used triple quotes to define a multi-line prompt for ease of readability and processing.
4. Text editing
Then, as before, we send this prompt to the model under the "content" key of a user message.
Voilà! We have our updated text. This approach is much more flexible than your standard find-and-replace tool.
5. Text summarization
Next, let's explore text summarization.
Imagine you work for a large company with millions of customers.
The customer support team asks for short summaries of customer chats to track performance and improve customer satisfaction.
They provide a chat transcript stored as a string.
6. Text summarization
To summarize it, we'll craft a prompt that clearly asks for a concise summary, and use an f-string to insert the text variable.
F-strings are denoted with an "f" before the opening quotes, and they essentially convert Python objects into strings and insert them in one go.
We pass this prompt to the model,
and there it is!
The AI generates a clear summary, allowing us to grasp the conversation's main points without reading the entire transcript.
Imagine how helpful this would be when dealing with thousands of support chats!
7. Controlling response length
What if the generated summary is too short?
The max_tokens parameter can be used to control the maximum length of the response, shortening or lengthening it.
8. Understanding tokens
Tokens are a unit of one or more characters used by language models to understand and interpret text.
Here, we can see how the model would encode this sentence as tokens to process it on input.
When we set max_tokens, it's an upper limit on the number of tokens the model will output.
9. Calculating the cost
Now, let's talk about cost.
Outside of this course, using DeepSeek models via an API incurs a cost based on the platform hosting the API, the model chosen, and the number of tokens processed.
Each model has a price per token, and for some models, the input and output tokens may have different prices.
So, increasing max_tokens likely means higher costs per request.
10. Calculating the cost
Let's calculate the cost for our previous summary request with a max_tokens of 500.
11. Calculating the cost
First, we need the price per token for input and output tokens.
Since the pricing is per million tokens, in this case, we divide by one million to get the cost per token.
We also need the total number of tokens used in the request.
The input token count is found in the API response under .usage.prompt_tokens.
For output tokens, we typically assume the max_tokens value as an upper bound, as there can be variation between requests.
We multiply each cost per token by the number of tokens and sum the result.
That's small, but for longer documents and different models, costs can very quickly add up.
Always estimate costs before deploying AI features at scale.
12. Let's practice!
Now it's your turn!