Skip to content

Commit 48392a7

Browse files
committed
Add Getting Started with Pinecone Assistant Notebook
1 parent e0e4734 commit 48392a7

File tree

1 file changed

+233
-0
lines changed

1 file changed

+233
-0
lines changed
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"private_outputs": true,
7+
"provenance": []
8+
},
9+
"kernelspec": {
10+
"name": "python3",
11+
"display_name": "Python 3"
12+
},
13+
"language_info": {
14+
"name": "python"
15+
}
16+
},
17+
"cells": [
18+
{
19+
"cell_type": "markdown",
20+
"source": [
21+
"# Pinecone Assitant Getting Started\n",
22+
"\n",
23+
"Welcome to the getting started Notebook for [Pinecone assistant](https://www.pinecone.io/blog/pinecone-assistant/)!\n",
24+
"\n",
25+
"**!IMPORTANT!** - This code will not work unless your account has been invited to the private beta"
26+
],
27+
"metadata": {
28+
"id": "IpHsLVa0mAJe"
29+
}
30+
},
31+
{
32+
"cell_type": "code",
33+
"source": [
34+
"# Install pinecone client and assistants plugin\n",
35+
"!pip install --upgrade pinecone-client pinecone-plugin-assistant"
36+
],
37+
"metadata": {
38+
"id": "bAEbPIcn46t2"
39+
},
40+
"execution_count": null,
41+
"outputs": []
42+
},
43+
{
44+
"cell_type": "code",
45+
"source": [
46+
"# Install Pinecone notebook utilities including the Pinecone Connect widget\n",
47+
"!pip install pinecone-notebooks==0.1.1"
48+
],
49+
"metadata": {
50+
"id": "v6cdZP0ylfC5"
51+
},
52+
"execution_count": null,
53+
"outputs": []
54+
},
55+
{
56+
"cell_type": "code",
57+
"source": [
58+
"import os\n",
59+
"\n",
60+
"if not os.environ.get(\"PINECONE_API_KEY\"):\n",
61+
" from pinecone_notebooks.colab import Authenticate\n",
62+
" Authenticate()"
63+
],
64+
"metadata": {
65+
"id": "HO8ass1Qmdgq"
66+
},
67+
"execution_count": null,
68+
"outputs": []
69+
},
70+
{
71+
"cell_type": "markdown",
72+
"source": [],
73+
"metadata": {
74+
"id": "lixB5GGnmAHv"
75+
}
76+
},
77+
{
78+
"cell_type": "code",
79+
"source": [
80+
"from google.colab import userdata\n",
81+
"from pinecone import Pinecone\n",
82+
"\n",
83+
"pc = Pinecone(api_key=os.environ.get('PINECONE_API_KEY') or userdata.get('PINECONE_API_KEY'))\n",
84+
"\n",
85+
"assistant_name = 'HelloPineconeAssistant'\n",
86+
"\n",
87+
"metadata = {\"author\": \"Jane Doe\", \"version\": \"1.0\"}\n",
88+
"\n",
89+
"assistant = pc.assistant.create_assistant(\n",
90+
" assistant_name=assistant_name,\n",
91+
" metadata=metadata,\n",
92+
" timeout=30 # Wait 30 seconds for model creation to complete.\n",
93+
")"
94+
],
95+
"metadata": {
96+
"id": "unDcuyR2EaJr"
97+
},
98+
"execution_count": null,
99+
"outputs": []
100+
},
101+
{
102+
"cell_type": "code",
103+
"source": [
104+
"# Get assistant status\n",
105+
"assistant_status = pc.assistant.describe_assistant(assistant_name=assistant_name)\n",
106+
"assistant_status"
107+
],
108+
"metadata": {
109+
"id": "HJ5fxLvY97yF"
110+
},
111+
"execution_count": null,
112+
"outputs": []
113+
},
114+
{
115+
"cell_type": "code",
116+
"source": [
117+
"import random\n",
118+
"\n",
119+
"# Function to generate a random toy title\n",
120+
"def generate_toy_title():\n",
121+
" adjectives = [\"Amazing\", \"Super\", \"Fantastic\", \"Incredible\", \"Awesome\", \"Magical\", \"Ultimate\", \"Deluxe\"]\n",
122+
" nouns = [\"Robot\", \"Doll\", \"Blocks\", \"Puzzle\", \"Car\", \"Train\", \"Spaceship\", \"Dinosaur\", \"Unicorn\", \"Dragon\"]\n",
123+
" return f\"{random.choice(adjectives)} {random.choice(nouns)}\"\n",
124+
"\n",
125+
"# Function to generate a random toy description\n",
126+
"def generate_toy_description():\n",
127+
" features = [\n",
128+
" \"Made from high-quality materials\",\n",
129+
" \"Encourages imaginative play\",\n",
130+
" \"Develops problem-solving skills\",\n",
131+
" \"Suitable for ages 3 and up\",\n",
132+
" \"Battery-operated with flashing lights\",\n",
133+
" \"Includes multiple accessories\",\n",
134+
" \"Educational and fun\",\n",
135+
" \"Easy to clean and store\",\n",
136+
" \"Durable and long-lasting\",\n",
137+
" \"Promotes hand-eye coordination\"\n",
138+
" ]\n",
139+
" return \"\\n\".join(random.sample(features, 4))\n",
140+
"\n",
141+
"# Generate 75 toy entries\n",
142+
"toy_entries = []\n",
143+
"for i in range(75):\n",
144+
" title = generate_toy_title()\n",
145+
" description = generate_toy_description()\n",
146+
" entry = f\"{title}\\n\\n{description}\\n\\n{'='*30}\\n\\n\"\n",
147+
" toy_entries.append(entry)\n",
148+
"\n",
149+
"# Write to a local file in Colab\n",
150+
"file_path = \"/content/toy_descriptions.txt\"\n",
151+
"\n",
152+
"with open(file_path, 'w') as f:\n",
153+
" f.writelines(toy_entries)\n",
154+
"\n",
155+
"print(f\"Created toy descriptions file at {file_path}\")\n",
156+
"\n",
157+
"# Display the first few entries as a sample\n",
158+
"with open(file_path, 'r') as f:\n",
159+
" print(f.read().split('='*30)[:3])"
160+
],
161+
"metadata": {
162+
"id": "uqOICQmhNZiY"
163+
},
164+
"execution_count": null,
165+
"outputs": []
166+
},
167+
{
168+
"cell_type": "code",
169+
"source": [
170+
"import os\n",
171+
"\n",
172+
"# Target our existing Pinecone Assistant\n",
173+
"assistant = pc.assistant.Assistant(\n",
174+
" assistant_name=assistant_name,\n",
175+
")\n",
176+
"\n",
177+
"# Upload the file\n",
178+
"if os.path.exists(file_path):\n",
179+
" response = assistant.upload_file(\n",
180+
" file_path=file_path,\n",
181+
" timeout=None\n",
182+
" )\n",
183+
" print(f\"Uploaded {file_path}\")\n",
184+
" print(\"Response:\", response)\n",
185+
"else:\n",
186+
" print(f\"File not found: {file_path}\")"
187+
],
188+
"metadata": {
189+
"id": "CVixRBQfEKpo"
190+
},
191+
"execution_count": null,
192+
"outputs": []
193+
},
194+
{
195+
"cell_type": "code",
196+
"source": [
197+
"# List uploaded files our assistant is aware of\n",
198+
"files = assistant.list_files()\n",
199+
"files"
200+
],
201+
"metadata": {
202+
"id": "fqYUFoZ8N487"
203+
},
204+
"execution_count": null,
205+
"outputs": []
206+
},
207+
{
208+
"cell_type": "code",
209+
"source": [
210+
"# Chat with your Pinecone assistant, which automatically references\n",
211+
"# your uploaded documents in its responses\n",
212+
"from pinecone_plugins.assistant.models.chat import Message\n",
213+
"chat_context = [Message(content='Which toys include Unicorn in their name?')]\n",
214+
"response = assistant.chat_completions(messages=chat_context)\n",
215+
"print(response)"
216+
],
217+
"metadata": {
218+
"id": "iKLZtk7BOomq"
219+
},
220+
"execution_count": null,
221+
"outputs": []
222+
},
223+
{
224+
"cell_type": "code",
225+
"source": [],
226+
"metadata": {
227+
"id": "GQKf1l3rOFhy"
228+
},
229+
"execution_count": null,
230+
"outputs": []
231+
}
232+
]
233+
}

0 commit comments

Comments
 (0)