AttributeError: 'NoneType' object has no attribute 'get' #165

Closed
opened 2026-02-15 16:28:25 -05:00 by yindo · 2 comments
Owner

Originally created by @m-c-frank on GitHub (Nov 19, 2024).

this appeared after recursively using tools. i am not doing anything with images

.../ollama/_client.py", line 233, in chat
    if images := message.get('images'):
AttributeError: 'NoneType' object has no attribute 'get'

my function:

def magic(client, raw_readme: str, messages = []):
    def process_metadata(messages):
        response = client.chat(
            model="llama3.2",
            messages=messages,
            tools=[
                {
                    "type": "function",
                    "function": {
                        "name": "validate_metadata",
                        "description": (
                            "Validates if metadata can be parsed into a Python dictionary and that it contains every aspect "
                            "of the metadata including parameters. Do not just print out the readme file."
                        ),
                        "parameters": {
                            "type": "object",
                            "properties": {
                                "metadata_yaml": {
                                    "type": "string",
                                    "description": "metadata as YAML",
                                }
                            },
                        },
                    },
                }
            ],
        )
        return response

    if messages == []:
        messages = [
            {
                "role": "system",
                "content": (
                    "It's your task to compress a README into its core metadata. For instance, if you see a README that describes "
                    "an experiment, we need to note every single detail about the experiment. We store them as key-value pairs, "
                    "dropping filler language."
                ),
            },
            {
                "role": "user",
                "content": f"Extract metadata from this README:\n\n{raw_readme}",
            },
        ]

    response = process_metadata(messages)

    if "tool_calls" in response["message"] and response["message"]["tool_calls"]:
        for tool_call in response["message"]["tool_calls"]:
            if tool_call["function"]["name"] == "validate_metadata":
                arguments = tool_call["function"]["arguments"]
                print(arguments)
                return arguments
    else:
        if "message" in response:
            messages.append(response["message"])
            messages.append(
                {
                    "role": "user",
                    "content": (
                        "seems like you didnt use the function call you had available."
                        "Please extract metadata fields such as 'title', 'charge', 'procedure', 'temperature', "
                        "'has_impedance', 'discharge', 'charging', and others from the text. Focus on creating key-value pairs."
                    ),
                }
            )

            print(messages)

            messages = process_metadata(messages)
            magic(client, raw_readme, extracted_metadata)
Originally created by @m-c-frank on GitHub (Nov 19, 2024). this appeared after recursively using tools. i am not doing anything with images ```sh .../ollama/_client.py", line 233, in chat if images := message.get('images'): AttributeError: 'NoneType' object has no attribute 'get' ``` my function: ```py def magic(client, raw_readme: str, messages = []): def process_metadata(messages): response = client.chat( model="llama3.2", messages=messages, tools=[ { "type": "function", "function": { "name": "validate_metadata", "description": ( "Validates if metadata can be parsed into a Python dictionary and that it contains every aspect " "of the metadata including parameters. Do not just print out the readme file." ), "parameters": { "type": "object", "properties": { "metadata_yaml": { "type": "string", "description": "metadata as YAML", } }, }, }, } ], ) return response if messages == []: messages = [ { "role": "system", "content": ( "It's your task to compress a README into its core metadata. For instance, if you see a README that describes " "an experiment, we need to note every single detail about the experiment. We store them as key-value pairs, " "dropping filler language." ), }, { "role": "user", "content": f"Extract metadata from this README:\n\n{raw_readme}", }, ] response = process_metadata(messages) if "tool_calls" in response["message"] and response["message"]["tool_calls"]: for tool_call in response["message"]["tool_calls"]: if tool_call["function"]["name"] == "validate_metadata": arguments = tool_call["function"]["arguments"] print(arguments) return arguments else: if "message" in response: messages.append(response["message"]) messages.append( { "role": "user", "content": ( "seems like you didnt use the function call you had available." "Please extract metadata fields such as 'title', 'charge', 'procedure', 'temperature', " "'has_impedance', 'discharge', 'charging', and others from the text. Focus on creating key-value pairs." ), } ) print(messages) messages = process_metadata(messages) magic(client, raw_readme, extracted_metadata) ```
yindo closed this issue 2026-02-15 16:28:25 -05:00
Author
Owner

@m-c-frank commented on GitHub (Nov 19, 2024):

i suppose a check would be enough to fix this bug

@m-c-frank commented on GitHub (Nov 19, 2024): i suppose a check would be enough to fix this bug
Author
Owner

@m-c-frank commented on GitHub (Nov 19, 2024):

lmao nvm its this:

            messages = process_metadata(messages)
            magic(client, raw_readme, extracted_metadata)

sorry im going to bed now

@m-c-frank commented on GitHub (Nov 19, 2024): lmao nvm its this: ```py messages = process_metadata(messages) magic(client, raw_readme, extracted_metadata) ``` sorry im going to bed now
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#165