Langchain Output Formattingのロゴ

Langchain Output Formatting

組織
Seeed-Projects
langchain-output-formatting

Format LLM output using Langchain on Jetson for structured smart home control signals. Deploys a local chatbot with Gradio UI that uses LlamaCpp and Langchain's StructuredOutputParser to produce JSON-formatted responses. Requires JetPack 5.0+ and a GGUF model.

概要

公開者Seeed-Projects
リポジトリSeeed-Jetson-DevelopTool
スキル名langchain-output-formatting
スター
58
フォーク
9
同梱ファイル
2
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 2個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    Seeed-ProjectsがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Langchain Output Formatting」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/Seeed-Projects/Seeed-Jetson-DevelopTool/tree/main/seeed_jetson_develop/skills/openclaw/langchain-output-formatting
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Seeed-Projects/Seeed-Jetson-DevelopTool.git /tmp/Seeed-Jetson-DevelopTool
mkdir -p .claude/skills
cp -r /tmp/Seeed-Jetson-DevelopTool/seeed_jetson_develop/skills/openclaw/langchain-output-formatting .claude/skills/langchain-output-formatting
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでLangchain Output Formattingを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にLangchain Output Formattingを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Langchain Output Formattingは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Format LLM Output with Langchain on Jetson

Use Langchain's StructuredOutputParser to constrain LLM output into structured JSON for smart home control. The chatbot runs locally on Jetson using LlamaCpp with a Gradio web interface.


Execution model

Run one phase at a time. After each phase:

  • Relay all output to the user.
  • If output contains [STOP] → stop, consult the failure decision tree.
  • If output ends with [OK] → tell the user "Phase N complete" and proceed.

Prerequisites

RequirementDetail
HardwareJetson device (e.g. reComputer J4012)
JetPack5.0+
ModelLlama 2 7B Chat GGUF (Q4_0 quantization)
Pythonpip3 available

Phase 1 — Install dependencies (~3 min)

bash
pip3 install --no-cache-dir --verbose "langchain[llm]" openai
pip3 install --no-cache-dir --verbose gradio==3.38.0

[OK] when both packages install without error. [STOP] if pip3 fails — check Python version and pip availability.


Phase 2 — Download GGUF model (~5–15 min)

Download the Llama 2 7B Chat GGUF model (Q4_0 quantization) from Hugging Face:

bash
mkdir -p ~/models
# Download llama-2-7b-chat.Q4_0.gguf from Hugging Face
# Example using wget or huggingface-cli:
pip3 install huggingface-hub
huggingface-cli download TheBloke/Llama-2-7B-Chat-GGUF llama-2-7b-chat.Q4_0.gguf --local-dir ~/models

Verify:

bash
ls -lh ~/models/llama-2-7b-chat.Q4_0.gguf

[OK] when the GGUF file exists (~3.8 GB). [STOP] if download fails — check network and disk space.


Phase 3 — Create the chatbot script

Create format_opt.py with the following content. The script uses Langchain's StructuredOutputParser with ResponseSchema to define output fields (user_input, suggestion, control signal, temperature), then wraps a LlamaCpp model in a Gradio chat interface:

bash
cat > format_opt.py << 'PYEOF'
import copy
import gradio as gr
from langchain.llms import LlamaCpp
from langchain.output_parsers import StructuredOutputParser, ResponseSchema
from langchain.prompts import PromptTemplate

