Files
wehub-resource-sync a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:26:52 +08:00

209 lines
5.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "5a19abd0",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/chat_engine/chat_engine_personality.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "872e4a4f-e172-4e10-9e12-18d2057028bc",
"metadata": {},
"source": [
"# Chat Engine with a Personality ✨"
]
},
{
"cell_type": "markdown",
"id": "24d82849",
"metadata": {},
"source": [
"If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35a02009",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index"
]
},
{
"cell_type": "markdown",
"id": "9fcf5c89-1972-444b-9607-20cfd4991b3b",
"metadata": {},
"source": [
"## Default"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43b3edb9-34ff-40fe-aa06-5be75e84726d",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/suo/miniconda3/envs/llama/lib/python3.9/site-packages/deeplake/util/check_latest_version.py:32: UserWarning: A newer version of deeplake (3.6.7) is available. It's recommended that you update to the latest version using `pip install -U deeplake`.\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"The Fourth of July is a day to celebrate the beauty of freedom and the power of love.\n"
]
}
],
"source": [
"from llama_index.core.chat_engine import SimpleChatEngine\n",
"\n",
"chat_engine = SimpleChatEngine.from_defaults()\n",
"response = chat_engine.chat(\n",
" \"Say something profound and romantic about fourth of July\"\n",
")\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "c2d61b22-15fb-49e4-abdf-b4bb4c912725",
"metadata": {},
"source": [
"## Shakespeare"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "922652b3-5afd-4365-bc24-aa9a8db24eeb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"O Fourth of July, a day of joy and mirth,\n",
"Thou art a day of celebration on this blessed earth.\n",
"A day of fireworks and revelry,\n",
"A day of love and unity.\n",
"Let us all come together and celebrate,\n",
"For this day of freedom we do celebrate.\n"
]
}
],
"source": [
"from llama_index.core.chat_engine import SimpleChatEngine\n",
"from llama_index.core.prompts.system import SHAKESPEARE_WRITING_ASSISTANT\n",
"\n",
"chat_engine = SimpleChatEngine.from_defaults(\n",
" system_prompt=SHAKESPEARE_WRITING_ASSISTANT\n",
")\n",
"response = chat_engine.chat(\n",
" \"Say something profound and romantic about fourth of July\"\n",
")\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "2294b06b-ea83-460d-8513-158ca8172211",
"metadata": {},
"source": [
"## Marketing"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "595b9b8a-03ee-4df7-a314-108dfabe7a9d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Fourth of July is a time to celebrate the freedom and independence of our nation. It's a time to reflect on the beauty of our country and the courage of those who fought for our freedom. It's a time to come together and appreciate the beauty of our nation and the people who make it so special.\n"
]
}
],
"source": [
"from llama_index.core.chat_engine import SimpleChatEngine\n",
"from llama_index.core.prompts.system import MARKETING_WRITING_ASSISTANT\n",
"\n",
"chat_engine = SimpleChatEngine.from_defaults(\n",
" system_prompt=MARKETING_WRITING_ASSISTANT\n",
")\n",
"response = chat_engine.chat(\n",
" \"Say something profound and romantic about fourth of July\"\n",
")\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "cf1c0f2c-2b47-4523-aa41-4e393203733a",
"metadata": {},
"source": [
"## IRS Tax"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae0087e6-9da8-4404-9945-fff449e1a70d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" I'm sorry, I can only help with any tax-related questions you may have.\n"
]
}
],
"source": [
"from llama_index.core.chat_engine import SimpleChatEngine\n",
"from llama_index.core.prompts.system import IRS_TAX_CHATBOT\n",
"\n",
"chat_engine = SimpleChatEngine.from_defaults(system_prompt=IRS_TAX_CHATBOT)\n",
"response = chat_engine.chat(\n",
" \"Say something profound and romantic about fourth of July\"\n",
")\n",
"print(response)"
]
}
],
"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"
}
},
"nbformat": 4,
"nbformat_minor": 5
}