forked from huggingface/tgi-gaudi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve tools to include name and add tests (huggingface#1693)
This PR makes tool calling aware of the name of the function selected. Fixes: huggingface#1657 Thank you @puppetm4st3r for the helpful snippets, large parts of this PR are simply refactors of the code shared 🙏 **opening draft PR because small tweaks are needed before merging
- Loading branch information
Showing
11 changed files
with
428 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...snapshots__/test_tools_llama/test_flash_llama_grammar_tools_insufficient_information.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"choices": [ | ||
{ | ||
"finish_reason": "eos_token", | ||
"index": 0, | ||
"logprobs": null, | ||
"message": { | ||
"content": null, | ||
"name": null, | ||
"role": "assistant", | ||
"tool_calls": [ | ||
{ | ||
"function": { | ||
"arguments": { | ||
"error": "Cannot get current weather forecast from specified location and temperature unit. Please try again with different options." | ||
}, | ||
"description": null, | ||
"name": "notify_error" | ||
}, | ||
"id": 0, | ||
"type": "function" | ||
} | ||
] | ||
}, | ||
"usage": null | ||
} | ||
], | ||
"created": 1712852597, | ||
"id": "", | ||
"model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0", | ||
"object": "text_completion", | ||
"system_fingerprint": "1.4.5-native", | ||
"usage": { | ||
"completion_tokens": 39, | ||
"prompt_tokens": 496, | ||
"total_tokens": 535 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
import json | ||
|
||
from text_generation.types import GrammarType | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def flash_llama_chat_handle(launcher): | ||
with launcher( | ||
"TinyLlama/TinyLlama-1.1B-Chat-v1.0", num_shard=2, disable_grammar_support=False | ||
) as handle: | ||
yield handle | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def flash_llama_chat(flash_llama_chat_handle): | ||
await flash_llama_chat_handle.health(300) | ||
return flash_llama_chat_handle.client | ||
|
||
|
||
@pytest.mark.private | ||
async def test_flash_llama_simple(flash_llama_chat, response_snapshot): | ||
response = await flash_llama_chat.chat( | ||
max_tokens=100, | ||
seed=1, | ||
messages=[ | ||
{ | ||
"role": "system", | ||
"content": "Youre a helpful assistant! Answer the users question best you can.", | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What is the weather like in Brooklyn, New York?", | ||
}, | ||
], | ||
) | ||
|
||
assert ( | ||
response.choices[0].message.content | ||
== "As of today, there is a Update available for the Brooklyn, New York, area. According to the latest forecast, it's warm with high temperatures throughout the day. It's forecasted at 75°F for today and 77°F for tomorrow. However, in autumn, the weather typically changes drastically, becoming cooler and wetter. You can find the current weather forecast for the area through your local weather service. Additionally" | ||
) | ||
assert response == response_snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.