_convert_from_v1_to_groq() — langchain Function Reference
Architecture documentation for the _convert_from_v1_to_groq() function in _compat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8c517c3f_5f8e_2502_f1c7_23d229230a92["_convert_from_v1_to_groq()"] ef83f101_bef8_8169_a129_dfe165c89407["_compat.py"] 8c517c3f_5f8e_2502_f1c7_23d229230a92 -->|defined in| ef83f101_bef8_8169_a129_dfe165c89407 style 8c517c3f_5f8e_2502_f1c7_23d229230a92 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/groq/langchain_groq/_compat.py lines 9–71
def _convert_from_v1_to_groq(
content: list[types.ContentBlock],
model_provider: str | None,
) -> tuple[list[dict[str, Any] | str], dict]:
new_content: list = []
new_additional_kwargs: dict = {}
for i, block in enumerate(content):
if block["type"] == "text":
new_content.append({"text": block.get("text", ""), "type": "text"})
elif (
block["type"] == "reasoning"
and (reasoning := block.get("reasoning"))
and model_provider == "groq"
):
new_additional_kwargs["reasoning_content"] = reasoning
elif block["type"] == "server_tool_call" and model_provider == "groq":
new_block = {}
if "args" in block:
new_block["arguments"] = json.dumps(block["args"])
if idx := block.get("extras", {}).get("index"):
new_block["index"] = idx
if block.get("name") == "web_search":
new_block["type"] = "search"
elif block.get("name") == "code_interpreter":
new_block["type"] = "python"
else:
new_block["type"] = ""
if i < len(content) - 1 and content[i + 1]["type"] == "server_tool_result":
result = cast("types.ServerToolResult", content[i + 1])
for k, v in result.get("extras", {}).items():
new_block[k] = v # noqa: PERF403
if "output" in result:
new_block["output"] = result["output"]
if "executed_tools" not in new_additional_kwargs:
new_additional_kwargs["executed_tools"] = []
new_additional_kwargs["executed_tools"].append(new_block)
elif block["type"] == "server_tool_result":
continue
elif (
block["type"] == "non_standard"
and "value" in block
and model_provider == "groq"
):
new_content.append(block["value"])
else:
new_content.append(block)
# For consistency with v0 payloads, we cast single text blocks to str
if (
len(new_content) == 1
and isinstance(new_content[0], dict)
and new_content[0].get("type") == "text"
and (text_content := new_content[0].get("text"))
and isinstance(text_content, str)
):
return text_content, new_additional_kwargs
return new_content, new_additional_kwargs
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does _convert_from_v1_to_groq() do?
_convert_from_v1_to_groq() is a function in the langchain codebase, defined in libs/partners/groq/langchain_groq/_compat.py.
Where is _convert_from_v1_to_groq() defined?
_convert_from_v1_to_groq() is defined in libs/partners/groq/langchain_groq/_compat.py at line 9.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free