Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
AI Networking Cookbook
AI Networking Cookbook

AI Networking Cookbook: Practical recipes for AI-assisted network automation and development

eBook
$30.79 $43.99
Paperback
$43.99 $54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

AI Networking Cookbook

Local AI Model Ollama

Ollama is an easy way to experiment with running language model locally.

Getting Ready

Ensure you have an Ollama account, sign up athttps://ollama.com/signup if you need to. Also make sure you have Docker Engine (https://www.docker.com/) and docker-compose (https://docs.docker.com/compose/) are installed on the machine you wish to run the images on.

How to do it…

The Ollama site allows easy-to-download docker images that can switch between models easily.

  1. Launch Docker engine, such as docker.desktop.
  2. Write the docker-compose file with text editor, name it docker-compose.yml.
    networks:
      ollama:
    
    services:
      ollama:
        image: ollama/ollama
        networks:
          - ollama
        # deploy:
        #   resources:
        #     reservations:
        # ...

Python Script with Ollama

We can use a Python script to programmatically interact with the local Ollama LLM model.

Getting Ready

Use the existing Python virtual environment or create a new one and install the ollama Python library:

$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install ollama

How to do it…

  1. Construct a simple Python library:
    from ollama import Client
    
    client = Client(host='http://localhost:11434')
    response = client.chat(model='gemma3:1b', messages=[
        {
            'role': 'user',
            'content': 'What is Layer 2 of the OSI model?',
        },
    ])
    print(response['message']['content'])
  2. Execute and observe the output:
    $ python example_1.py
    Layer 2 of the OSI model is the **Data...

2.1 Using curl for OpenAI API communication