class ChatBot:
    def __init__(self, llama_model_path, history_length=3):
        self.chat_history = []
        self.history_threshold = history_length
        self.llm = LlamaCpp(
            model_path=llama_model_path,
            temperature=0.75,
            max_tokens=2000,
            top_p=1
        )
        response_schemas = [
            ResponseSchema(name="user_input", description="This is the user's input"),
            ResponseSchema(name="suggestion", type="string", description="your suggestion"),
            ResponseSchema(name="control", description="This is your response"),
            ResponseSchema(name="temperature", type="int",
                           description="Degrees centigrade temperature of the air conditioner.")
        ]
        self.output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
        self.format_instructions = self.output_parser.get_format_instructions()
        self.template = """
            Now you are a smart speaker, and you need to determine whether to turn on the air conditioner based on the user's input.
            In the suggestion section, please reply normal conversation.
            In the control section, if you need to turn on the air conditioner, please reply with <1>; if you need to turn off the air conditioner, please reply with <0>.
            {format_instructions}
            Please do not generate any comments.
            % USER INPUT:
            {user_input}
            YOUR RESPONSE:
        """
        self.prompt = PromptTemplate(
            input_variables=["user_input"],
            partial_variables={"format_instructions": self.format_instructions},
            template=self.template
        )

    def format_chat_prompt(self, message):
        prompt = ""
        for turn in self.chat_history:
            user_message, bot_message = turn
            prompt = f"{prompt}\nUser: {user_message}\nAssistant: {bot_message}"
        prompt = f"{prompt}\nUser: {message}\nAssistant:"
        return prompt

    def respond(self, message):
        prompt = self.prompt.format(user_input=message)
        formatted_prompt = self.format_chat_prompt(prompt)
        bot_message = self.llm(formatted_prompt)
        if len(self.chat_history) >= self.history_threshold:
            del self.chat_history[0]
        self.chat_history.append((message, bot_message))
        return "", self.chat_history

    def run_webui(self):
        with gr.Blocks() as demo:
            gr.Markdown("# Format Output of LLM Demo")
            chatbot = gr.Chatbot(height=500)
            msg = gr.Textbox(label="Prompt")
            btn = gr.Button("Submit")
            clear = gr.ClearButton(components=[msg, chatbot], value="Clear console")
            btn.click(self.respond, inputs=[msg], outputs=[msg, chatbot])
            msg.submit(self.respond, inputs=[msg], outputs=[msg, chatbot])
        gr.close_all()
        demo.launch()

if __name__ == '__main__':
    chatbot_ins = ChatBot("/home/nvidia/models/llama-2-7b-chat.Q4_0.gguf")
    chatbot_ins.run_webui()
PYEOF

Update the model path in the script to match your actual GGUF location.

[OK] when file is created.


Phase 4 — Run the chatbot (~1 min to start)

bash
python3 format_opt.py

Open a browser and navigate to http://<jetson-ip>:7861/.

Test by typing prompts like "It's really hot today" — the LLM should respond with structured JSON containing control signals.

[OK] when the Gradio UI loads and the LLM returns formatted JSON output. [STOP] if the model fails to load or Gradio crashes.


Failure decision tree

SymptomAction
pip3 install langchain failsUpgrade pip: pip3 install --upgrade pip. Check Python ≥ 3.8.
ModuleNotFoundError: llama_cppInstall: pip3 install llama-cpp-python. May need CMAKE_ARGS="-DLLAMA_CUBLAS=on" for GPU.
Model loading OOMUse a smaller quantization (Q2_K) or free memory. Check with free -h.
Gradio won't start on port 7861Port in use. Kill existing process or set demo.launch(server_port=7862).
LLM output not valid JSONAdjust temperature lower (0.3–0.5). Ensure format_instructions are in the prompt.
Browser can't reach JetsonCheck firewall: sudo ufw allow 7861. Verify IP with hostname -I.

Reference files

  • references/source.body.md — Full Seeed Wiki tutorial with code examples, screenshots, and next steps for Riva integration (reference only)

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Langchain Output Formatting」では何ができますか?

Format LLM output using Langchain on Jetson for structured smart home control signals. Deploys a local chatbot with Gradio UI that uses LlamaCpp and Langchain's StructuredOutputParser to produce JSON-formatted responses. Requires JetPack 5.0+ and a GGUF model.

TypingMindでLangchain Output Formattingを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Langchain Output Formattingはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにLangchain Output Formattingをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/Seeed-Projects/Seeed-Jetson-DevelopTool/tree/main/seeed_jetson_develop/skills/openclaw/langchain-output-formattingを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Langchain Output Formattingを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Langchain Output Formattingで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもLangchain Output Formattingを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Langchain Output Formatting」は無料ですか?

はい。Seeed-ProjectsがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