File size: 4,947 Bytes
17c6d62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
β οΈ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# μμ΄μ νΈ & λꡬ [[agents-tools]]
<Tip warning={true}>
Transformers Agentλ μ€ν μ€μΈ APIμ΄λ―λ‘ μΈμ λ μ§ λ³κ²½λ μ μμ΅λλ€.
APIλ κΈ°λ° λͺ¨λΈμ΄ μμ£Ό μ
λ°μ΄νΈλλ―λ‘, μμ΄μ νΈκ° μ 곡νλ κ²°κ³Όλ¬Όμ λ¬λΌμ§ μ μμ΅λλ€.
</Tip>
μμ΄μ νΈμ λꡬμ λν΄ λ μμλ³΄λ €λ©΄ [μκ° κ°μ΄λ](../transformers_agents)λ₯Ό κΌ μ½μ΄λ³΄μΈμ.
μ΄ νμ΄μ§μλ κΈ°λ³Έ ν΄λμ€μ λν API λ¬Έμκ° ν¬ν¨λμ΄ μμ΅λλ€.
## μμ΄μ νΈ [[agents]]
μ°λ¦¬λ κΈ°λ³Έ [`Agent`] ν΄λμ€λ₯Ό κΈ°λ°μΌλ‘ λ κ°μ§ μ νμ μμ΄μ νΈλ₯Ό μ 곡ν©λλ€:
- [`CodeAgent`]λ ν λ²μ λμν©λλ€. μμ
μ ν΄κ²°νκΈ° μν΄ μ½λλ₯Ό μμ±ν λ€μ, λ°λ‘ μ€νν©λλ€.
- [`ReactAgent`]λ λ¨κ³λ³λ‘ λμνλ©°, κ° λ¨κ³λ νλμ μκ°, νλμ λꡬ νΈμΆ λ° μ€νμΌλ‘ ꡬμ±λ©λλ€. μ΄ μμ΄μ νΈμλ λ κ°μ§ ν΄λμ€κ° μμ΅λλ€:
- [`ReactJsonAgent`]λ λꡬ νΈμΆμ JSONμΌλ‘ μμ±ν©λλ€.
- [`ReactCodeAgent`]λ λꡬ νΈμΆμ Python μ½λλ‘ μμ±ν©λλ€.
### Agent [[agent]]
[[autodoc]] Agent
### CodeAgent [[codeagent]]
[[autodoc]] CodeAgent
### React agents [[react-agents]]
[[autodoc]] ReactAgent
[[autodoc]] ReactJsonAgent
[[autodoc]] ReactCodeAgent
## Tools [[tools]]
### load_tool [[loadtool]]
[[autodoc]] load_tool
### Tool [[tool]]
[[autodoc]] Tool
### Toolbox [[toolbox]]
[[autodoc]] Toolbox
### PipelineTool [[pipelinetool]]
[[autodoc]] PipelineTool
### launch_gradio_demo [[launchgradiodemo]]
[[autodoc]] launch_gradio_demo
### ToolCollection [[toolcollection]]
[[autodoc]] ToolCollection
## μμ§ [[engines]]
μμ΄μ νΈ νλ μμν¬μμ μ¬μ©ν μ μλ μμ§μ μμ λ‘κ² λ§λ€κ³ μ¬μ©ν μ μμ΅λλ€.
μ΄ μμ§λ€μ λ€μκ³Ό κ°μ μ¬μμ κ°μ§κ³ μμ΅λλ€:
1. μ
λ ₯(`List[Dict[str, str]]`)μ λν [λ©μμ§ νμ](../chat_templating.md)μ λ°λ₯΄κ³ λ¬Έμμ΄μ λ°νν΄μΌ ν©λλ€.
2. μΈμ `stop_sequences`μ μνμ€κ° μ λ¬λκΈ° *μ μ* μΆλ ₯μ μμ±νλ κ²μ μ€μ§ν΄μΌ ν©λλ€.
### HfApiEngine [[HfApiEngine]]
νΈμλ₯Ό μν΄, μμ μ¬νμ ꡬννκ³ λκ·λͺ¨ μΈμ΄ λͺ¨λΈ μ€νμ μν΄ μΆλ‘ μλν¬μΈνΈλ₯Ό μ¬μ©νλ `HfApiEngine`μ μΆκ°νμ΅λλ€.
```python
>>> from transformers import HfApiEngine
>>> messages = [
... {"role": "user", "content": "Hello, how are you?"},
... {"role": "assistant", "content": "I'm doing great. How can I help you today?"},
... {"role": "user", "content": "No need to help, take it easy."},
... ]
>>> HfApiEngine()(messages, stop_sequences=["conversation"])
"That's very kind of you to say! It's always nice to have a relaxed "
```
[[autodoc]] HfApiEngine
## μμ΄μ νΈ μ ν [[agent-types]]
μμ΄μ νΈλ λꡬ κ°μ λͺ¨λ μ νμ κ°μ²΄λ₯Ό μ²λ¦¬ν μ μμ΅λλ€; λꡬλ μμ ν λ©ν°λͺ¨λ¬μ΄λ―λ‘ ν
μ€νΈ, μ΄λ―Έμ§, μ€λμ€, λΉλμ€ λ± λ€μν μ νμ μλ½νκ³ λ°νν μ μμ΅λλ€.
λꡬ κ°μ νΈνμ±μ λμ΄κ³ ipython (jupyter, colab, ipython λ
ΈνΈλΆ, ...)μμ μ΄λ¬ν
λ°ν κ°μ μ¬λ°λ₯΄κ² λ λλ§νκΈ° μν΄ μ΄λ¬ν μ νμ μ€μ¬μΌλ‘ λνΌ ν΄λμ€λ₯Ό
ꡬνν©λλ€.
λνλ κ°μ²΄λ μ²μκ³Ό λμΌνκ² μλν΄μΌ ν©λλ€; ν
μ€νΈ κ°μ²΄λ μ¬μ ν λ¬Έμμ΄λ‘ μλν΄μΌ νλ©°,
μ΄λ―Έμ§ κ°μ²΄λ μ¬μ ν `PIL.Image`λ‘ μλν΄μΌ ν©λλ€.
μ΄λ¬ν μ νμλ μΈ κ°μ§ νΉμ λͺ©μ μ΄ μμ΅λλ€:
- `to_raw`λ₯Ό νΈμΆνλ©΄ κΈ°λ³Έ κ°μ²΄κ° λ°νλμ΄μΌ ν©λλ€.
- `to_string`μ νΈμΆνλ©΄ κ°μ²΄κ° λ¬Έμμ΄λ‘ λ°νλμ΄μΌ ν©λλ€:
`AgentText`μ κ²½μ° λ¬Έμμ΄μ΄ λ μ μμ§λ§, λ€λ₯Έ κ²½μ°μλ κ°μ²΄μ μ§λ ¬νλ λ²μ μ κ²½λ‘μΌ μ μμ΅λλ€.
- ipython 컀λμμ νμν λ κ°μ²΄κ° μ¬λ°λ₯΄κ² νμλμ΄μΌ ν©λλ€.
### AgentText [[agenttext]]
[[autodoc]] transformers.agents.agent_types.AgentText
### AgentImage [[agentimage]]
[[autodoc]] transformers.agents.agent_types.AgentImage
### AgentAudio [[agentaudio]]
[[autodoc]] transformers.agents.agent_types.AgentAudio
|