mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-28 07:31:59 +00:00
chore: more code-interpreter removal
Final removal piece of code-interpreter provider. Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
parent
e3ad17ec5e
commit
c1f53ddc16
25 changed files with 7 additions and 346 deletions
|
|
@ -27,7 +27,6 @@ class BuiltinTool(Enum):
|
|||
brave_search = "brave_search"
|
||||
wolfram_alpha = "wolfram_alpha"
|
||||
photogen = "photogen"
|
||||
code_interpreter = "code_interpreter"
|
||||
|
||||
|
||||
Primitive = str | int | float | bool | None
|
||||
|
|
|
|||
|
|
@ -115,13 +115,6 @@ class ChatFormat:
|
|||
tokens.extend(toks)
|
||||
images.extend(imgs)
|
||||
|
||||
if (
|
||||
message.role == "assistant"
|
||||
and len(message.tool_calls) > 0
|
||||
and message.tool_calls[0].tool_name == BuiltinTool.code_interpreter
|
||||
):
|
||||
tokens.append(self.tokenizer.special_tokens["<|python_tag|>"])
|
||||
|
||||
_process_content(message.content)
|
||||
|
||||
if message.role == "user" and message.context is not None:
|
||||
|
|
@ -173,10 +166,6 @@ class ChatFormat:
|
|||
if content.startswith(header_str):
|
||||
content = content[len(header_str) :]
|
||||
|
||||
ipython = content.startswith("<|python_tag|>")
|
||||
if ipython:
|
||||
content = content[len("<|python_tag|>") :]
|
||||
|
||||
if content.endswith("<|eot_id|>"):
|
||||
content = content[: -len("<|eot_id|>")]
|
||||
stop_reason = StopReason.end_of_turn
|
||||
|
|
@ -208,11 +197,6 @@ class ChatFormat:
|
|||
}
|
||||
if tool_name in BuiltinTool.__members__:
|
||||
tool_name = BuiltinTool[tool_name]
|
||||
elif ipython:
|
||||
tool_name = BuiltinTool.code_interpreter
|
||||
tool_arguments = {
|
||||
"code": content,
|
||||
}
|
||||
|
||||
tool_calls = []
|
||||
if tool_name is not None and tool_arguments is not None:
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class BuiltinToolGenerator(PromptTemplateGeneratorBase):
|
|||
{% if builtin_tools or custom_tools -%}
|
||||
Environment: ipython
|
||||
{% endif -%}
|
||||
{% set builtin_tools = builtin_tools | reject('equalto', 'code_interpreter') | list -%}
|
||||
{% set builtin_tools = builtin_tools | list -%}
|
||||
{% if builtin_tools -%}
|
||||
Tools: {{ builtin_tools | join(", ") | trim -}}
|
||||
{% endif %}
|
||||
|
|
@ -79,14 +79,9 @@ class BuiltinToolGenerator(PromptTemplateGeneratorBase):
|
|||
return [
|
||||
# builtin tools
|
||||
[
|
||||
ToolDefinition(tool_name=BuiltinTool.code_interpreter),
|
||||
ToolDefinition(tool_name=BuiltinTool.brave_search),
|
||||
ToolDefinition(tool_name=BuiltinTool.wolfram_alpha),
|
||||
],
|
||||
# only code interpretor
|
||||
[
|
||||
ToolDefinition(tool_name=BuiltinTool.code_interpreter),
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -229,8 +229,6 @@ class ToolUtils:
|
|||
elif t.tool_name == BuiltinTool.photogen:
|
||||
q = t.arguments["query"]
|
||||
return f'photogen.call(query="{q}")'
|
||||
elif t.tool_name == BuiltinTool.code_interpreter:
|
||||
return t.arguments["code"]
|
||||
else:
|
||||
fname = t.tool_name
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,6 @@ print(is_prime(7)) # Output: True<|eom_id|>
|
|||
|
||||
|
||||
- Model starts with <|python_tag|> and continues writing python code that it needs to be executed
|
||||
- No explicit mention of code_interpreter in system prompt. `Environment: ipython` implicitly enables it.
|
||||
|
||||
|
||||
## Built-in tools full interaction
|
||||
|
|
|
|||
|
|
@ -147,25 +147,6 @@ def usecases() -> list[UseCase | str]:
|
|||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Builtin Code Interpreter",
|
||||
description="Here is an actual example of model responding with code",
|
||||
dialogs=[
|
||||
[
|
||||
RawMessage(role="system", content="Environment: ipython"),
|
||||
RawMessage(
|
||||
role="user",
|
||||
content="Write code to check if number is prime, use that to see if the number 7 is prime",
|
||||
),
|
||||
],
|
||||
],
|
||||
notes=textwrap.dedent(
|
||||
"""
|
||||
- Model starts with <|python_tag|> and continues writing python code that it needs to be executed
|
||||
- No explicit mention of code_interpreter in system prompt. `Environment: ipython` implicitly enables it.
|
||||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Built-in tools full interaction",
|
||||
description="Here is a full interaction with the built-in tools including the tool response and the final assistant response.",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ from llama_stack.models.llama.datatypes import (
|
|||
from ..prompt_format import (
|
||||
TextCompletionContent,
|
||||
UseCase,
|
||||
llama3_1_builtin_code_interpreter_dialog,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -157,22 +156,6 @@ def usecases():
|
|||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Code Interpreter",
|
||||
description=textwrap.dedent(
|
||||
"""
|
||||
Code Interpreter continues to work in 3.2 text models similar to Llama 3.1 model family.
|
||||
Here is an example,
|
||||
"""
|
||||
),
|
||||
dialogs=[llama3_1_builtin_code_interpreter_dialog()],
|
||||
notes=textwrap.dedent(
|
||||
"""
|
||||
- Note `Environment: ipython` in the system prompt.
|
||||
- Note that the response starts with `<|python_tag|>` and ends with `<|eom_id|>`
|
||||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Zero shot function calling E2E format",
|
||||
description=textwrap.dedent(
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ def usecases():
|
|||
Use `Environment: ipython` to enable tools.
|
||||
Add `Tools: {{tool_name1}},{{tool_name2}}` for each of the builtin tools.
|
||||
The same builtin tools as Llama3.1 are available,
|
||||
- code_interpreter (for executing python code)
|
||||
- brave_search (to search the web)
|
||||
- wolfram_alpha (for querying wolfram alpha for mathematical questions)
|
||||
""",
|
||||
|
|
@ -72,7 +71,6 @@ def usecases():
|
|||
"""
|
||||
- Note the `<|python_tag|>` before `brave_search` function call.
|
||||
- The `<|eom_id|>` tag is used to indicate the end of the message.
|
||||
- Similar to Llama3.1, code_interpreter is not explicitly mentioned but is enabled via `Environment: ipython`.
|
||||
- Tool Calling does NOT work with images in the prompt as of now.
|
||||
"""
|
||||
),
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ Llama3.2 vision models follow the same tool calling format as Llama3.1 models wh
|
|||
Use `Environment: ipython` to enable tools.
|
||||
Add `Tools: {{tool_name1}},{{tool_name2}}` for each of the builtin tools.
|
||||
The same builtin tools as Llama3.1 are available,
|
||||
- code_interpreter (for executing python code)
|
||||
- brave_search (to search the web)
|
||||
- wolfram_alpha (for querying wolfram alpha for mathematical questions)
|
||||
|
||||
|
|
@ -94,7 +93,6 @@ Search the web for the latest price of 1oz gold?<|eot_id|><|start_header_id|>ass
|
|||
|
||||
- Note the `<|python_tag|>` before `brave_search` function call.
|
||||
- The `<|eom_id|>` tag is used to indicate the end of the message.
|
||||
- Similar to Llama3.1, code_interpreter is not explicitly mentioned but is enabled via `Environment: ipython`.
|
||||
- Tool Calling does NOT work with images in the prompt as of now.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -148,25 +148,6 @@ def usecases() -> list[UseCase | str]:
|
|||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Builtin Code Interpreter",
|
||||
description="Here is an actual example of model responding with code",
|
||||
dialogs=[
|
||||
[
|
||||
RawMessage(role="system", content="Environment: ipython"),
|
||||
RawMessage(
|
||||
role="user",
|
||||
content="Write code to check if number is prime, use that to see if the number 7 is prime",
|
||||
),
|
||||
],
|
||||
],
|
||||
notes=textwrap.dedent(
|
||||
"""
|
||||
- Model starts with <|python_tag|> and continues writing python code that it needs to be executed
|
||||
- No explicit mention of code_interpreter in system prompt. `Environment: ipython` implicitly enables it.
|
||||
"""
|
||||
),
|
||||
),
|
||||
UseCase(
|
||||
title="Built-in tools full interaction",
|
||||
description="Here is a full interaction with the built-in tools including the tool response and the final assistant response.",
|
||||
|
|
|
|||
|
|
@ -285,11 +285,6 @@ class ChatFormat:
|
|||
}
|
||||
if tool_name in BuiltinTool.__members__:
|
||||
tool_name = BuiltinTool[tool_name]
|
||||
elif ipython:
|
||||
tool_name = BuiltinTool.code_interpreter
|
||||
tool_arguments = {
|
||||
"code": content,
|
||||
}
|
||||
|
||||
tool_calls = []
|
||||
if tool_name is not None and tool_arguments is not None:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ from llama_stack.models.llama.llama4.tokenizer import Tokenizer
|
|||
|
||||
from .llama3.interface import LLama31Interface
|
||||
from .llama3.template_data import (
|
||||
system_message_builtin_code_only,
|
||||
system_message_builtin_tools_only,
|
||||
system_message_custom_tools_only,
|
||||
)
|
||||
|
|
@ -164,17 +163,6 @@ def llama3_1_builtin_tool_call_dialog(tool_prompt_format=ToolPromptFormat.json):
|
|||
return messages
|
||||
|
||||
|
||||
def llama3_1_builtin_code_interpreter_dialog(tool_prompt_format=ToolPromptFormat.json):
|
||||
interface = LLama31Interface(tool_prompt_format)
|
||||
|
||||
messages = interface.system_messages(**system_message_builtin_code_only())
|
||||
messages += interface.user_message(
|
||||
content="Write code to check if number is prime. Use it to verify if number 7 is prime"
|
||||
)
|
||||
|
||||
return messages
|
||||
|
||||
|
||||
def llama3_1_builtin_tool_call_with_image_dialog(
|
||||
tool_prompt_format=ToolPromptFormat.json,
|
||||
):
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ CAT_HATE = "Hate"
|
|||
CAT_SELF_HARM = "Self-Harm"
|
||||
CAT_SEXUAL_CONTENT = "Sexual Content"
|
||||
CAT_ELECTIONS = "Elections"
|
||||
CAT_CODE_INTERPRETER_ABUSE = "Code Interpreter Abuse"
|
||||
|
||||
|
||||
SAFETY_CATEGORIES_TO_CODE_MAP = {
|
||||
|
|
@ -65,7 +64,6 @@ SAFETY_CATEGORIES_TO_CODE_MAP = {
|
|||
CAT_SELF_HARM: "S11",
|
||||
CAT_SEXUAL_CONTENT: "S12",
|
||||
CAT_ELECTIONS: "S13",
|
||||
CAT_CODE_INTERPRETER_ABUSE: "S14",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,7 +94,7 @@ LLAMA_GUARD_MODEL_IDS = {
|
|||
}
|
||||
|
||||
MODEL_TO_SAFETY_CATEGORIES_MAP = {
|
||||
"meta-llama/Llama-Guard-3-8B": DEFAULT_LG_V3_SAFETY_CATEGORIES + [CAT_CODE_INTERPRETER_ABUSE],
|
||||
"meta-llama/Llama-Guard-3-8B": DEFAULT_LG_V3_SAFETY_CATEGORIES,
|
||||
"meta-llama/Llama-Guard-3-1B": DEFAULT_LG_V3_SAFETY_CATEGORIES,
|
||||
"meta-llama/Llama-Guard-3-11B-Vision": DEFAULT_LG_V3_SAFETY_CATEGORIES,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,3 @@
|
|||
|:-----|:-----|:-----|:-----|
|
||||
| /create_agent_turn | rag | test_rag_agent | ✅ |
|
||||
| /create_agent_turn | custom_tool | test_custom_tool | ✅ |
|
||||
| /create_agent_turn | code_execution | test_code_interpreter_for_attachments | ✅ |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue