Skip to content

Commit 60b1abd

Browse files
authored
Fixed agents.md (#164)
Fix docs: custom_model should return an object that has a .content attribute
1 parent 695d303 commit 60b1abd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/source/en/reference/agents.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ You could use any `model` callable for your agent, as long as:
6565
1. It follows the [messages format](./chat_templating) (`List[Dict[str, str]]`) for its input `messages`, and it returns a `str`.
6666
2. It stops generating outputs *before* the sequences passed in the argument `stop_sequences`
6767

68-
For defining your LLM, you can make a `custom_model` method which accepts a list of [messages](./chat_templating) and returns text. This callable also needs to accept a `stop_sequences` argument that indicates when to stop generating.
68+
For defining your LLM, you can make a `custom_model` method which accepts a list of [messages](./chat_templating) and returns an object with a .content attribute containing the text. This callable also needs to accept a `stop_sequences` argument that indicates when to stop generating.
6969

7070
```python
7171
from huggingface_hub import login, InferenceClient
@@ -76,9 +76,9 @@ model_id = "meta-llama/Llama-3.3-70B-Instruct"
7676

7777
client = InferenceClient(model=model_id)
7878

79-
def custom_model(messages, stop_sequences=["Task"]) -> str:
79+
def custom_model(messages, stop_sequences=["Task"]):
8080
response = client.chat_completion(messages, stop=stop_sequences, max_tokens=1000)
81-
answer = response.choices[0].message.content
81+
answer = response.choices[0].message
8282
return answer
8383
```
8484

@@ -140,4 +140,4 @@ model = LiteLLMModel("anthropic/claude-3-5-sonnet-latest", temperature=0.2)
140140
print(model(messages, max_tokens=10))
141141
```
142142

143-
[[autodoc]] LiteLLMModel
143+
[[autodoc]] LiteLLMModel

0 commit comments

Comments
 (0)