curl (https://github.com/curl/curl) is one of the most ubiquitous command-line tools when it comes to testing API communications. It allows us to learn the fundamentals of API communication with OpenAI, such as establishing connectivity, handling authentication, and processing responses directly in the command-line interface (CLI).

Getting ready

For many Linux distributions, curl is installed by default. We can check whether that is the case with the curl command:

$ curl --version
curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 libpsl/0.21.2 (+libidn2/2.3.7) libssh/0.10.6/openssl/zlib nghttp2/1.59.0 librtmp/2.3 OpenLDAP/2.6.7

However, if it is not already installed, you can find the installation instructions at https://curl.se/docs/install.html.

Additionally, make sure you obtain OpenAI keys and have them ready to go (see the Setting up an OpenAI environment...

2.2 Using Postman with the OpenAI API

When it comes to API testing, curl is great at stripping away all the non-essential items, such as the graphical user interface. But once we are familiar with the basic process, we might want to move on to more polished tools with more refined user interfaces. After all, typing in command-line options every single time is probably not your favorite activity in the day.

Postman (https://www.postman.com/) is another popular tool for working with APIs. It elevates your API testing capabilities by introducing a user-friendly graphical interface. Postman provides a professional-grade interface for API testing, development, and collaboration.

This recipe covers the basic features for using Postman with the OpenAI API, such as environmental variable management, automated testing, and team collaboration.

Getting ready

To use Postman, we need to either use the Postman web-based interface or download the Postman application specific to the...

2.3 Fine-tuning OpenAI responses

The OpenAI LLM base model, sometimes referred to as the foundation model, is amazingly functional and can handle most, if not all, the tasks we throw at it. As we have seen so far, it can help us with many general network engineering tasks, such as configuring VLANs, assigning IP addresses, and changing interface descriptions.

But one thing it does not currently do, as no out-of-the-box solution can do, is personalize the feedback for our specific organizational needs. For example, if our team wants to always use Loopback 0 for router-id when we configure BGP, the foundation model would not know that.

We can customize our OpenAI model for our specific needs by fine-tuning it. Fine-tuning allows us to teach OpenAI models our organization’s specific network configuration standard, for example, so that we do not just get the generic configurations.

In this recipe, we will learn how to prepare training data, execute the fine-tuning process...

2.4 Generating network topology with OpenAI

Show me a network engineer and I will show you an engineer who spends countless hours putting together network diagrams, drawing lines to illustrate connection points, and even trying to pick the color scheme that matches their artistic taste. If this sounds like you, you will like this recipe.

In this recipe, we will demonstrate how to automatically generate network topology using OpenAI’s LLM. Traditional topology generation relies heavily on both the engineer’s network knowledge and their familiarity with tools. If the engineer is used to Visio diagrams or draw.io, those are probably the tools they will use. However, we can use OpenAI to automatically generate a network topology diagram by interpreting the topology description and producing code for visualization purposes.

Getting ready

We will use several Python packages to complete this recipe. Please install the following packages in your virtual environment...

2.5 Generating methods of procedure (MOPs) with OpenAI

Any network engineer working in a medium to large-sized enterprise environment is probably familiar with the MOP document. The MOP is generally a detailed document outlining the steps for executing a specific task or process, often used in network engineering operations. An example would be a MOP to create a new VLAN, find an available IP block to be used with the VLAN, and then assign a gateway IP to the VLAN interface.

The MOP focuses on the technical aspect of the process and is often used in a form of knowledge transfer between senior to junior engineers, or just as a simple reminder of steps when a sleepy engineer is performing the task at 3 A.M. While the MOP is useful, creating it can be pretty boring. In this recipe, we will show you how to leverage OpenAI LLMs to help you create one.

Getting ready

We just need the openai Python package for this recipe.

How to do it…

  1. We will use the following...

Summary

In this chapter, we provided five comprehensive recipes that progressively built your expertise in leveraging OpenAI’s capabilities for network engineering tasks. Each recipe followed a practical, hands-on approach that you could immediately apply in your environment. More importantly, they were written with a network engineering focus, so they are relevant and applicable to our daily jobs.

In the next chapter, we will move on to one of the most important topics relating to AI LLMs: prompt engineering. See you there!

Get This Book’s PDF Version and Exclusive Extras

Scan the QR code (or go to packtpub.com/unlock). Search for this book by name, confirm the edition, and then follow the steps on the page.

Note: Keep your invoice handy. Purchases made directly from Packt...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Leverage AI assistants like OpenAI and Claude to build network automation solutions
  • Use prompt engineering and AI tools to automate network setup, monitoring, and threat detection
  • Build AI-assisted network configuration, monitoring, and management workflows with multi-vendor APIs
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Transform your approach to network automation with the power of AI LLM assistants guided by hands-on recipes for building custom automation solutions quickly using artificial intelligence. You’ll learn tools and techniques such as Vibe coding for conversational development, OpenAI API scripts, prompt engineering for better outputs, local LLM fine-tuning, combining models with LangChain, and Streamlit-based frontends development. The book progresses from simple Python scripts to advanced AI-assisted automation techniques, including multi-vendor API integration, showing you how AI can enhance network configuration, monitoring, security, and troubleshooting. Each recipe presents realistic mock data, complete code examples, and step-by-step guidance, creating a safe environment for experimentation while building a solid foundation for future production use. Whether you want to automate routine configuration, implement AI-driven troubleshooting, or build compliance monitoring systems, this cookbook helps you connect your networking expertise with the capabilities of modern AI.

Who is this book for?

The AI for Networking Cookbook is for experienced network engineers, network architects, and DevOps professionals who want to enhance their network automation capabilities using AI and LLM technologies. It is especially invaluable for networking professionals looking to integrate conversational AI development, prompt engineering, and modern AI tools like OpenAI APIs, LangChain, and local LLM models into their workflows. Familiarity with basic networking concepts, configurations, and Python is helpful, but no prior AI or advanced programming experience is required.

What you will learn

  • Understand the AI LLM landscape and key parameters for networking tasks
  • Create OpenAI-enabled scripts for daily network engineering workflows
  • Master prompt engineering techniques for improved AI outputs
  • Build local LLMs using Ollama for network applications
  • Chain language models with LangChain for complex network solutions
  • Develop AI application frontends using the Streamlit framework
  • Design robust backends for network AI applications
  • Build an end-to-end network copilot by integrating all the techniques you've learned

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 14, 2026
Length: 346 pages
Edition : 1st
Language : English
ISBN-13 : 9781805807988
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 14, 2026
Length: 346 pages
Edition : 1st
Language : English
ISBN-13 : 9781805807988
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

12 Chapters
The AI LLM Landscape and Key Parameters Chevron down icon Chevron up icon
OpenAI Recipes for Network Engineers Chevron down icon Chevron up icon
Prompt Engineering for Reliable Outputs Chevron down icon Chevron up icon
Local AI LLM Playground in Network Engineering Chevron down icon Chevron up icon
LangChain for Networking Tasks Chevron down icon Chevron up icon
Building an AI LLM Network Application Frontend with Streamlit Chevron down icon Chevron up icon
Building AI LLM Application Backends Chevron down icon Chevron up icon
Building a Network Co-Pilot Chevron down icon Chevron up icon
Network Monitoring and Performance Use Cases with MCP Chevron down icon Chevron up icon
Network Security through Vibe Coding Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon