[GH-ISSUE #4408] Ollama chat API output consistently missing <tool_call> #2758

Closed
opened 2026-04-12 13:04:25 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @adrienbrault on GitHub (May 13, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4408

What is the issue?

When using adrienbrault/nous-hermes2pro-llama3-8b over the OpenAPI compatible API, I am always able to see <tool_call> and </tool_call> in the output, while I never see them when using the Ollama API.

The messages to reproduce:

const messages = [
    {
        "role": "system",
        "content": "You are a function calling AI model.\nHere are the available tools:\n<tools>\n[\n  {\n \"name\": \"search_10q\",\n \"description\": \"search_10q(data) - Useful to search information from the latest 10-Q form for a\\n    given stock.\\n    The input to this tool should be a pipe (|) separated text of\\n    length two, representing the stock ticker you are interested and what\\n    question you have from it.\\n\\t\\tFor example, `AAPL|what was last quarter's revenue`.\",\n \"parameters\": {\n \"title\": \"search_10qSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"data\": {\n \"title\": \"Data\"\n        }\n      },\n \"required\": [\n \"data\"\n      ]\n    }\n  },\n  {\n \"name\": \"search_10k\",\n \"description\": \"search_10k(data) - Useful to search information from the latest 10-K form for a\\ngiven stock.\\nThe input to this tool should be a pipe (|) separated text of\\nlength two, representing the stock ticker you are interested, what\\nquestion you have from it.\\nFor example, `AAPL|what was last year's revenue`.\",\n \"parameters\": {\n \"title\": \"search_10kSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"data\": {\n \"title\": \"Data\"\n        }\n      },\n \"required\": [\n \"data\"\n      ]\n    }\n  },\n  {\n \"name\": \"get_stock_fundamentals\",\n \"description\": \"get_stock_fundamentals(symbol: str) -> dict - Get fundamental data for a given stock symbol using yfinance API.\\n\\nArgs:\\n    symbol (str): The stock symbol.\\n\\nReturns:\\n    dict: A dictionary containing fundamental data.\\n        Keys:\\n            - 'symbol': The stock symbol.\\n            - 'company_name': The long name of the company.\\n            - 'sector': The sector to which the company belongs.\\n            - 'industry': The industry to which the company belongs.\\n            - 'market_cap': The market capitalization of the company.\\n            - 'pe_ratio': The forward price-to-earnings ratio.\\n            - 'pb_ratio': The price-to-book ratio.\\n            - 'dividend_yield': The dividend yield.\\n            - 'eps': The trailing earnings per share.\\n            - 'beta': The beta value of the stock.\\n            - '52_week_high': The 52-week high price of the stock.\\n            - '52_week_low': The 52-week low price of the stock.\",\n \"parameters\": {\n \"title\": \"get_stock_fundamentalsSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"symbol\": {\n \"title\": \"Symbol\",\n \"type\": \"string\"\n        }\n      },\n \"required\": [\n \"symbol\"\n      ]\n    }\n  },\n  {\n \"name\": \"get_financial_statements\",\n \"description\": \"get_financial_statements(symbol: str) -> dict - Get financial statements for a given stock symbol.\\n\\nArgs:\\nsymbol (str): The stock symbol.\\n\\nReturns:\\ndict: Dictionary containing financial statements (income statement, balance sheet, cash flow statement).\",\n \"parameters\": {\n \"title\": \"get_financial_statementsSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"symbol\": {\n \"title\": \"Symbol\",\n \"type\": \"string\"\n        }\n      },\n \"required\": [\n \"symbol\"\n      ]\n    }\n  }\n]\n</tools>\n\nPlease use <scratchpad> XML tags to record your reasoning and planning before you call the functions as follows:\n<scratchpad>\n{step-by-step reasoning}\n</scratchpad>\nFor each function call return a json object with function name and arguments within <tool_call> XML tags as follows:\n<tool_call>\n{\"arguments\": <args-dict>, \"name\": <function-name>}\n</tool_call>"
    },
    {
        "role": "user",
        "content": "Your task is to Extract key financial data and ratios from NVDA's SEC filings."
    }
];

I have sample code to reproduce this issue in the following repository: https://github.com/adrienbrault/h2p-l8b-bug

$ ollama -v ; bun run index.ts
ollama version is 0.1.37
{
  endpoint: "http://ai-mbp-14:11434/v1/chat/completions",
  model: "adrienbrault/nous-hermes2pro-llama3-8b:q8_0",
  content: "\n<scratchpad>\nFirst, I will use the `search_10k` function to search for information from the latest 10-K form of NVDA. Then, I will look up their most recent quarterly report using the `search_10q` function. Finally, I will gather more detailed fundamental data about NVDA using the `get_stock_fundamentals` function. For this purpose, I need to have an API key for Yahoo Finance to access the yfinance package.\n</scratchpad>\n\n<tool_call>\n{\"arguments\": {\"data\": \"NVDA|what was last year's revenue\"}, \"name\": \"search_10k\"}\n</tool_call>\n<tool_call>\n{\"arguments\": {\"data\": \"NVDA|what was last quarter's revenue\"}, \"name\": \"search_10q\"}\n</tool_call>\n<tool_call>\n{\"arguments\": {\"symbol\": \"NVDA\"}, \"name\": \"get_stock_fundamentals\"}\n</tool_call>",
}

{
  endpoint: "http://ai-mbp-14:11434/api/chat",
  model: "adrienbrault/nous-hermes2pro-llama3-8b:q8_0",
  content: "\n<scratchpad>\nTo extract key financial data and ratios from NVDA's SEC filings, I will follow these steps:\n\n1. Search for the latest 10-Q form filed by NVDA.\n2. Use the information found in the 10",
}

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.1.37

Originally created by @adrienbrault on GitHub (May 13, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4408 ### What is the issue? When using [adrienbrault/nous-hermes2pro-llama3-8b](https://ollama.com/adrienbrault/nous-hermes2pro-llama3-8b) over the OpenAPI compatible API, I am always able to see `<tool_call>` and `</tool_call>` in the output, while I never see them when using the Ollama API. The messages to reproduce: ```typescript const messages = [ { "role": "system", "content": "You are a function calling AI model.\nHere are the available tools:\n<tools>\n[\n {\n \"name\": \"search_10q\",\n \"description\": \"search_10q(data) - Useful to search information from the latest 10-Q form for a\\n given stock.\\n The input to this tool should be a pipe (|) separated text of\\n length two, representing the stock ticker you are interested and what\\n question you have from it.\\n\\t\\tFor example, `AAPL|what was last quarter's revenue`.\",\n \"parameters\": {\n \"title\": \"search_10qSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"data\": {\n \"title\": \"Data\"\n }\n },\n \"required\": [\n \"data\"\n ]\n }\n },\n {\n \"name\": \"search_10k\",\n \"description\": \"search_10k(data) - Useful to search information from the latest 10-K form for a\\ngiven stock.\\nThe input to this tool should be a pipe (|) separated text of\\nlength two, representing the stock ticker you are interested, what\\nquestion you have from it.\\nFor example, `AAPL|what was last year's revenue`.\",\n \"parameters\": {\n \"title\": \"search_10kSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"data\": {\n \"title\": \"Data\"\n }\n },\n \"required\": [\n \"data\"\n ]\n }\n },\n {\n \"name\": \"get_stock_fundamentals\",\n \"description\": \"get_stock_fundamentals(symbol: str) -> dict - Get fundamental data for a given stock symbol using yfinance API.\\n\\nArgs:\\n symbol (str): The stock symbol.\\n\\nReturns:\\n dict: A dictionary containing fundamental data.\\n Keys:\\n - 'symbol': The stock symbol.\\n - 'company_name': The long name of the company.\\n - 'sector': The sector to which the company belongs.\\n - 'industry': The industry to which the company belongs.\\n - 'market_cap': The market capitalization of the company.\\n - 'pe_ratio': The forward price-to-earnings ratio.\\n - 'pb_ratio': The price-to-book ratio.\\n - 'dividend_yield': The dividend yield.\\n - 'eps': The trailing earnings per share.\\n - 'beta': The beta value of the stock.\\n - '52_week_high': The 52-week high price of the stock.\\n - '52_week_low': The 52-week low price of the stock.\",\n \"parameters\": {\n \"title\": \"get_stock_fundamentalsSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"symbol\": {\n \"title\": \"Symbol\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"symbol\"\n ]\n }\n },\n {\n \"name\": \"get_financial_statements\",\n \"description\": \"get_financial_statements(symbol: str) -> dict - Get financial statements for a given stock symbol.\\n\\nArgs:\\nsymbol (str): The stock symbol.\\n\\nReturns:\\ndict: Dictionary containing financial statements (income statement, balance sheet, cash flow statement).\",\n \"parameters\": {\n \"title\": \"get_financial_statementsSchema\",\n \"type\": \"object\",\n \"properties\": {\n \"symbol\": {\n \"title\": \"Symbol\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"symbol\"\n ]\n }\n }\n]\n</tools>\n\nPlease use <scratchpad> XML tags to record your reasoning and planning before you call the functions as follows:\n<scratchpad>\n{step-by-step reasoning}\n</scratchpad>\nFor each function call return a json object with function name and arguments within <tool_call> XML tags as follows:\n<tool_call>\n{\"arguments\": <args-dict>, \"name\": <function-name>}\n</tool_call>" }, { "role": "user", "content": "Your task is to Extract key financial data and ratios from NVDA's SEC filings." } ]; ``` I have sample code to reproduce this issue in the following repository: https://github.com/adrienbrault/h2p-l8b-bug ```console $ ollama -v ; bun run index.ts ollama version is 0.1.37 { endpoint: "http://ai-mbp-14:11434/v1/chat/completions", model: "adrienbrault/nous-hermes2pro-llama3-8b:q8_0", content: "\n<scratchpad>\nFirst, I will use the `search_10k` function to search for information from the latest 10-K form of NVDA. Then, I will look up their most recent quarterly report using the `search_10q` function. Finally, I will gather more detailed fundamental data about NVDA using the `get_stock_fundamentals` function. For this purpose, I need to have an API key for Yahoo Finance to access the yfinance package.\n</scratchpad>\n\n<tool_call>\n{\"arguments\": {\"data\": \"NVDA|what was last year's revenue\"}, \"name\": \"search_10k\"}\n</tool_call>\n<tool_call>\n{\"arguments\": {\"data\": \"NVDA|what was last quarter's revenue\"}, \"name\": \"search_10q\"}\n</tool_call>\n<tool_call>\n{\"arguments\": {\"symbol\": \"NVDA\"}, \"name\": \"get_stock_fundamentals\"}\n</tool_call>", } { endpoint: "http://ai-mbp-14:11434/api/chat", model: "adrienbrault/nous-hermes2pro-llama3-8b:q8_0", content: "\n<scratchpad>\nTo extract key financial data and ratios from NVDA's SEC filings, I will follow these steps:\n\n1. Search for the latest 10-Q form filed by NVDA.\n2. Use the information found in the 10", } ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.1.37
GiteaMirror added the bug label 2026-04-12 13:04:25 -05:00
Author
Owner

@adrienbrault commented on GitHub (May 14, 2024):

Whoops, my code had an issue 🤦‍♂️

<!-- gh-comment-id:2111175848 --> @adrienbrault commented on GitHub (May 14, 2024): Whoops, my code [had an issue](https://github.com/adrienbrault/h2p-l8b-bug/commit/82de3176fc717bf50e7143c8603d61785ec01170) 🤦‍♂️
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2758