Skip to content

Commit

Permalink
update project
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Feb 4, 2025
1 parent 302511d commit 53ffead
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 36 deletions.
30 changes: 12 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: '.*\.md$'
- id: check-case-conflict
- id: check-yaml
- id: check-toml
Expand All @@ -21,30 +22,23 @@ repos:
- id: check-docstring-first
- id: detect-private-key

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
name: Upgrade code

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
- id: codespell
additional_dependencies: [tomli]
args: ["--in-place"]
#args: ["--write-changes"]

- repo: https://github.com/asottile/yesqa
rev: v1.5.0
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: yesqa
additional_dependencies:
- pep8-naming
- pydocstyle
- id: prettier
files: \.(json|yml|yaml|toml)
# https://prettier.io/docs/en/options.html#print-width
args: ["--print-width=120"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.8.1
hooks:
- id: ruff-format
args: ["--preview"]
Expand Down
316 changes: 316 additions & 0 deletions examples/gemini.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "7921ef1d",
"metadata": {},
"outputs": [],
"source": [
"import pathlib\n",
"import textwrap\n",
"\n",
"import google.generativeai as genai\n",
"\n",
"from IPython.display import display\n",
"from IPython.display import Markdown\n",
"import os\n",
"\n",
"\n",
"def to_markdown(text):\n",
" text = text.replace('•', ' *')\n",
" return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "85fff597f3c8c867",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:15.553304Z",
"start_time": "2024-05-24T20:19:15.546539Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv(\"../.env\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "bc2bd84632ebba22",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:15.555886Z",
"start_time": "2024-05-24T20:19:15.554110Z"
}
},
"outputs": [],
"source": [
"GOOGLE_API_KEY = os.getenv(\"GEMINI_KEY\")\n",
"genai.configure(api_key=GOOGLE_API_KEY)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e9ed65ab94d97ea2",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:16.939506Z",
"start_time": "2024-05-24T20:19:16.212137Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"models/gemini-1.0-pro\n",
"models/gemini-1.0-pro-001\n",
"models/gemini-1.0-pro-latest\n",
"models/gemini-1.0-pro-vision-latest\n",
"models/gemini-1.5-flash\n",
"models/gemini-1.5-flash-001\n",
"models/gemini-1.5-flash-latest\n",
"models/gemini-1.5-pro\n",
"models/gemini-1.5-pro-001\n",
"models/gemini-1.5-pro-latest\n",
"models/gemini-pro\n",
"models/gemini-pro-vision\n"
]
}
],
"source": [
"for m in genai.list_models():\n",
" if 'generateContent' in m.supported_generation_methods:\n",
" print(m.name)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8ef8ec0466497d9f",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:17.510510Z",
"start_time": "2024-05-24T20:19:17.507513Z"
}
},
"outputs": [],
"source": [
"model = genai.GenerativeModel('gemini-1.5-flash-latest')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a216bd25f1a11691",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:23.488972Z",
"start_time": "2024-05-24T20:19:19.787653Z"
}
},
"outputs": [],
"source": [
"response = model.generate_content(\"What is the meaning of life?\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fc419774c04102de",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:19:29.301826Z",
"start_time": "2024-05-24T20:19:29.298926Z"
},
"scrolled": false
},
"outputs": [
{
"data": {
"text/markdown": [
"> The meaning of life is a question that has been pondered by philosophers and individuals for centuries. There is no one definitive answer, as the meaning of life is deeply personal and subjective. \n",
"> \n",
"> Here are some perspectives on the meaning of life:\n",
"> \n",
"> **Existentialist View:**\n",
"> \n",
"> * **Individual Choice and Freedom:** Existentialists believe that life has no inherent meaning, and it is up to each individual to create their own meaning through their choices and actions.\n",
"> * **Authenticity and Self-Creation:** The focus is on living authentically and creating a life that is true to oneself, even in the face of the absurdity of existence.\n",
"> \n",
"> **Religious and Spiritual Views:**\n",
"> \n",
"> * **Divine Purpose:** Many religions believe that life has a purpose given by a higher power or deity. This purpose may involve serving God, following religious teachings, or achieving spiritual enlightenment.\n",
"> * **Karma and Reincarnation:** Some Eastern religions believe in karma and reincarnation, suggesting that life is a cycle of birth, death, and rebirth, with the purpose of spiritual growth and evolution.\n",
"> \n",
"> **Humanist View:**\n",
"> \n",
"> * **Human Flourishing and Meaningful Relationships:** Humanists focus on the importance of human experience, relationships, and contributions to society. They believe that meaning comes from living a fulfilling life and making a positive impact on the world.\n",
"> \n",
"> **Nihilistic View:**\n",
"> \n",
"> * **Absence of Meaning:** Nihilism suggests that life has no inherent meaning or purpose. This can lead to a sense of despair or apathy.\n",
"> \n",
"> **Other Perspectives:**\n",
"> \n",
"> * **Happiness and Well-being:** Some believe that the meaning of life is to find happiness and well-being, both for oneself and others.\n",
"> * **Love and Connection:** Love, connection, and relationships with others can be a source of meaning and purpose.\n",
"> * **Contribution and Legacy:** Leaving a positive mark on the world through creativity, innovation, or acts of kindness can provide a sense of meaning.\n",
"> \n",
"> Ultimately, the meaning of life is a question that each individual must answer for themselves. It is a journey of self-discovery, reflection, and exploration. There is no right or wrong answer, and the meaning of life can evolve and change throughout one's lifetime. \n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"to_markdown(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f0bb4f9d78aebcb4",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-24T20:20:48.593713Z",
"start_time": "2024-05-24T20:20:48.591513Z"
}
},
"outputs": [],
"source": [
"response = model.generate_content(\"What is the meaning of life?\", stream=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "9d07977ceabd05df",
"metadata": {
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The\n",
"________________________________________________________________________________\n",
" meaning of life is a question that has been pondered by philosophers, theologians, and\n",
"________________________________________________________________________________\n",
" individuals for centuries. There is no single, universally accepted answer, as the meaning\n",
"________________________________________________________________________________\n",
" of life is a deeply personal and subjective concept. \n",
"\n",
"Here are some common perspectives:\n",
"\n",
"**Philosophical perspectives:**\n",
"\n",
"* **Nihilism:** \n",
"________________________________________________________________________________\n",
"Life is inherently meaningless and without purpose.\n",
"* **Existentialism:** Life is meaningless until we create our own meaning through our choices and actions.\n",
"\n",
"________________________________________________________________________________\n",
"* **Absurdism:** Life is inherently absurd, but we can find meaning in embracing the absurdity.\n",
"* **Hedonism:** The meaning of life is to maximize pleasure and minimize pain.\n",
"* **Utilitarianism\n",
"________________________________________________________________________________\n",
":** The meaning of life is to promote the greatest good for the greatest number of people.\n",
"\n",
"**Religious perspectives:**\n",
"\n",
"* **Theism:** Life has meaning and purpose given by a divine creator.\n",
"* **Buddhism:**\n",
"________________________________________________________________________________\n",
" The meaning of life is to reach enlightenment and escape the cycle of suffering.\n",
"* **Hinduism:** The meaning of life is to achieve liberation from the cycle of birth and death.\n",
"\n",
"**Personal perspectives:**\n",
"\n",
"* **Love and connection:** Finding love and meaningful relationships can provide purpose and joy.\n",
"*\n",
"________________________________________________________________________________\n",
" **Creativity and self-expression:** Expressing oneself through art, music, writing, or other creative pursuits can give life meaning.\n",
"* **Making a difference:** Contributing to society, helping others, or leaving a positive legacy can provide a sense of purpose.\n",
"* **Personal growth and learning:** Continuously expanding knowledge\n",
"________________________________________________________________________________\n",
", skills, and understanding can make life meaningful.\n",
"\n",
"Ultimately, the meaning of life is up to each individual to decide. What matters most is finding something that gives your life purpose and brings you joy and fulfillment. \n",
"\n",
"Here are some questions to help you consider your own perspective:\n",
"\n",
"* What brings you joy and\n",
"________________________________________________________________________________\n",
" fulfillment?\n",
"* What are your values and beliefs?\n",
"* What are your goals and aspirations?\n",
"* What legacy do you want to leave behind?\n",
"\n",
"By reflecting on these questions, you can begin to define what the meaning of life is for you.\n",
"\n",
"________________________________________________________________________________\n"
]
}
],
"source": [
"for chunk in response:\n",
" print(chunk.text)\n",
" print(\"_\"*80)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f99aeac",
"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.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 53ffead

Please sign in to comment.