Home / Function/ _convert_to_v1_from_groq() — langchain Function Reference

_convert_to_v1_from_groq() — langchain Function Reference

Architecture documentation for the _convert_to_v1_from_groq() function in groq.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9d4d24e2_43fa_881e_628f_8a0a55cde2e6["_convert_to_v1_from_groq()"]
  0e434ace_bc91_58ed_0c26_ebc25d9a766a["groq.py"]
  9d4d24e2_43fa_881e_628f_8a0a55cde2e6 -->|defined in| 0e434ace_bc91_58ed_0c26_ebc25d9a766a
  d3a08b19_6b17_3730_f767_a9f61415fb56["translate_content()"]
  d3a08b19_6b17_3730_f767_a9f61415fb56 -->|calls| 9d4d24e2_43fa_881e_628f_8a0a55cde2e6
  84304337_3d26_515e_aeb4_1effbf41e0bb["translate_content_chunk()"]
  84304337_3d26_515e_aeb4_1effbf41e0bb -->|calls| 9d4d24e2_43fa_881e_628f_8a0a55cde2e6
  4a0480f6_7bf8_0fd9_4661_c2a6287501d8["_parse_code_json()"]
  9d4d24e2_43fa_881e_628f_8a0a55cde2e6 -->|calls| 4a0480f6_7bf8_0fd9_4661_c2a6287501d8
  93add5be_b499_e5c1_485e_3c2cf6bd0ceb["_populate_extras()"]
  9d4d24e2_43fa_881e_628f_8a0a55cde2e6 -->|calls| 93add5be_b499_e5c1_485e_3c2cf6bd0ceb
  style 9d4d24e2_43fa_881e_628f_8a0a55cde2e6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/block_translators/groq.py lines 51–118

def _convert_to_v1_from_groq(message: AIMessage) -> list[types.ContentBlock]:
    """Convert groq message content to v1 format."""
    content_blocks: list[types.ContentBlock] = []

    if reasoning_block := _extract_reasoning_from_additional_kwargs(message):
        content_blocks.append(reasoning_block)

    if executed_tools := message.additional_kwargs.get("executed_tools"):
        for idx, executed_tool in enumerate(executed_tools):
            args: dict[str, Any] | None = None
            if arguments := executed_tool.get("arguments"):
                try:
                    args = json.loads(arguments)
                except json.JSONDecodeError:
                    if executed_tool.get("type") == "python":
                        try:
                            args = _parse_code_json(arguments)
                        except ValueError:
                            continue
                    elif (
                        executed_tool.get("type") == "function"
                        and executed_tool.get("name") == "python"
                    ):
                        # GPT-OSS
                        args = {"code": arguments}
                    else:
                        continue
            if isinstance(args, dict):
                name = ""
                if executed_tool.get("type") == "search":
                    name = "web_search"
                elif executed_tool.get("type") == "python" or (
                    executed_tool.get("type") == "function"
                    and executed_tool.get("name") == "python"
                ):
                    name = "code_interpreter"
                server_tool_call: types.ServerToolCall = {
                    "type": "server_tool_call",
                    "name": name,
                    "id": str(idx),
                    "args": args,
                }
                content_blocks.append(server_tool_call)
            if tool_output := executed_tool.get("output"):
                tool_result: types.ServerToolResult = {
                    "type": "server_tool_result",
                    "tool_call_id": str(idx),
                    "output": tool_output,
                    "status": "success",
                }
                known_fields = {"type", "arguments", "index", "output"}
                _populate_extras(tool_result, executed_tool, known_fields)
                content_blocks.append(tool_result)

    if isinstance(message.content, str) and message.content:
        content_blocks.append({"type": "text", "text": message.content})

    content_blocks.extend(
        {
            "type": "tool_call",
            "name": tool_call["name"],
            "args": tool_call["args"],
            "id": tool_call.get("id"),
        }
        for tool_call in message.tool_calls
    )

    return content_blocks

Domain

Subdomains

Frequently Asked Questions

What does _convert_to_v1_from_groq() do?
_convert_to_v1_from_groq() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/groq.py.
Where is _convert_to_v1_from_groq() defined?
_convert_to_v1_from_groq() is defined in libs/core/langchain_core/messages/block_translators/groq.py at line 51.
What does _convert_to_v1_from_groq() call?
_convert_to_v1_from_groq() calls 2 function(s): _parse_code_json, _populate_extras.
What calls _convert_to_v1_from_groq()?
_convert_to_v1_from_groq() is called by 2 function(s): translate_content, translate_content_chunk.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free