DSPy

DSPy is a Python framework for composing language-model programs and optimizing their instructions and examples against defined metrics

출처 원문 · EN

실제 예시 보기

사용 예시

DSPy: see a signature produce the author’s haiku

Build the first haiku program from the author’s complete LM setup and signature example. The printed poem is the tutorial’s illustrative output; its exact generation model is unspecified. The copied recipe preserves the setup model string and API-key placeholder.

입력 예시

import dspy

# Pass the key explicitly...
lm = dspy.LM("openai/gpt-5-nano", api_key="YOUR_OPENAI_API_KEY")

dspy.configure(lm=lm)

haiku_signature = "subject -> haiku"
haiku_generator = dspy.Predict(haiku_signature)
result = haiku_generator(subject="computer science")
print(result.haiku)

출력 예시

Silent code unfolds
Logic threads through hidden paths
Bugs bloom, then resolve
라이선스

Complete original license and any source copyright retained. Source-authored examples are separate from site-reproduced results; no original scripts, installations, model/API requests, account creation, memory writes, graph queries or tests were executed. Complete pinned source blocks are assembled in documented order, with their separate file bindings retained in the review record. The SDK setup and printed illustrative poem come from separate source sections; no exact generation-model binding is claimed.

MIT License

Copyright (c) 2023 Stanford Future Data Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
사용 예시

DSPy: specify setting, mood and season

The full source signature adds setting, mood and a Literal season before calling the haiku program for Bodega Bay. The author’s printed poem stays alongside the recipe. Setup and sample output come from separate documented sections, so the poem’s exact model is unspecified.

입력 예시

import dspy

# Pass the key explicitly...
lm = dspy.LM("openai/gpt-5-nano", api_key="YOUR_OPENAI_API_KEY")

dspy.configure(lm=lm)

from typing import Literal

Season = Literal[
    "spring", "summer", "autumn", "winter",
]

class HaikuBot(dspy.Signature):
    """
    Write a classical haiku given the provided inputs.
    """
    location: str = dspy.InputField()
    mood: str = dspy.InputField()
    season: Season = dspy.InputField()
    haiku: str = dspy.OutputField()

haiku_bot = dspy.Predict(HaikuBot)
result = haiku_bot(location="Bodega Bay", mood="mysterious", season="autumn")
print(result.haiku)

출력 예시

Fog drifts over waves,  
Crimson leaves swirl by the pier—  
Night whispers secrets.
라이선스

Complete original license and any source copyright retained. Source-authored examples are separate from site-reproduced results; no original scripts, installations, model/API requests, account creation, memory writes, graph queries or tests were executed. Complete pinned source blocks are assembled in documented order, with their separate file bindings retained in the review record. The SDK setup and printed illustrative poem come from separate source sections; no exact generation-model binding is claimed.

MIT License

Copyright (c) 2023 Stanford Future Data Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
출처에 기재된 기능

DSPy의 주요 기능

  1. 01Define model tasks with typed signatures
  2. 02Compose reusable modules in Python
  3. 03Optimize prompts using examples and evaluation metrics
출처 원문 · EN
차별점

차별점

DSPy treats model calls as parts of a program that can be evaluated and optimized. Useful results depend on representative examples and the metric supplied by the developer.

출처 원문 · EN
추천 대상

추천 대상

  • Developers evaluating language-model pipelines
  • Teams tuning repeatable AI tasks
출처 원문 · EN
선택하기 전에

확인할 사항

  • 실제 작업 하나를 시험하고 결과가 요구 사항에 맞는지 비교합니다.
  • 어떤 데이터가 저장·공유되거나 학습에 사용되는지 확인합니다.
  • 공식 사이트에서 현재 가격, 사용 한도, 해지 조건을 확인합니다.
마지막 확인

공식 링크는 2026년 10월 20일에 확인했습니다. 기능 주장은 독립적으로 테스트하지 않았습니다.