DeepSeek 모델에 요청 보내기

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

요약

모델과 데이터, 모델 파라미터를 포함한 요청을 Together.ai API로 보내는 컴퓨터

Python으로 DeepSeek 활용하기

요청 생성하기

from openai import OpenAI

# To send to DeepSeek API: base_url="https://api.deepseek.com" client = OpenAI(api_key="<TogetherAI API Key>", base_url="https://api.together.xyz/v1")
  • openai 라이브러리로 요청 생성
  • OpenAI: AI 모델 및 앱 개발사(예: ChatGPT)
  • base_url: 요청을 OpenAI에서 DeepSeek 모델 제공업체로 _전환_
  • api_key: API 인증(제공업체 문서 참고)
1 https://platform.deepseek.com/api_keys
Python으로 DeepSeek 활용하기

요청 생성하기

from openai import OpenAI
# To send to DeepSeek API: base_url="https://api.deepseek.com"
client = OpenAI(api_key="<TogetherAI API Key>", base_url="https://api.together.xyz/v1")


response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Pro-0813",
messages=[{"role": "user", "content": "In one sentence, what is hallucination in AI?"}]
)
print(response)
Python으로 DeepSeek 활용하기

응답

ChatCompletion(id='onVWeEx-gBAtS-a09121fcae54578c', choices=[Choice(finish_reason='stop', index=0,
logprobs=None, message=ChatCompletionMessage(content='Hallucination in AI is when a model confidently
generates information that sounds plausible but is factually incorrect, misleading, or entirely
fabricated.', refusal=None, role='assistant', annotations=None, audio=None, function_call=None,
tool_calls=[]), seed=None)], created=1781018557, model='deepseek-ai/DeepSeek-V4-Pro-0813',
object='chat.completion', moderation=None, service_tier=None, system_fingerprint='default',
usage=CompletionUsage(completion_tokens=28, prompt_tokens=15, total_tokens=43,
completion_tokens_details=None, prompt_tokens_details=PromptTokensDetails(audio_tokens=None,
cached_tokens=0)), prompt=[])
Python으로 DeepSeek 활용하기

응답

ChatCompletion(id='onVWeEx-gBAtS-a09121fcae54578c',
               choices=[Choice(finish_reason='stop', index=0, logprobs=None,
                               message=ChatCompletionMessage(content='Hallucination in AI refers...',
                               refusal=None, role='assistant', annotations=None, audio=None,
                               function_call=None, tool_calls=[]), seed=None)],
               created=1781018557,
               model='deepseek-ai/DeepSeek-V4-Pro-0813',
               object='chat.completion',
               moderation=None,
               service_tier=None,
               system_fingerprint='default',
               usage=CompletionUsage(completion_tokens=28, prompt_tokens=15, total_tokens=43,
                                     completion_tokens_details=None,
                                     prompt_tokens_details=PromptTokensDetails(audio_tokens=None,
                                          cached_tokens=0)),
               prompt=[])
Python으로 DeepSeek 활용하기

응답 해석하기

print(response.choices)
[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(
content='Hallucination in AI refers to the generation of false or nonsensical information
that is presented as factual, often due to limitations in training data, model biases, or
inference errors.', refusal=None, role='assistant', annotations=None, audio=None,
function_call=None, tool_calls=[]), seed=None)]
Python으로 DeepSeek 활용하기

응답 해석하기

print(response.choices[0])
Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(
content='Hallucination in AI refers to the generation of false or nonsensical information
that is presented as factual, often due to limitations in training data, model biases, or
inference errors.', refusal=None, role='assistant', annotations=None, audio=None,
function_call=None, tool_calls=[]), seed=None)
Python으로 DeepSeek 활용하기

응답 해석하기

print(response.choices[0].message)
ChatCompletionMessage(content='Hallucination in AI refers to the generation of false or
nonsensical information that is presented as factual, often due to limitations in training
data, model biases, or inference errors.', refusal=None, role='assistant', annotations=None,
audio=None, function_call=None, tool_calls=[])
print(response.choices[0].message.content)
Hallucination in AI refers to the generation of false or nonsensical information that is
presented as factual, often due to limitations in training data, model biases, or inference
errors.
Python으로 DeepSeek 활용하기

API 사용 비용

 

  • DeepSeek의 경우:
    • 제공업체(예: together.ai)
    • 모델
    • 입력과 출력이 클수록 비용 증가

유료 도로

1 https://api-docs.deepseek.com/quick_start/pricing
Python으로 DeepSeek 활용하기

연습해 봅시다!

Python으로 DeepSeek 활용하기

Preparing Video For Download...