始める無料で始める

Coding with reasoning mode

Time for you to have a go at coding with DeepSeek V4-Pro's reasoning! As you may know, one important part of developing reliable code is to include tests, which validate that intermediate processes are running correctly before returning a final output. Well-written tests make debugging much easier!

Your colleague has handed-over a Python script they were working on, which you notice doesn't contain any tests. As you aren't familiar with the libraries or syntax used in the script, you'll lean on V4-Pro's default reasoning to add appropriate testing to the script in the form of assert statements. If you'd like to read more about assert statements, check out this DataCamp tutorial.

import numpy as np
a = np.arange(5)
b = a.reshape(-1, 1)
c = np.ones((5, 3))
d = np.hstack((b, c))
col_means = d.mean(axis=0)

この演習はコースの一部です

Working with DeepSeek in Python

コースを見る

演習の手順

  • Copy the code provided into the delimited prompt that has been started for you.
  • Send prompt to deepseek-ai/DeepSeek-V4-Pro.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

# Copy the code into the prompt
prompt = """[Task: Write Python assert statements for the following code.]
Code:
____
"""

# Send the prompt — V4-Pro reasons by default
response = client.chat.completions.create(model="deepseek-ai/DeepSeek-V4-Pro", messages=[{"role": "user", "content": ____}], max_tokens=400)
print(response.choices[0].message.content)
コードを編集して実行