Skip to content

Commit 3cbe5c0

Browse files
authored
Merge pull request #369 from pinecone-io/add-pinecone-assistant-getting-started-notebook
Add Getting Started with Pinecone Assistant Notebook
2 parents e0e4734 + 6a862a0 commit 3cbe5c0

File tree

2 files changed

+799
-0
lines changed

2 files changed

+799
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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 Assistant 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 assistant 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": "markdown",
116+
"source": [
117+
"Upload the toys.txt file from the repository to Google Colab:\n",
118+
"\n",
119+
"1. Click the folder icon in Google Colab's left rail <--\n",
120+
"2. Click the upload button and use the file picker to select `toys.txt` from the subdirectory of https://github.com/pinecone-io/examples that contains this notebook\n",
121+
"3. Run the next cell to upload the toys.txt file to your Pinecone assistant\n"
122+
],
123+
"metadata": {
124+
"id": "nIyz6gYqAbHn"
125+
}
126+
},
127+
{
128+
"cell_type": "code",
129+
"source": [
130+
"import os\n",
131+
"\n",
132+
"# Target our existing Pinecone Assistant\n",
133+
"assistant = pc.assistant.Assistant(\n",
134+
" assistant_name=assistant_name,\n",
135+
")\n",
136+
"\n",
137+
"file_path = '/content/toys.txt'\n",
138+
"\n",
139+
"# Upload the file\n",
140+
"if os.path.exists(file_path):\n",
141+
" response = assistant.upload_file(\n",
142+
" file_path=file_path,\n",
143+
" timeout=None\n",
144+
" )\n",
145+
" print(f\"Uploaded {file_path}\")\n",
146+
" print(\"Response:\", response)\n",
147+
"else:\n",
148+
" print(f\"File not found: {file_path}\")"
149+
],
150+
"metadata": {
151+
"id": "CVixRBQfEKpo"
152+
},
153+
"execution_count": null,
154+
"outputs": []
155+
},
156+
{
157+
"cell_type": "code",
158+
"source": [
159+
"# List uploaded files our assistant is aware of\n",
160+
"files = assistant.list_files()\n",
161+
"files"
162+
],
163+
"metadata": {
164+
"id": "fqYUFoZ8N487"
165+
},
166+
"execution_count": null,
167+
"outputs": []
168+
},
169+
{
170+
"cell_type": "code",
171+
"source": [
172+
"# Chat with your Pinecone assistant, which automatically references\n",
173+
"# your uploaded documents in its responses\n",
174+
"from pinecone_plugins.assistant.models.chat import Message\n",
175+
"chat_context = [Message(content='Which toys teach STEM skills?')]\n",
176+
"response = assistant.chat_completions(messages=chat_context)\n",
177+
"print(response)"
178+
],
179+
"metadata": {
180+
"id": "iKLZtk7BOomq"
181+
},
182+
"execution_count": null,
183+
"outputs": []
184+
},
185+
{
186+
"cell_type": "code",
187+
"source": [],
188+
"metadata": {
189+
"id": "GQKf1l3rOFhy"
190+
},
191+
"execution_count": null,
192+
"outputs": []
193+
}
194+
]
195+
}

0 commit comments

Comments
 (0)