Skip to content

Commit

Permalink
update notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-sol committed Feb 22, 2024
1 parent bc02571 commit 08b8fbf
Show file tree
Hide file tree
Showing 14 changed files with 16,743 additions and 17,690 deletions.
158 changes: 87 additions & 71 deletions notebooks/01-Basic_Tutor.ipynb
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMWsO+T66P1RZEeDMmjXjcm",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/towardsai/ai-tutor-rag-system/blob/main/notebooks/01-Basic_Tutor.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Install Packages and Setup Variables"
],
"metadata": {
"id": "DMXyyXD0xix9"
}
},
"source": [
"# Install Packages and Setup Variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"id": "o4Q0N2omkAoZ"
},
Expand All @@ -48,67 +32,72 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "xxK7EAAvr2aT"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
"os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\""
],
"metadata": {
"id": "xxK7EAAvr2aT"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"source": [
"# Load the API client"
],
"metadata": {
"id": "68RbStS-xpbL"
}
},
"source": [
"# Load the API client"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "La8hdWqJkFkh"
},
"outputs": [],
"source": [
"from openai import OpenAI\n",
"\n",
"# Defining the \"client\" object that enables\n",
"# us to connect to OpenAI API endpoints.\n",
"client = OpenAI()"
],
"metadata": {
"id": "La8hdWqJkFkh"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"source": [
"# Query the API"
],
"metadata": {
"id": "CC-sa_uv6J2C"
}
},
"source": [
"# Query the API"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "7JRrn0uIsBfg"
},
"outputs": [],
"source": [
"# Define two questions: 1) Related to AI, 2) Unrelated topic.\n",
"# These questions will be used to evaluate model's performance.\n",
"QUESTION_AI = \"List a number of famous artificial intelligence frameworks?\"\n",
"QUESTION_NOT_AI = \"What is the name of the highest mountain in the world and its height?\""
],
"metadata": {
"id": "7JRrn0uIsBfg"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "CcP26IauuBuV"
},
"outputs": [],
"source": [
"# Defining a function to answer a question using \"gpt-3.5-turbo-16k\" model.\n",
"def ask_ai_tutor(question):\n",
Expand Down Expand Up @@ -137,32 +126,22 @@
"\n",
" except Exception as e:\n",
" return f\"An error occurred: {e}\""
],
"metadata": {
"id": "CcP26IauuBuV"
},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"source": [
"# Ask the AI-related question.\n",
"res = ask_ai_tutor( QUESTION_AI )\n",
"print( res )"
],
"execution_count": 6,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "W_dbwURpufR7",
"outputId": "196c4c2f-9b7f-4302-a6e5-3ba2b8cbb37e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"Sure! There are several famous artificial intelligence frameworks that are widely used in the field. Some of the popular ones include:\n",
"\n",
Expand All @@ -179,32 +158,69 @@
"These are just a few examples of famous AI frameworks, and there are many others available depending on specific needs and preferences.\n"
]
}
],
"source": [
"# Ask the AI-related question.\n",
"res = ask_ai_tutor( QUESTION_AI )\n",
"print( res )"
]
},
{
"cell_type": "code",
"source": [
"# Ask the unrelated question.\n",
"res = ask_ai_tutor( QUESTION_NOT_AI )\n",
"print( res )"
],
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "37YuVJQquhpN",
"outputId": "17c4b543-65fe-4cfb-9020-2d44bfef2eac"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"output_type": "stream",
"text": [
"I'm sorry, but I cannot answer that question as it is not related to artificial intelligence.\n"
]
}
],
"source": [
"# Ask the unrelated question.\n",
"res = ask_ai_tutor( QUESTION_NOT_AI )\n",
"print( res )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"authorship_tag": "ABX9TyMWsO+T66P1RZEeDMmjXjcm",
"include_colab_link": true,
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
]
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit 08b8fbf

Please sign in to comment.