Skip to content

Commit 7069ea4

Browse files
🌐 [i18n-KO] Translated models.md to Korean (#1776)
Co-authored-by: Albert Villanova del Moral <[email protected]>
1 parent 983bb71 commit 7069ea4

File tree

2 files changed

+283
-4
lines changed

2 files changed

+283
-4
lines changed

docs/source/ko/_toctree.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
# title: "(번역중) Human-in-the-Loop: Customize agent plan interactively"
4141
# - local: examples/async_agent
4242
# title: (번역중) Async Applications with Agents
43-
#- title: Reference
44-
# sections:
43+
- title: Reference
44+
sections:
4545
# - local: reference/agents
4646
# title: Agent-related objects
47-
# - local: reference/models
48-
# title: Model-related objects
47+
- local: reference/models
48+
title: 모델 관련 클래스
4949
# - title: Tools
5050
# sections:
5151
# - title: Tool-related objects

docs/source/ko/reference/models.md

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
# 모델[[models]]
2+
3+
<Tip warning={true}>
4+
5+
Smolagents는 언제든지 변경될 수 있는 실험적인 API입니다. API 또는 기반 모델이 바뀌면 에이전트가 반환하는 결과도 달라질 수 있습니다.
6+
7+
</Tip>
8+
9+
에이전트와 도구에 대한 자세한 내용은 꼭 [소개 가이드](../index)를 읽어보시기 바랍니다. 이 페이지는 기반 클래스에 대한 API 문서를 포함하고 있습니다.
10+
11+
## 모델[[models]]
12+
13+
smolagents의 모든 모델 클래스는 추가 키워드 인수(`temperature`, `max_tokens`, `top_p` 등)를 인스턴스화 시점에 바로 전달할 수 있습니다.
14+
이 파라미터들은 기반 모델의 생성 호출에 자동으로 전달되어, 창의성, 응답 길이, 샘플링 전략과 같은 모델의 동작을 설정할 수 있습니다.
15+
16+
### 기본 모델[[smolagents.Model]]
17+
18+
`Model` 클래스는 모든 모델 구현의 기반이 되는 클래스이며, 사용자 정의 모델이 에이전트와 함께 작동하기 위해 구현해야 하는 핵심 인터페이스를 제공합니다.
19+
20+
[[autodoc]] Model
21+
22+
### API 모델[[smolagents.ApiModel]]
23+
24+
`ApiModel` 클래스는 모든 API 기반 모델 구현의 토대가 되며, 외부 API 상호 작용, 속도 제한, 클라이언트 관리 등 모델이 상속하는 공통 기능을 제공합니다.
25+
26+
[[autodoc]] ApiModel
27+
28+
### TransformersModel[[smolagents.TransformersModel]]
29+
30+
편의를 위해, 초기화 시 주어진 model_id에 대한 로컬 `transformers` 파이프라인을 구축하여 위 사항들을 구현하는 `TransformersModel`을 추가했습니다.
31+
32+
```python
33+
from smolagents import TransformersModel
34+
35+
model = TransformersModel(model_id="HuggingFaceTB/SmolLM2-360M-Instruct")
36+
37+
print(model([{"role": "user", "content": [{"type": "text", "text": "좋아!"}]}], stop_sequences=[""]))
38+
```
39+
```text
40+
>>> 좋아! 아래와 같
41+
```
42+
43+
기반 모델에서 지원하는 모든 키워드 인수(`temperature`, `max_new_tokens`, `top_p` 등)를 인스턴스화 시점에 직접 전달할 수 있습니다. 이들은 모델 생성 호출로 전달됩니다:
44+
45+
```python
46+
model = TransformersModel(
47+
model_id="HuggingFaceTB/SmolLM2-360M-Instruct",
48+
temperature=0.7,
49+
max_new_tokens=1000
50+
)
51+
```
52+
53+
> [!TIP]
54+
> 사용자의 컴퓨터에 `transformers``torch`가 설치되어 있어야 합니다. 설치되지 않은 경우 `pip install 'smolagents[transformers]'`를 실행하십시오.
55+
56+
[[autodoc]] TransformersModel
57+
58+
### InferenceClientModel[[smolagents.InferenceClientModel]]
59+
60+
`InferenceClientModel`은 LLM 실행을 위해 huggingface_hub의 [InferenceClient](https://huggingface.co/docs/huggingface_hub/main/en/guides/inference)를 래핑합니다. 이는 Hub에서 사용할 수 있는 모든 [Inference Providers](https://huggingface.co/docs/inference-providers/index)를 지원합니다. Cerebras, Cohere, Fal, Fireworks, HF-Inference, Hyperbolic, Nebius, Novita, Replicate, SambaNova, Together 등이 있습니다.
61+
62+
또한 `requests_per_minute` 인수를 사용하여 분당 요청 수로 속도 제한을 설정할 수 있습니다:
63+
64+
```python
65+
from smolagents import InferenceClientModel
66+
67+
messages = [
68+
{"role": "user", "content": [{"type": "text", "text": "안녕하세요, 잘 지내고 계신가요?"}]}
69+
]
70+
71+
model = InferenceClientModel(provider="novita", requests_per_minute=60)
72+
print(model(messages))
73+
```
74+
```text
75+
>>> 안녕하세요. 덕분에 잘 지내고 있습니다.
76+
```
77+
78+
기반 모델에서 지원하는 모든 키워드 인수(`temperature`, `max_tokens`, `top_p` 등)를 인스턴스화 시점에 직접 전달할 수 있습니다. 이들은 모델 생성 호출로 전달됩니다:
79+
80+
```python
81+
model = InferenceClientModel(
82+
provider="novita",
83+
requests_per_minute=60,
84+
temperature=0.8,
85+
max_tokens=500
86+
)
87+
```
88+
89+
[[autodoc]] InferenceClientModel
90+
91+
### LiteLLMModel[[smolagents.LiteLLMModel]]
92+
93+
`LiteLLMModel`[LiteLLM](https://www.litellm.ai/)을 활용하여 다양한 제공업체의 100개 이상의 LLM을 지원합니다.
94+
모델 초기화 시 키워드 인수를 전달하면, 이후 모델을 사용할 때마다 해당 설정이 적용됩니다. 예를 들어 아래에서는 `temperature`를 전달합니다. 또한 `requests_per_minute` 인수를 통해 분당 요청 수를 제한할 수도 있습니다.
95+
96+
```python
97+
from smolagents import LiteLLMModel
98+
99+
messages = [
100+
{"role": "user", "content": [{"type": "text", "text": "안녕하세요, 잘 지내고 계신가요?"}]}
101+
]
102+
103+
model = LiteLLMModel(model_id="anthropic/claude-3-5-sonnet-latest", temperature=0.2, max_tokens=10, requests_per_minute=60)
104+
print(model(messages))
105+
```
106+
107+
[[autodoc]] LiteLLMModel
108+
109+
### LiteLLMRouterModel[[smolagents.LiteLLMRouterModel]]
110+
111+
`LiteLLMRouterModel`[LiteLLM Router](https://docs.litellm.ai/docs/routing)를 감싼 래퍼로, 다양한 고급 라우팅 전략을 지원합니다. 예를 들어, 여러 배포 환경 간 로드 밸런싱, 큐 기반의 중요 요청 우선 처리, 쿨다운, 폴백, 지수적 백오프 재시도 같은 기본 신뢰성 조치 구현 기능을 제공합니다.
112+
113+
```python
114+
from smolagents import LiteLLMRouterModel
115+
116+
messages = [
117+
{"role": "user", "content": [{"type": "text", "text": "안녕하세요, 잘 지내고 계신가요?"}]}
118+
]
119+
120+
model = LiteLLMRouterModel(
121+
model_id="llama-3.3-70b",
122+
model_list=[
123+
{
124+
"model_name": "llama-3.3-70b",
125+
"litellm_params": {"model": "groq/llama-3.3-70b", "api_key": os.getenv("GROQ_API_KEY")},
126+
},
127+
{
128+
"model_name": "llama-3.3-70b",
129+
"litellm_params": {"model": "cerebras/llama-3.3-70b", "api_key": os.getenv("CEREBRAS_API_KEY")},
130+
},
131+
],
132+
client_kwargs={
133+
"routing_strategy": "simple-shuffle",
134+
},
135+
)
136+
print(model(messages))
137+
```
138+
139+
[[autodoc]] LiteLLMRouterModel
140+
141+
### OpenAIServerModel[[smolagents.OpenAIServerModel]]
142+
143+
이 클래스를 사용하면 OpenAIServer와 호환되는 모든 모델을 호출할 수 있습니다. 설정 방법은 다음과 같습니다 (`api_base` url을 다른 서버를 가리키도록 사용자 정의할 수 있습니다):
144+
```py
145+
import os
146+
from smolagents import OpenAIServerModel
147+
148+
model = OpenAIServerModel(
149+
model_id="gpt-4o",
150+
api_base="https://api.openai.com/v1",
151+
api_key=os.environ["OPENAI_API_KEY"],
152+
)
153+
```
154+
155+
기반 모델에서 지원하는 모든 키워드 인수(`temperature`, `max_tokens`, `top_p` 등)를 인스턴스화 시점에 직접 전달할 수 있습니다. 이들은 모델 생성 호출로 전달됩니다:
156+
157+
```py
158+
model = OpenAIServerModel(
159+
model_id="gpt-4o",
160+
api_base="https://api.openai.com/v1",
161+
api_key=os.environ["OPENAI_API_KEY"],
162+
temperature=0.7,
163+
max_tokens=1000,
164+
top_p=0.9,
165+
)
166+
```
167+
168+
[[autodoc]] OpenAIServerModel
169+
170+
### AzureOpenAIServerModel[[smolagents.AzureOpenAIServerModel]]
171+
172+
`AzureOpenAIServerModel`을 사용하면 모든 Azure OpenAI 배포에 연결할 수 있습니다.
173+
174+
아래에서 설정 예시를 확인할 수 있습니다. `azure_endpoint`, `api_key`, `api_version` 인수는 환경 변수(`AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_API_KEY`, `OPENAI_API_VERSION`)를 설정해 두면 생략할 수 있습니다.
175+
176+
`OPENAI_API_VERSION``AZURE_` 접두사가 포함되지 않는다는 점을 주의하시기 바랍니다. 이는 기반이 되는 [openai](https://github.com/openai/openai-python) 패키지의 설계 방식 때문입니다.
177+
178+
```py
179+
import os
180+
181+
from smolagents import AzureOpenAIServerModel
182+
183+
model = AzureOpenAIServerModel(
184+
model_id = os.environ.get("AZURE_OPENAI_MODEL"),
185+
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
186+
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
187+
api_version=os.environ.get("OPENAI_API_VERSION")
188+
)
189+
```
190+
191+
[[autodoc]] AzureOpenAIServerModel
192+
193+
### AmazonBedrockServerModel[[smolagents.AmazonBedrockServerModel]]
194+
195+
`AmazonBedrockServerModel`은 Amazon Bedrock에 연결하고, 사용할 수 있는 모든 모델에서 에이전트를 실행할 수 있도록 지원합니다.
196+
197+
아래는 설정 예시입니다. 이 클래스는 사용자 정의를 위한 추가 옵션도 제공합니다.
198+
199+
```py
200+
import os
201+
202+
from smolagents import AmazonBedrockServerModel
203+
204+
model = AmazonBedrockServerModel(
205+
model_id = os.environ.get("AMAZON_BEDROCK_MODEL_ID"),
206+
)
207+
```
208+
209+
[[autodoc]] AmazonBedrockServerModel
210+
211+
### MLXModel[[smolagents.MLXModel]]
212+
213+
214+
```python
215+
from smolagents import MLXModel
216+
217+
model = MLXModel(model_id="HuggingFaceTB/SmolLM-135M-Instruct")
218+
219+
print(model([{"role": "user", "content": "좋아!"}], stop_sequences=[""]))
220+
```
221+
```text
222+
>>> 좋아! 아래와 같
223+
```
224+
225+
> [!TIP]
226+
> 사용자의 컴퓨터에 `mlx-lm`이 설치되어 있어야 합니다. 설치되지 않은 경우 `pip install 'smolagents[mlx-lm]'`를 실행해 설치합니다.
227+
228+
[[autodoc]] MLXModel
229+
230+
### VLLMModel[[smolagents.VLLMModel]]
231+
232+
빠른 LLM 추론 및 서빙을 위해 [vLLM](https://docs.vllm.ai/)을 사용하는 모델입니다.
233+
234+
```python
235+
from smolagents import VLLMModel
236+
237+
model = VLLMModel(model_id="HuggingFaceTB/SmolLM2-360M-Instruct")
238+
239+
print(model([{"role": "user", "content": "좋아!"}], stop_sequences=[""]))
240+
```
241+
242+
> [!TIP]
243+
> 사용자의 컴퓨터에 `vllm`이 설치되어 있어야 합니다. 설치되지 않은 경우 `pip install 'smolagents[vllm]'`를 실행하세요.
244+
245+
[[autodoc]] VLLMModel
246+
247+
### 사용자 정의 모델[[custom-model]]
248+
249+
자유롭게 자신만의 모델을 만들어 에이전트를 구동하는 데 사용할 수 있습니다.
250+
251+
기본 `Model` 클래스를 상속받아 에이전트를 위한 모델을 만들 수 있습니다.
252+
주요 기준은 `generate` 메소드를 오버라이드하는 것이며, 다음 두 가지 기준을 따릅니다:
253+
1. 입력으로 전달되는 `messages`[메시지 형식](./chat_templating)(`List[Dict[str, str]]`)을 따라야 하며 `.content` 속성을 가진 객체를 반환합니다.
254+
2. `stop_sequences` 인수로 전달된 시퀀스에서 출력을 중단합니다.
255+
256+
LLM을 정의하기 위해, 기본 `Model` 클래스를 상속하는 `CustomModel` 클래스를 만들 수 있습니다.
257+
이 클래스는 [메시지](./chat_templating) 리스트를 받아 텍스트를 포함하는 `.content` 속성을 가진 객체를 반환하는 `generate` 메소드를 가져야 합니다. `generate` 메소드는 또한 생성을 중단할 시점을 나타내는 `stop_sequences` 인수를 받아들여야 합니다.
258+
259+
```python
260+
from huggingface_hub import login, InferenceClient
261+
262+
from smolagents import Model
263+
264+
login("<YOUR_HUGGINGFACEHUB_API_TOKEN>")
265+
266+
model_id = "meta-llama/Llama-3.3-70B-Instruct"
267+
268+
client = InferenceClient(model=model_id)
269+
270+
class CustomModel(Model):
271+
def generate(messages, stop_sequences=["Task"]):
272+
response = client.chat_completion(messages, stop=stop_sequences, max_tokens=1024)
273+
answer = response.choices[0].message
274+
return answer
275+
276+
custom_model = CustomModel()
277+
```
278+
279+
또한, `generate` 메소드는 `grammar` 인수를 받아 [제약된 생성](https://huggingface.co/docs/text-generation-inference/conceptual/guidance)을 허용하여 올바른 형식의 에이전트 출력을 강제할 수 있습니다.

0 commit comments

Comments
 (0)