Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 9d80f2c

Browse files
committed
update LLMU notebooks - RAG etc
1 parent ce24aef commit 9d80f2c

9 files changed

+488
-798
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22

33
Welcome to the Cohere Cookbook! This repository provides a collection of examples to help you get started with the Cohere API. These examples contain step-by-step guides, with code examples and explanations, to help you understand and use the API effectively.
44

5-
# Getting Started
6-
The cookbook is grouped into two categories. To get started, go to any of the categories below. You will find more details there, but here's a summary:
5+
# Categories
6+
The cookbook is grouped into two categories. To get started, go to any of the categories below.
77

88
| Category | Description |
99
| --- | --- |
1010
| [Guides](notebooks/guides/) | Tutorials and step-by-step guides covering a range of topics, providing practical guidance and code examples.
11-
| [LLM University](notebooks/llmu/) | Guides for getting started with Cohere, starting with basic usage and progressing to advanced topics. The code companion to the full [LLM University course](https://llm.university/).|
11+
| [LLM University](notebooks/llmu/) | Guides for getting started with Cohere, starting with basic usage and progressing to advanced topics. The code companion to the full [LLM University course](https://llm.university/).|
12+
13+
# Getting Started
14+
If you are looking for a quick tour of the Cohere API, the following notebooks will help you get up and running.
15+
16+
- [**Text Generation**](notebooks/llmu/Building_a_Chatbot.ipynb): Get started with the Command R+ model by building a chatbot using Cohere’s Chat endpoint. Build a chatbot that can respond to user messages and maintain the context of the conversation.
17+
18+
- [**Text Embeddings**](notebooks/llmu/Introduction_Text_Embeddings.ipynb): Get started with the Embed model by generating text embeddings for a dataset. Observe graphically the relationships between documents and explore how to leverage embeddings for semantic search and clustering.
19+
20+
- [**Retrieval-Augmented Generation**](notebooks/llmu/RAG_with_Chat_Embed_and_Rerank.ipynb): Build a RAG-powered chatbot that can extract relevant information from external documents and produce verifiable, inline citations in its responses. This leverages the Chat endpoint as well as the Embed v3 and Rerank 3 models.
21+
22+
- [**Tool Use**](notebooks/Vanilla_Tool_Use.ipynb): Tool use allows you to connect LLMs to external tools like search engines, APIs, functions, databases, etc. In this example, build an assistant that that can query sales reports and a product catalog and provide its analysis.
23+
24+
- [**Multi-Step Tool Use**](notebooks/Data_Analyst_Agent_Cohere_and_Langchain.ipynb): Multi-step tool use allows an LLM to call more than one tool in a sequence of steps, using the results from one tool call in a subsequent step. In this example, build a simple data analyst agent that is able to search the web and run code in a Python interpreter. This agent uses Cohere's Command R+ model and Langchain.

notebooks/llmu/Embed_Endpoint.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"source": [
1818
"# The Embed Endpoint\n",
1919
"\n",
20-
"In this lab, we'll learn how to analyze a text dataset using Cohere's Embed cohere endpoint. This colab accompanies the [Classify endpoint lesson](https://docs.cohere.com/docs/embed-endpoint/) of LLM University."
20+
"In this lab, we'll learn how to analyze a text dataset using Cohere's Embed cohere endpoint. This colab accompanies the [Embed endpoint lesson](https://docs.cohere.com/docs/embed-endpoint/) of LLM University."
2121
]
2222
},
2323
{

notebooks/llmu/Visualizing_Text_Embeddings.ipynb renamed to notebooks/llmu/Introduction_Text_Embeddings.ipynb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/Visualizing_Text_Embeddings.ipynb\">\n",
7+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/Introduction_Text_Embeddings.ipynb\">\n",
88
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
99
"</a>"
1010
]
@@ -15,23 +15,11 @@
1515
"id": "psRggLwvhi1E"
1616
},
1717
"source": [
18-
"# Visualizing Text Embeddings\n",
18+
"# Introduction to Text Embeddings\n",
1919
"\n",
2020
"Text embeddings are a useful way to turn text into numbers that capture its meaning and context. In this notebook, you'll learn how to put them into practice using Cohere's [Embed endpoint](https://docs.cohere.com/reference/embed). You'll calculate embeddings for a dataset of sentences, and plot them in the plane to observe graphically that indeed similar sentences are mapped to close points in the embedding. You'll also explore how to leverage embeddings for semantic search and clustering."
2121
]
2222
},
23-
{
24-
"cell_type": "markdown",
25-
"metadata": {},
26-
"source": [
27-
"## Overview\n",
28-
"\n",
29-
"This notebook has three main sections, each with a corresponding blog post:\n",
30-
"- **Introduction to Text Embeddings** - Understand the intuition behind text embeddings. _Read the accompanying [blog post here](https://txt.cohere.ai/introduction-to-text-embeddings/)._ \n",
31-
"- **Introduction to Semantic Search** - Learn how to use embeddings to build a search capability that surfaces relevant information based on the semantic meaning of a query. _Read the accompanying [blog post here](https://txt.cohere.ai/introduction-to-semantic-search/)._\n",
32-
"- **Clustering with Embeddings** - Learn how to use embeddings to group similar documents into clusters, to discover emerging patterns in the documents. _Read the accompanying [blog post here](https://docs.cohere.com/docs/clustering-with-embeddings)._"
33-
]
34-
},
3523
{
3624
"cell_type": "markdown",
3725
"metadata": {},
@@ -69,13 +57,6 @@
6957
"from sklearn.cluster import KMeans"
7058
]
7159
},
72-
{
73-
"cell_type": "markdown",
74-
"metadata": {},
75-
"source": [
76-
"Fill in your Cohere API key in the next cell. To do this, begin by [signing up to Cohere](https://os.cohere.ai/) (for free!) if you haven't yet. Then get your API key [here](https://dashboard.cohere.com/api-keys)."
77-
]
78-
},
7960
{
8061
"cell_type": "code",
8162
"execution_count": 3,
@@ -94,8 +75,6 @@
9475
"\n",
9576
"In this section, we understand the intuition behind text embeddings.\n",
9677
"\n",
97-
"_Read the accompanying [blog post here](https://txt.cohere.ai/introduction-to-text-embeddings/)._\n",
98-
"\n",
9978
"### Step 1: Prepare the Dataset\n",
10079
"\n",
10180
"We'll work with a subset of the Airline Travel Information System (ATIS) dataset ([source](https://aclanthology.org/H90-1021/)), created based on customer inquiries related to flight bookings, flight departures, arrivals, delays, and cancellations. In the next code cell, we create and preview a dataframe `df` containing 91 queries."

notebooks/llmu/Introduction_to_RAG.ipynb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
},
216216
{
217217
"cell_type": "code",
218-
"execution_count": null,
218+
"execution_count": 2,
219219
"metadata": {
220220
"id": "CdxeI3XW4yIH"
221221
},
@@ -256,7 +256,7 @@
256256
},
257257
{
258258
"cell_type": "code",
259-
"execution_count": null,
259+
"execution_count": 3,
260260
"metadata": {
261261
"colab": {
262262
"base_uri": "https://localhost:8080/"
@@ -269,18 +269,15 @@
269269
"name": "stdout",
270270
"output_type": "stream",
271271
"text": [
272-
"The tallest living species of penguin is the emperor penguin (Apteryx australis), which can measure up to 1.6 to 1.8 m (5.2 to 6 ft) when fully grown.\n",
272+
"The tallest living penguins are emperor penguins, which are found only in Antarctica.\n",
273273
"\n",
274274
"CITATIONS:\n",
275-
"start=45 end=60 text='emperor penguin' document_ids=['doc_0']\n",
276-
"start=61 end=80 text='(Apteryx australis)' document_ids=['doc_0']\n",
277-
"start=106 end=118 text='1.6 to 1.8 m' document_ids=['doc_0']\n",
278-
"start=119 end=132 text='(5.2 to 6 ft)' document_ids=['doc_0']\n",
275+
"start=32 end=48 text='emperor penguins' document_ids=['doc_0']\n",
276+
"start=66 end=85 text='only in Antarctica.' document_ids=['doc_1']\n",
279277
"\n",
280278
"DOCUMENTS:\n",
281279
"{'id': 'doc_0', 'text': 'Emperor penguins are the tallest.', 'title': 'Tall penguins'}\n",
282-
"{'id': 'doc_1', 'text': 'Emperor penguins only live in Antarctica.', 'title': 'Penguin habitats'}\n",
283-
"{'id': 'doc_2', 'text': 'Animals are different from plants.', 'title': 'What are animals?'}\n"
280+
"{'id': 'doc_1', 'text': 'Emperor penguins only live in Antarctica.', 'title': 'Penguin habitats'}\n"
284281
]
285282
}
286283
],
@@ -290,9 +287,9 @@
290287
"\n",
291288
"# Generate the response\n",
292289
"response = co.chat_stream(message=message,\n",
290+
" model=\"command-r-plus\",\n",
293291
" documents=documents)\n",
294292
"\n",
295-
"\n",
296293
"# Display the response\n",
297294
"citations = []\n",
298295
"cited_documents = []\n",
@@ -302,8 +299,8 @@
302299
" print(event.text, end=\"\")\n",
303300
" elif event.event_type == \"citation-generation\":\n",
304301
" citations.extend(event.citations)\n",
305-
" elif event.event_type == \"search-results\":\n",
306-
" cited_documents = event.documents\n",
302+
" elif event.event_type == \"stream-end\":\n",
303+
" cited_documents = event.response.documents\n",
307304
"\n",
308305
"# Display the citations and source documents\n",
309306
"if citations:\n",
@@ -326,7 +323,16 @@
326323
"name": "python3"
327324
},
328325
"language_info": {
329-
"name": "python"
326+
"codemirror_mode": {
327+
"name": "ipython",
328+
"version": 3
329+
},
330+
"file_extension": ".py",
331+
"mimetype": "text/x-python",
332+
"name": "python",
333+
"nbconvert_exporter": "python",
334+
"pygments_lexer": "ipython3",
335+
"version": "3.11.4"
330336
}
331337
},
332338
"nbformat": 4,

0 commit comments

Comments
 (0)