HN 日本語サマリー

← 一覧へ戻る
AI・機械学習

DeepSeek V4 Pro 0813が静かにリリース

DeepSeek V4 Pro 0813 quietly released (api-docs.deepseek.com)

53 pointsby HiPHInch4 コメント

要約

DeepSeekは、Codexの需要に応えるため、APIでResponses API形式をサポート開始しました。これにより、OpenAI SDKを使用してDeepSeekモデルをCodexに簡単に統合できます。ストリーミングや様々なイベントタイプ、互換性のあるパラメータについても詳細が説明されています。

全文翻訳

Responses APIの使用

Codexの需要に応えるため、当社のAPIはResponses API形式をサポートするようになりました。base_urlはhttps://api.deepseek.comです。

簡単な設定で、CodexでDeepSeekモデルを使用できます。

DeepSeekモデルをCodexに統合する​

Codexとの統合を参照してください。

Responses API経由でDeepSeekモデルを呼び出す​

# まずOpenAI SDKをインストールしてください: `pip3 install openai`
from openai import OpenAI
client = OpenAI(api_key="<your DeepSeek API Key>", base_url="https://api.deepseek.com")
response = client.responses.create(
    model="deepseek-flash",
    instructions="You are a helpful assistant.",
    input="Hi, how are you?",
)
print(response.output_text)

ストリーミング​

stream: trueを設定すると、応答をセマンティックなサーバー送信イベント(SSE)のシーケンスとして受信できます。各イベントにはイベントタイプを示すeventフィールドと、単調増加するsequence_numberが含まれます。ストリームはresponse.completed / response.incomplete / response.failedイベントで終了します。data: [DONE]メッセージはありません。

stream = client.responses.create(
    model="deepseek-flash",
    instructions="You are a helpful assistant.",
    input="Hi, how are you?",
    stream=True,
)
for event in stream:
    if event.type == "response.output_text.delta":
        print(event.delta, end="")

イベントの全リスト:

イベント
response.created
response.in_progress
response.output_item.added / response.output_item.done
response.content_part.added / response.content_part.done
response.reasoning_text.delta / response.reasoning_text.done
response.output_text.delta / response.output_text.done
response.function_call_arguments.delta / response.function_call_arguments.done
response.custom_tool_call_input.delta / response.custom_tool_call_input.done
response.web_search_call.in_progress / response.web_search_call.searching / response.web_search_call.completed
response.completed
response.incomplete
response.failed

画像入力​

Responses APIはdeepseek-flashモデルで画像を受け付けます。画像制限とサポートされるフォーマットはChat Completionsと同じです。

画像は、messageアイテム内のinput_imageコンテンツパートを介して提供されます。image_url(http(s) URLまたはbase64データURL)またはfile_id(Files API経由でアップロードされた画像)を使用します。

response = client.responses.create(
    model="deepseek-flash",
    input=[
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "What is in this image?"},
                {"type": "input_image", "image_url": "https://example.com/image.jpg", "detail": "low"},
            ],
        },
    ],
)
print(response.output_text)

input_imageパートは、function_call_output / custom_tool_call_outputアイテムのoutputにも表示されることがあります。これにより、モデルはツールによって生成された画像を受け取ることができます。

input=[
    {"role": "user", "content": "Read the screenshot the tool returned."},
    {"type": "function_call", "call_id": "fc1", "name": "take_screenshot", "arguments": "{}"},
    {"type": "function_call_output", "call_id": "fc1",     "output": [{"type": "input_image", "image_url": "data:image/png;base64,<BASE64_DATA>"}]}
]
input_imageフィールド​
  • image_url: http(s) URL(最大8192文字)またはbase64エンコードされたデータURL(data:image/jpeg;base64,...)。サポートされるフォーマット: JPEG、PNG、GIF、WebP。
  • file_id: Files API経由でアップロードされた画像のID。形式はfile-api-...です。
  • detail: low / high / original / auto。lowは推論前に画像を512x512にダウンサンプリングします。他の値は元の画像を保持します。file_idが設定されている場合は無視されます。

image_urlとfile_idは排他的です。どちらも指定しない場合は400エラー("input_image must have image_url or file_id