Notebooks
A
Azure
Working With Langchain

Working With Langchain

azure-openai-samplesBasic_Sampleslangchain

How to use LangChain and Azure OpenAI with Python

Langchain is an open source framework for developing applications using large language models (LLM).

This guide will demonstrate how to setup and use Azure OpenAI models' API with LangChain.

Set Up

The following libraries must be installed to use LangChain with Azure OpenAI.

[36]

API Configuation and Deployed Model Setup

After installing the necessary libraies, the API must be configured. The code below shows how to configure the API directly in your Python environment.

[42]

Deployed Model Setup

[43]
AIMessage(content="In the realm of dreams, where thoughts take flight,\nA tapestry of words, I shall now write.\nWith ink and quill, I'll weave a tale,\nOf love and hope, where hearts prevail.\n\nIn meadows adorned with flowers so fair,\nA gentle breeze whispers secrets in the air.\nThe sun shines bright, painting the sky,\nA canvas of colors, where dreams never die.\n\nBeneath a canopy of stars, we shall dance,\nLost in a moment, in a lover's trance.\nOur hearts entwined, beats synchronized,\nA symphony of love, never compromised.\n\nThrough valleys of sorrow, we shall tread,\nWith courage and strength, our fears we'll shed.\nFor love, a beacon, shall guide our way,\nThrough darkest nights, to a brighter day.\n\nIn the depths of silence, a whispered prayer,\nFor peace and harmony, beyond compare.\nMay kindness bloom, like flowers in spring,\nAnd compassion's song, forever sing.\n\nOh, let this poem be a gentle reminder,\nThat within us all, love is a powerful binder.\nFor in these words, a message so true,\nThat love's embrace can heal and renew.\n\nSo let us cherish, this gift we possess,\nThe power of words, to heal and impress.\nThrough poetry's grace, may hearts be moved,\nAnd in its beauty, we shall be proved.", additional_kwargs={}, example=False)

PromptTemplates

Langchain provides a built in PromptsTemplate module to simplify the construction of prompts to get more specific answers.

[44]
Example #1:
content='A highly recommended face wash for acne-prone skin is the "Neutrogena Oil-Free Acne Wash." This product contains salicylic acid, which helps to treat and prevent acne by unclogging pores and reducing inflammation. It is oil-free, non-comedogenic, and gentle enough for daily use. Additionally, it effectively removes dirt, excess oil, and makeup without over-drying the skin.' additional_kwargs={} example=False


Example #2:
If you're looking for warm weather and beautiful beaches in December, here are a few destinations you might consider:

1. Maldives: This tropical paradise offers pristine beaches, crystal-clear waters, and luxurious resorts. December is a great time to visit, with temperatures averaging around 28°C (82°F).

2. Thailand: Thailand's southern islands, such as Phuket, Krabi, and Koh Samui, offer warm weather and stunning beaches in December. You can relax on the white sands, go snorkeling or diving, and explore the vibrant local culture.

3. Bali, Indonesia: Bali is a popular destination known for its stunning beaches, lush landscapes, and vibrant culture. In December, you can enjoy warm temperatures and take part in water sports or simply unwind by the beach.

4. Cancun, Mexico: Cancun is a favorite destination for beach lovers, with its turquoise waters and soft white sands. December is a great time to visit, with temperatures around 27°C (81°F), and you can also explore the nearby Mayan ruins.

5. Seychelles: This archipelago in the Indian Ocean boasts some of the world's most beautiful beaches. December is an excellent time to visit, as the weather is warm and you can enjoy activities like snorkeling, diving, and island hopping.

Remember to check travel restrictions and safety guidelines before planning your trip, as they may vary due to the ongoing COVID-19 pandemic.

Chains

There are many applications of chains that allow you to combine numerous LLM calls and actions.

Simple Sequential Chains

Allow you to feed the output of one LLM Chain as input for another.

[45]
[46]
[47]
[48]
[49]


> Entering new SimpleSequentialChain chain...
DIY Sparkling Fairy Wand:

Materials needed:
- Wooden dowel or stick
- Glitter foam sheets in various colors
- Ribbon or tulle
- Craft glue
- Scissors
- Decorative gems or sequins
- Glitter glue (optional)

Instructions:
1. Begin by cutting out a star shape from one of the glitter foam sheets. This will be the top of the wand.
2. Cut out a long strip of foam from another color and wrap it around the wooden dowel or stick, starting from the bottom. Secure it with craft glue.
3. Cut out smaller shapes like hearts, butterflies, or flowers from different colored glitter foam sheets.
4. Use craft glue to stick these shapes onto the wrapped foam strip, creating a beautiful pattern. Let them dry completely.
5. Once the foam shapes are secure, add some extra sparkle by applying glitter glue to the edges or adding decorative gems or sequins.
6. Finally, tie ribbons or tulle strands to the bottom of the wooden dowel or stick for an extra touch of magic.
7. Let the wand dry completely before giving it to the 5-year-old girl to play with.

This DIY project will allow the 5-year-old girl to express her creativity and imagination as she creates her very own sparkling fairy wand. She can use it for pretend play, dress-up parties, or even as a room decoration.
DIY Sparkling Fairy Wand:

Materials needed:
- Wooden dowel or stick
- Glitter foam sheets in various colors
- Ribbon or tulle
- Craft glue
- Scissors
- Decorative gems or sequins
- Glitter glue (optional)

Instructions:
1. Cut out a star shape from a glitter foam sheet for the top of the wand.
2. Wrap a long strip of foam from another color around the wooden dowel or stick, securing it with craft glue.
3. Cut out smaller shapes like hearts, butterflies, or flowers from different colored glitter foam sheets.
4. Use craft glue to stick these shapes onto the wrapped foam strip to create a pattern. Let them dry completely.
5. Add extra sparkle by applying glitter glue to the edges or adding decorative gems or sequins.
6. Tie ribbons or tulle strands to the bottom of the wooden dowel or stick for an extra touch of magic.
7. Let the wand dry completely before giving it to the 5-year-old girl to play with.

This DIY project allows the 5-year-old girl to express her creativity and imagination. She can use the sparkling fairy wand for pretend play, dress-up parties, or even as a room decoration.

> Finished chain.