Simon Willison

Results 2645 comments of Simon Willison

```bash git diff | llm -s 'describe change' ``` > The change introduces support for chaining multiple LLM responses, especially to enable tool calls to be executed in sequence within...

Against my `llm-ollama` fork: ```python import llm model = llm.get_model("qwen3:4b") def get_weather(city: str) -> str: """Get the weather for a given city.""" return f"The weather in {city} is fine." for...

Tried with OpenAI and it went into an infinite loop, had to implement my chain limit to see that. ```bash LLM_OPENAI_SHOW_RESPONSES=1 python ``` Then: ```python import llm model = llm.get_model("gpt-4.1-mini")...

Oops, I implemented Anthropic when I should have been implementing OpenAI. Anthropic code in `build_messages()` looks something like this: ```python if prompt.tool_results: messages.append( { "role": "user", "content": [ { "type":...

... and then I implemented the OpenAI Responses API: ```python for tool_result in prompt.tool_results: messages.append({ "type": "function_call_output", "call_id": tool_result.tool_call_id, "output": tool_result.output, }) ``` But I should have implemented the Chat...

Got to this error: > `openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.", 'type': 'invalid_request_error',...

Got a demo script working like this (upgraded from a bad LLM-generated script): ```python import os import json from openai import OpenAI import openai client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) # 3️⃣ Dummy...

Here's the JSON body I needed to see: ```json { "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Weather in San Francisco?"...

So to get my code working I need to add that assistant message with the previous function call.

Actually found docs here: https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages ![Image](https://github.com/user-attachments/assets/9164134c-02b9-4561-b779-4e845ccc72ad) So I need to do this: ```json { "role": "assistant", "tool_calls": [{ "function": , "id": , "type": "function"}] } ```