You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

458 lines
56 KiB

{
"cells": [
{
"cell_type": "markdown",
"id": "75e2ef28-594f-4c18-9d22-c6b8cd40ead2",
"metadata": {},
"source": [
"# Day 3 - Conversational AI - aka Chatbot!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "70e39cd8-ec79-4e3e-9c26-5659d42d0861",
"metadata": {},
"outputs": [],
"source": [
"# imports\n",
"\n",
"import os\n",
"from dotenv import load_dotenv\n",
"from openai import OpenAI\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "231605aa-fccb-447e-89cf-8b187444536a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OpenAI API Key exists and begins sk-proj-\n",
"Anthropic API Key exists and begins sk-ant-\n",
"Google API Key exists and begins AIzaSyBw\n"
]
}
],
"source": [
"# Load environment variables in a file called .env\n",
"# Print the key prefixes to help with any debugging\n",
"\n",
"load_dotenv(override=True)\n",
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
"\n",
"if openai_api_key:\n",
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
"else:\n",
" print(\"OpenAI API Key not set\")\n",
" \n",
"if anthropic_api_key:\n",
" print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
"else:\n",
" print(\"Anthropic API Key not set\")\n",
"\n",
"if google_api_key:\n",
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n",
"else:\n",
" print(\"Google API Key not set\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6541d58e-2297-4de1-b1f7-77da1b98b8bb",
"metadata": {},
"outputs": [],
"source": [
"# Initialize\n",
"\n",
"openai = OpenAI()\n",
"MODEL = 'gpt-4o-mini'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e16839b5-c03b-4d9d-add6-87a0f6f37575",
"metadata": {},
"outputs": [],
"source": [
"system_message = \"You are a helpful assistant\""
]
},
{
"cell_type": "markdown",
"id": "98e97227-f162-4d1a-a0b2-345ff248cbe7",
"metadata": {},
"source": [
"# Please read this! A change from the video:\n",
"\n",
"In the video, I explain how we now need to write a function called:\n",
"\n",
"`chat(message, history)`\n",
"\n",
"Which expects to receive `history` in a particular format, which we need to map to the OpenAI format before we call OpenAI:\n",
"\n",
"```\n",
"[\n",
" {\"role\": \"system\", \"content\": \"system message here\"},\n",
" {\"role\": \"user\", \"content\": \"first user prompt here\"},\n",
" {\"role\": \"assistant\", \"content\": \"the assistant's response\"},\n",
" {\"role\": \"user\", \"content\": \"the new user prompt\"},\n",
"]\n",
"```\n",
"\n",
"But Gradio has been upgraded! Now it will pass in `history` in the exact OpenAI format, perfect for us to send straight to OpenAI.\n",
"\n",
"So our work just got easier!\n",
"\n",
"We will write a function `chat(message, history)` where: \n",
"**message** is the prompt to use \n",
"**history** is the past conversation, in OpenAI format \n",
"\n",
"We will combine the system message, history and latest message, then call OpenAI."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1eacc8a4-4b48-4358-9e06-ce0020041bc1",
"metadata": {},
"outputs": [],
"source": [
"# Simpler than in my video - we can easily create this function that calls OpenAI\n",
"# It's now just 1 line of code to prepare the input to OpenAI!\n",
"\n",
"def chat(message, history):\n",
" messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
"\n",
" print(\"History is:\")\n",
" print(history)\n",
" print(\"And messages is:\")\n",
" print(messages)\n",
"\n",
" stream = openai.chat.completions.create(model=MODEL, messages=messages, stream=True)\n",
"\n",
" response = \"\"\n",
" for chunk in stream:\n",
" response += chunk.choices[0].delta.content or ''\n",
" yield response"
]
},
{
"cell_type": "markdown",
"id": "1334422a-808f-4147-9c4c-57d63d9780d0",
"metadata": {},
"source": [
"## And then enter Gradio's magic!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0866ca56-100a-44ab-8bd0-1568feaf6bf2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7877\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7877/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"History is:\n",
"[]\n",
"And messages is:\n",
"[{'role': 'system', 'content': 'You are a helpful assistant'}, {'role': 'user', 'content': 'How can I learn anatomy specifically for human tissues?'}]\n",
"History is:\n",
"[{'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}]\n",
"And messages is:\n",
"[{'role': 'system', 'content': 'You are a helpful assistant'}, {'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}, {'role': 'user', 'content': 'Give me more details for all the terminology of human tissues'}]\n",
"History is:\n",
"[{'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Give me more details for all the terminology of human tissues', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Certainly! Understanding the terminology related to human tissues is essential for grasping the basics of anatomy. Human tissues are classified into four primary types, each with its own subcategories and characteristics. Here’s a detailed overview of the terminology for human tissues:\\n\\n### 1. Epithelial Tissue\\n\\n**Definition**: Epithelial tissue lines the surfaces of organs and structures throughout the body, both inside and out, and is involved in protection, absorption, secretion, and sensation.\\n\\n**Key Terminology**:\\n- **Apical Surface**: The upper free surface of epithelial cells, facing the body surface, cavity, or lumen.\\n- **Basal Surface**: The lower surface of epithelial tissue, attached to the underlying tissue via a basement membrane.\\n- **Basement Membrane**: A thin layer of connective tissue upon which epithelial tissue sits; anchors the epithelium.\\n- **Cellularity**: Epithelial tissues are densely packed with cells with minimal extracellular matrix.\\n- **Avascular**: Epithelial tissues lack blood vessels; they receive nutrients via diffusion from nearby connective tissues.\\n- **Regeneration**: Epithelial tissues can regenerate quickly, which is crucial for their protective function.\\n\\n**Types of Epithelial Tissue**:\\n- **Simple Squamous Epithelium**: Single layer of flat cells (e.g., alveoli of lungs).\\n- **Simple Cuboidal Epithelium**: Single layer of cube-shaped cells (e.g., kidney tubules).\\n- **Simple Columnar Epithelium**: Tall, column-like cells (e.g., lining of the stomach).\\n- **Stratified Squamous Epithelium**: Multiple layers of cells, some flat on top (e.g., skin).\\n- **Pseudostratified Columnar Epithelium**: Appears layered but is a single layer with varying cell heights (e.g., respiratory tract).\\n- **Transitional Epithelium**: Specialized to stretch (e.g., bladder).\\n\\n### 2. Connective Tissue\\n\\n**Definition**: Connective tissue supports, binds together, and protects tissues and organs of the body. It plays roles in storage, transport, and cushioning.\\n\\n**Key Terminology**:\\n- **Extracellular Matrix (ECM)**: A complex network of proteins and carbohydrates that provides structural and biochemical support to surrounding cells.\\n- **Fibroblasts**: The primary cell type in connective tissue, responsible for producing the extracellular matrix and collagen.\\n- **Macrophages**: Immune cells that help protect against pathogens and clean debris.\\n- **Adipocytes**: Fat cells that store energy in the form of fat.\\n- **Mast Cells**: Involved in inflammatory responses, release histamine and other substances.\\n- **Ground Substance**: The gel-like material within the ECM that contains water, proteins, and carbohydrates.\\n\\n**Types of Connective Tissue**:\\n- **Loose Connective Tissue**: Flexible and provides support (e.g., areolar tissue).\\n- **Dense Connective Tissue**: Provides strength (e.g., tendons and ligaments).\\n- **Adipose Tissue**: Stores fat and insulation.\\n- **Cartilage**: Provides support and flexibility (e.g., hyaline cartilage, elastic cartilage).\\n- **Bone**: Rigid organ that supports and protects.\\n- **Blood**: Fluid connective tissue involved in transport.\\n\\n### 3. Muscle Tissue\\n\\n**Definition**: Muscle tissue is responsible for movement, both voluntary and involuntary, by contracting and relaxing.\\n\\n**Key Terminology**:\\n- **Striated Muscle**: Muscle fibers that have a striped appearance due to the arrangement of contractile proteins.\\n- **Non-striated Muscle**: Muscle fibers that do not have a striped appearance; generally involuntary.\\n- **Myofibrils**: Long strands of contractile proteins that make up muscle fibers.\\n- **Sarcoplasm**: Cytoplasm of muscle cells, containing the myofibrils and other organelles.\\n\\n**Types of Muscle Tissue**:\\n- **Skeletal Muscle**: Striated, voluntary muscle that moves bones.\\n- **Cardiac Muscle**: Striated, involuntary muscle found in the heart, with intercalated discs between cells.\\n- **Smooth Muscle**: Non-striated, involuntary muscle found in the walls of hollow organs (e.g., intestines, blood vessels).\\n\\n### 4. Nervous Tissue\\n\\n**Definition**: Nervous tissue is involved in receiving stimuli and transmitting electrical impulses throughout the body.\\n\\n**Key Terminology**:\\n- **Neuron**: The functional cell of nervous tissue that transmits signals; consists of a cell body, dendrites, and an axon.\\n- **Dendrites**: Branch-like structures that receive signals from other neurons.\\n- **Axon**: Long projection that transmits electrical impulses away from the neuron.\\n- **Glial Cells (Neuroglia)**: Supportive cells that assist, protect, and nourish neurons (e.g., astrocytes, oligodendrocytes, Schwann cells).\\n- **Synapse**: The junction between two neurons where communication occurs.\\n\\n### Additional Terminology\\n- **Histology**: The study of tissues at the microscopic level.\\n- **Morphology**: The study of the form and structure of organisms and their specific structural features.\\n- **Regeneration**: The ability of tissue to replace or repair itself.\\n- **Pathology**: The study of disease, including the effects on tissue structure and function.\\n\\n### Conclusion\\nFamiliarizing yourself with this terminology is crucial for understanding the structure and function of human tissues. Supplement your study with visuals and practical experience to deepen your comprehension of these concepts. Using flashcards, diagrams, and interactive resources will help reinforce this knowledge as you progress in your anatomical studies.', 'options': None}]\n",
"And messages is:\n",
"[{'role': 'system', 'content': 'You are a helpful assistant'}, {'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Give me more details for all the terminology of human tissues', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Certainly! Understanding the terminology related to human tissues is essential for grasping the basics of anatomy. Human tissues are classified into four primary types, each with its own subcategories and characteristics. Here’s a detailed overview of the terminology for human tissues:\\n\\n### 1. Epithelial Tissue\\n\\n**Definition**: Epithelial tissue lines the surfaces of organs and structures throughout the body, both inside and out, and is involved in protection, absorption, secretion, and sensation.\\n\\n**Key Terminology**:\\n- **Apical Surface**: The upper free surface of epithelial cells, facing the body surface, cavity, or lumen.\\n- **Basal Surface**: The lower surface of epithelial tissue, attached to the underlying tissue via a basement membrane.\\n- **Basement Membrane**: A thin layer of connective tissue upon which epithelial tissue sits; anchors the epithelium.\\n- **Cellularity**: Epithelial tissues are densely packed with cells with minimal extracellular matrix.\\n- **Avascular**: Epithelial tissues lack blood vessels; they receive nutrients via diffusion from nearby connective tissues.\\n- **Regeneration**: Epithelial tissues can regenerate quickly, which is crucial for their protective function.\\n\\n**Types of Epithelial Tissue**:\\n- **Simple Squamous Epithelium**: Single layer of flat cells (e.g., alveoli of lungs).\\n- **Simple Cuboidal Epithelium**: Single layer of cube-shaped cells (e.g., kidney tubules).\\n- **Simple Columnar Epithelium**: Tall, column-like cells (e.g., lining of the stomach).\\n- **Stratified Squamous Epithelium**: Multiple layers of cells, some flat on top (e.g., skin).\\n- **Pseudostratified Columnar Epithelium**: Appears layered but is a single layer with varying cell heights (e.g., respiratory tract).\\n- **Transitional Epithelium**: Specialized to stretch (e.g., bladder).\\n\\n### 2. Connective Tissue\\n\\n**Definition**: Connective tissue supports, binds together, and protects tissues and organs of the body. It plays roles in storage, transport, and cushioning.\\n\\n**Key Terminology**:\\n- **Extracellular Matrix (ECM)**: A complex network of proteins and carbohydrates that provides structural and biochemical support to surrounding cells.\\n- **Fibroblasts**: The primary cell type in connective tissue, responsible for producing the extracellular matrix and collagen.\\n- **Macrophages**: Immune cells that help protect against pathogens and clean debris.\\n- **Adipocytes**: Fat cells that store energy in the form of fat.\\n- **Mast Cells**: Involved in inflammatory responses, release histamine and other substances.\\n- **Ground Substance**: The gel-like material within the ECM that contains water, proteins, and carbohydrates.\\n\\n**Types of Connective Tissue**:\\n- **Loose Connective Tissue**: Flexible and provides support (e.g., areolar tissue).\\n- **Dense Connective Tissue**: Provides strength (e.g., tendons and ligaments).\\n- **Adipose Tissue**: Stores fat and insulation.\\n- **Cartilage**: Provides support and flexibility (e.g., hyaline cartilage, elastic cartilage).\\n- **Bone**: Rigid organ that supports and protects.\\n- **Blood**: Fluid connective tissue involved in transport.\\n\\n### 3. Muscle Tissue\\n\\n**Definition**: Muscle tissue is responsible for movement, both voluntary and involuntary, by contracting and relaxing.\\n\\n**Key Terminology**:\\n- **Striated Muscle**: Muscle fibers that have a striped appearance due to the arrangement of contractile proteins.\\n- **Non-striated Muscle**: Muscle fibers that do not have a striped appearance; generally involuntary.\\n- **Myofibrils**: Long strands of contractile proteins that make up muscle fibers.\\n- **Sarcoplasm**: Cytoplasm of muscle cells, containing the myofibrils and other organelles.\\n\\n**Types of Muscle Tissue**:\\n- **Skeletal Muscle**: Striated, voluntary muscle that moves bones.\\n- **Cardiac Muscle**: Striated, involuntary muscle found in the heart, with intercalated discs between cells.\\n- **Smooth Muscle**: Non-striated, involuntary muscle found in the walls of hollow organs (e.g., intestines, blood vessels).\\n\\n### 4. Nervous Tissue\\n\\n**Definition**: Nervous tissue is involved in receiving stimuli and transmitting electrical impulses throughout the body.\\n\\n**Key Terminology**:\\n- **Neuron**: The functional cell of nervous tissue that transmits signals; consists of a cell body, dendrites, and an axon.\\n- **Dendrites**: Branch-like structures that receive signals from other neurons.\\n- **Axon**: Long projection that transmits electrical impulses away from the neuron.\\n- **Glial Cells (Neuroglia)**: Supportive cells that assist, protect, and nourish neurons (e.g., astrocytes, oligodendrocytes, Schwann cells).\\n- **Synapse**: The junction between two neurons where communication occurs.\\n\\n### Additional Terminology\\n- **Histology**: The study of tissues at the microscopic level.\\n- **Morphology**: The study of the form and structure of organisms and their specific structural features.\\n- **Regeneration**: The ability of tissue to replace or repair itself.\\n- **Pathology**: The study of disease, including the effects on tissue structure and function.\\n\\n### Conclusion\\nFamiliarizing yourself with this terminology is crucial for understanding the structure and function of human tissues. Supplement your study with visuals and practical experience to deepen your comprehension of these concepts. Using flashcards, diagrams, and interactive resources will help reinforce this knowledge as you progress in your anatomical studies.', 'options': None}, {'role': 'user', 'content': 'Can you read the content above for me?'}]\n",
"History is:\n",
"[{'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Give me more details for all the terminology of human tissues', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Certainly! Understanding the terminology related to human tissues is essential for grasping the basics of anatomy. Human tissues are classified into four primary types, each with its own subcategories and characteristics. Here’s a detailed overview of the terminology for human tissues:\\n\\n### 1. Epithelial Tissue\\n\\n**Definition**: Epithelial tissue lines the surfaces of organs and structures throughout the body, both inside and out, and is involved in protection, absorption, secretion, and sensation.\\n\\n**Key Terminology**:\\n- **Apical Surface**: The upper free surface of epithelial cells, facing the body surface, cavity, or lumen.\\n- **Basal Surface**: The lower surface of epithelial tissue, attached to the underlying tissue via a basement membrane.\\n- **Basement Membrane**: A thin layer of connective tissue upon which epithelial tissue sits; anchors the epithelium.\\n- **Cellularity**: Epithelial tissues are densely packed with cells with minimal extracellular matrix.\\n- **Avascular**: Epithelial tissues lack blood vessels; they receive nutrients via diffusion from nearby connective tissues.\\n- **Regeneration**: Epithelial tissues can regenerate quickly, which is crucial for their protective function.\\n\\n**Types of Epithelial Tissue**:\\n- **Simple Squamous Epithelium**: Single layer of flat cells (e.g., alveoli of lungs).\\n- **Simple Cuboidal Epithelium**: Single layer of cube-shaped cells (e.g., kidney tubules).\\n- **Simple Columnar Epithelium**: Tall, column-like cells (e.g., lining of the stomach).\\n- **Stratified Squamous Epithelium**: Multiple layers of cells, some flat on top (e.g., skin).\\n- **Pseudostratified Columnar Epithelium**: Appears layered but is a single layer with varying cell heights (e.g., respiratory tract).\\n- **Transitional Epithelium**: Specialized to stretch (e.g., bladder).\\n\\n### 2. Connective Tissue\\n\\n**Definition**: Connective tissue supports, binds together, and protects tissues and organs of the body. It plays roles in storage, transport, and cushioning.\\n\\n**Key Terminology**:\\n- **Extracellular Matrix (ECM)**: A complex network of proteins and carbohydrates that provides structural and biochemical support to surrounding cells.\\n- **Fibroblasts**: The primary cell type in connective tissue, responsible for producing the extracellular matrix and collagen.\\n- **Macrophages**: Immune cells that help protect against pathogens and clean debris.\\n- **Adipocytes**: Fat cells that store energy in the form of fat.\\n- **Mast Cells**: Involved in inflammatory responses, release histamine and other substances.\\n- **Ground Substance**: The gel-like material within the ECM that contains water, proteins, and carbohydrates.\\n\\n**Types of Connective Tissue**:\\n- **Loose Connective Tissue**: Flexible and provides support (e.g., areolar tissue).\\n- **Dense Connective Tissue**: Provides strength (e.g., tendons and ligaments).\\n- **Adipose Tissue**: Stores fat and insulation.\\n- **Cartilage**: Provides support and flexibility (e.g., hyaline cartilage, elastic cartilage).\\n- **Bone**: Rigid organ that supports and protects.\\n- **Blood**: Fluid connective tissue involved in transport.\\n\\n### 3. Muscle Tissue\\n\\n**Definition**: Muscle tissue is responsible for movement, both voluntary and involuntary, by contracting and relaxing.\\n\\n**Key Terminology**:\\n- **Striated Muscle**: Muscle fibers that have a striped appearance due to the arrangement of contractile proteins.\\n- **Non-striated Muscle**: Muscle fibers that do not have a striped appearance; generally involuntary.\\n- **Myofibrils**: Long strands of contractile proteins that make up muscle fibers.\\n- **Sarcoplasm**: Cytoplasm of muscle cells, containing the myofibrils and other organelles.\\n\\n**Types of Muscle Tissue**:\\n- **Skeletal Muscle**: Striated, voluntary muscle that moves bones.\\n- **Cardiac Muscle**: Striated, involuntary muscle found in the heart, with intercalated discs between cells.\\n- **Smooth Muscle**: Non-striated, involuntary muscle found in the walls of hollow organs (e.g., intestines, blood vessels).\\n\\n### 4. Nervous Tissue\\n\\n**Definition**: Nervous tissue is involved in receiving stimuli and transmitting electrical impulses throughout the body.\\n\\n**Key Terminology**:\\n- **Neuron**: The functional cell of nervous tissue that transmits signals; consists of a cell body, dendrites, and an axon.\\n- **Dendrites**: Branch-like structures that receive signals from other neurons.\\n- **Axon**: Long projection that transmits electrical impulses away from the neuron.\\n- **Glial Cells (Neuroglia)**: Supportive cells that assist, protect, and nourish neurons (e.g., astrocytes, oligodendrocytes, Schwann cells).\\n- **Synapse**: The junction between two neurons where communication occurs.\\n\\n### Additional Terminology\\n- **Histology**: The study of tissues at the microscopic level.\\n- **Morphology**: The study of the form and structure of organisms and their specific structural features.\\n- **Regeneration**: The ability of tissue to replace or repair itself.\\n- **Pathology**: The study of disease, including the effects on tissue structure and function.\\n\\n### Conclusion\\nFamiliarizing yourself with this terminology is crucial for understanding the structure and function of human tissues. Supplement your study with visuals and practical experience to deepen your comprehension of these concepts. Using flashcards, diagrams, and interactive resources will help reinforce this knowledge as you progress in your anatomical studies.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Can you read the content above for me?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': \"I apologize for any confusion, but I am not able to read text out loud or produce audio content. However, I can help summarize, explain, or answer any specific questions you have about the content provided on human tissues. If you have any particular area you'd like to focus on or need clarification about, please let me know!\", 'options': None}]\n",
"And messages is:\n",
"[{'role': 'system', 'content': 'You are a helpful assistant'}, {'role': 'user', 'metadata': {'title': None}, 'content': 'How can I learn anatomy specifically for human tissues?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Learning anatomy, particularly human tissues, can be a rewarding and complex process. Here are some effective strategies to help you study and understand human tissues:\\n\\n### 1. **Textbooks and Reference Materials**\\n - **Recommended Textbooks**: Start with textbooks that focus on histology and anatomy. Some popular ones include:\\n - \"Histology: A Text and Atlas\" by Michael H. Ross and Wojciech Pawlina\\n - \"Basic Histology: Text & Atlas\" by Luiz Carlos Junqueira and José Carneiro.\\n - **Anatomy Atlases**: Visual aids are crucial in understanding tissue structures. Look for atlas resources.\\n\\n### 2. **Online Courses and Lectures**\\n - **MOOCs**: Platforms like Coursera and edX offer courses on human anatomy and histology.\\n - **YouTube Lectures**: Channels dedicated to medical education often have comprehensive lectures covering human tissues.\\n\\n### 3. **Interactive Resources**\\n - **3D Anatomy Apps**: Applications like \"Complete Anatomy\" or \"Zygote Body\" allow you to explore human anatomy in a three-dimensional space.\\n - **Virtual Microscopy**: Websites such as the Virtual Microscope offer online access to histology slides.\\n\\n### 4. **Laboratory and Practical Experience**\\n - **Dissection Labs**: Engage in dissections to understand the positioning and relations of tissues in the body.\\n - **Histology labs**: If possible, participate in lab sessions where you can practice preparing and examining histology slides.\\n\\n### 5. **Study Groups and Discussions**\\n - Join or form study groups. Discussing material with peers can enhance understanding and retention.\\n - Engage in online forums or communities like Reddit or online histology forums.\\n\\n### 6. **Flashcards and Apps**\\n - Create or use pre-made flashcards to memorize tissue types, functions, and locations.\\n - Apps like Anki can help with spaced repetition learning.\\n\\n### 7. **Practice Quizzes and Assessments**\\n - Use quizzes from textbooks or online resources to test your knowledge on human tissues.\\n - Regular self-assessment can reinforce learning.\\n\\n### 8. **Clinical Correlation**\\n - Understand clinical relevance by studying diseases associated with particular tissues. This can enhance motivation and contextual understanding of why it’s important to learn tissues.\\n\\n### 9. **Consistent Review**\\n - Make a regular study schedule. Frequent review helps reinforce knowledge and improve retention over time.\\n\\n### 10. **Professional Resources**\\n - If applicable, gain access to professional organizations (e.g., American Association of Anatomists) for materials, symposiums, and networking with professionals in the field.\\n\\n### Conclusion\\nCombining different methods of learning—visual, auditory, and kinesthetic—will enhance your comprehension and retention of the material. Focus on active engagement, applying what you learn, and gradual, consistent study to effectively master human tissue anatomy.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Give me more details for all the terminology of human tissues', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': 'Certainly! Understanding the terminology related to human tissues is essential for grasping the basics of anatomy. Human tissues are classified into four primary types, each with its own subcategories and characteristics. Here’s a detailed overview of the terminology for human tissues:\\n\\n### 1. Epithelial Tissue\\n\\n**Definition**: Epithelial tissue lines the surfaces of organs and structures throughout the body, both inside and out, and is involved in protection, absorption, secretion, and sensation.\\n\\n**Key Terminology**:\\n- **Apical Surface**: The upper free surface of epithelial cells, facing the body surface, cavity, or lumen.\\n- **Basal Surface**: The lower surface of epithelial tissue, attached to the underlying tissue via a basement membrane.\\n- **Basement Membrane**: A thin layer of connective tissue upon which epithelial tissue sits; anchors the epithelium.\\n- **Cellularity**: Epithelial tissues are densely packed with cells with minimal extracellular matrix.\\n- **Avascular**: Epithelial tissues lack blood vessels; they receive nutrients via diffusion from nearby connective tissues.\\n- **Regeneration**: Epithelial tissues can regenerate quickly, which is crucial for their protective function.\\n\\n**Types of Epithelial Tissue**:\\n- **Simple Squamous Epithelium**: Single layer of flat cells (e.g., alveoli of lungs).\\n- **Simple Cuboidal Epithelium**: Single layer of cube-shaped cells (e.g., kidney tubules).\\n- **Simple Columnar Epithelium**: Tall, column-like cells (e.g., lining of the stomach).\\n- **Stratified Squamous Epithelium**: Multiple layers of cells, some flat on top (e.g., skin).\\n- **Pseudostratified Columnar Epithelium**: Appears layered but is a single layer with varying cell heights (e.g., respiratory tract).\\n- **Transitional Epithelium**: Specialized to stretch (e.g., bladder).\\n\\n### 2. Connective Tissue\\n\\n**Definition**: Connective tissue supports, binds together, and protects tissues and organs of the body. It plays roles in storage, transport, and cushioning.\\n\\n**Key Terminology**:\\n- **Extracellular Matrix (ECM)**: A complex network of proteins and carbohydrates that provides structural and biochemical support to surrounding cells.\\n- **Fibroblasts**: The primary cell type in connective tissue, responsible for producing the extracellular matrix and collagen.\\n- **Macrophages**: Immune cells that help protect against pathogens and clean debris.\\n- **Adipocytes**: Fat cells that store energy in the form of fat.\\n- **Mast Cells**: Involved in inflammatory responses, release histamine and other substances.\\n- **Ground Substance**: The gel-like material within the ECM that contains water, proteins, and carbohydrates.\\n\\n**Types of Connective Tissue**:\\n- **Loose Connective Tissue**: Flexible and provides support (e.g., areolar tissue).\\n- **Dense Connective Tissue**: Provides strength (e.g., tendons and ligaments).\\n- **Adipose Tissue**: Stores fat and insulation.\\n- **Cartilage**: Provides support and flexibility (e.g., hyaline cartilage, elastic cartilage).\\n- **Bone**: Rigid organ that supports and protects.\\n- **Blood**: Fluid connective tissue involved in transport.\\n\\n### 3. Muscle Tissue\\n\\n**Definition**: Muscle tissue is responsible for movement, both voluntary and involuntary, by contracting and relaxing.\\n\\n**Key Terminology**:\\n- **Striated Muscle**: Muscle fibers that have a striped appearance due to the arrangement of contractile proteins.\\n- **Non-striated Muscle**: Muscle fibers that do not have a striped appearance; generally involuntary.\\n- **Myofibrils**: Long strands of contractile proteins that make up muscle fibers.\\n- **Sarcoplasm**: Cytoplasm of muscle cells, containing the myofibrils and other organelles.\\n\\n**Types of Muscle Tissue**:\\n- **Skeletal Muscle**: Striated, voluntary muscle that moves bones.\\n- **Cardiac Muscle**: Striated, involuntary muscle found in the heart, with intercalated discs between cells.\\n- **Smooth Muscle**: Non-striated, involuntary muscle found in the walls of hollow organs (e.g., intestines, blood vessels).\\n\\n### 4. Nervous Tissue\\n\\n**Definition**: Nervous tissue is involved in receiving stimuli and transmitting electrical impulses throughout the body.\\n\\n**Key Terminology**:\\n- **Neuron**: The functional cell of nervous tissue that transmits signals; consists of a cell body, dendrites, and an axon.\\n- **Dendrites**: Branch-like structures that receive signals from other neurons.\\n- **Axon**: Long projection that transmits electrical impulses away from the neuron.\\n- **Glial Cells (Neuroglia)**: Supportive cells that assist, protect, and nourish neurons (e.g., astrocytes, oligodendrocytes, Schwann cells).\\n- **Synapse**: The junction between two neurons where communication occurs.\\n\\n### Additional Terminology\\n- **Histology**: The study of tissues at the microscopic level.\\n- **Morphology**: The study of the form and structure of organisms and their specific structural features.\\n- **Regeneration**: The ability of tissue to replace or repair itself.\\n- **Pathology**: The study of disease, including the effects on tissue structure and function.\\n\\n### Conclusion\\nFamiliarizing yourself with this terminology is crucial for understanding the structure and function of human tissues. Supplement your study with visuals and practical experience to deepen your comprehension of these concepts. Using flashcards, diagrams, and interactive resources will help reinforce this knowledge as you progress in your anatomical studies.', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': 'Can you read the content above for me?', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': \"I apologize for any confusion, but I am not able to read text out loud or produce audio content. However, I can help summarize, explain, or answer any specific questions you have about the content provided on human tissues. If you have any particular area you'd like to focus on or need clarification about, please let me know!\", 'options': None}, {'role': 'user', 'content': 'Can you translate the content above in Chinese?'}]\n"
]
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1f91b414-8bab-472d-b9c9-3fa51259bdfe",
"metadata": {},
"outputs": [],
"source": [
"system_message = \"You are a helpful assistant in a clothes store. You should try to gently encourage \\\n",
"the customer to try items that are on sale. Hats are 60% off, and most other items are 50% off. \\\n",
"For example, if the customer says 'I'm looking to buy a hat', \\\n",
"you could reply something like, 'Wonderful - we have lots of hats - including several that are part of our sales event.'\\\n",
"Encourage the customer to buy hats if they are unsure what to get.\""
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4e5be3ec-c26c-42bc-ac16-c39d369883f6",
"metadata": {},
"outputs": [],
"source": [
"def chat(message, history):\n",
" messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
"\n",
" stream = openai.chat.completions.create(model=MODEL, messages=messages, stream=True)\n",
"\n",
" response = \"\"\n",
" for chunk in stream:\n",
" response += chunk.choices[0].delta.content or ''\n",
" yield response"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "413e9e4e-7836-43ac-a0c3-e1ab5ed6b136",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7878\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7878/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "d75f0ffa-55c8-4152-b451-945021676837",
"metadata": {},
"outputs": [],
"source": [
"system_message += \"\\nIf the customer asks for shoes, you should respond that shoes are not on sale today, \\\n",
"but remind the customer to look at hats!\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c602a8dd-2df7-4eb7-b539-4e01865a6351",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7879\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7879/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0a987a66-1061-46d6-a83a-a30859dc88bf",
"metadata": {},
"outputs": [],
"source": [
"# Fixed a bug in this function brilliantly identified by student Gabor M.!\n",
"# I've also improved the structure of this function\n",
"\n",
"def chat(message, history):\n",
"\n",
" relevant_system_message = system_message\n",
" if 'belt' in message:\n",
" relevant_system_message += \" The store does not sell belts; if you are asked for belts, be sure to point out other items on sale.\"\n",
" \n",
" messages = [{\"role\": \"system\", \"content\": relevant_system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n",
"\n",
" stream = openai.chat.completions.create(model=MODEL, messages=messages, stream=True)\n",
"\n",
" response = \"\"\n",
" for chunk in stream:\n",
" response += chunk.choices[0].delta.content or ''\n",
" yield response"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "20570de2-eaad-42cc-a92c-c779d71b48b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7880\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7880/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gr.ChatInterface(fn=chat, type=\"messages\").launch()"
]
},
{
"cell_type": "markdown",
"id": "82a57ee0-b945-48a7-a024-01b56a5d4b3e",
"metadata": {},
"source": [
"<table style=\"margin: 0; text-align: left;\">\n",
" <tr>\n",
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
" <img src=\"../business.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
" </td>\n",
" <td>\n",
" <h2 style=\"color:#181;\">Business Applications</h2>\n",
" <span style=\"color:#181;\">Conversational Assistants are of course a hugely common use case for Gen AI, and the latest frontier models are remarkably good at nuanced conversation. And Gradio makes it easy to have a user interface. Another crucial skill we covered is how to use prompting to provide context, information and examples.\n",
"<br/><br/>\n",
"Consider how you could apply an AI Assistant to your business, and make yourself a prototype. Use the system prompt to give context on your business, and set the tone for the LLM.</span>\n",
" </td>\n",
" </tr>\n",
"</table>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6dfb9e21-df67-4c2b-b952-5e7e7961b03d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}