Skip to content

Commit ca98702

Browse files
committed
feat: add text summarization tool
1 parent ef0605b commit ca98702

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import openai"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"from dotenv import dotenv_values\n",
19+
"config = dotenv_values(\".env\")"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 3,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"openai.api_key = config[\"OPENAI_API_KEY\"]"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 5,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"name": "stdout",
38+
"output_type": "stream",
39+
"text": [
40+
"Summarized text:\n",
41+
"\n",
42+
" Atlas Shrugged is a novel by Ayn Rand that explores philosophical themes such as reason, individualism, and capitalism, depicting a dystopian United States where private businesses suffer under increasingly burdensome regulations and culminating in the strikers planning to build a new capitalist society based on John Galt's philosophy.\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"\n",
48+
"input_text = input(\"Enter text that should be summarized: \")\n",
49+
"\n",
50+
"response = openai.ChatCompletion.create(\n",
51+
" model=\"gpt-3.5-turbo\",\n",
52+
" messages=[{\"role\": \"system\", \"content\": \"You are a text summarizer bot. Your goal is to summarize in a single sentence the text provided by the user.\"}, {\"role\": \"user\", \"content\": input_text}],\n",
53+
" max_tokens=100\n",
54+
")\n",
55+
"\n",
56+
"ai_response = response.choices[0].message.content\n",
57+
"print(\"Summarized text:\\n\\n \", ai_response)"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"metadata": {},
64+
"outputs": [],
65+
"source": []
66+
}
67+
],
68+
"metadata": {
69+
"kernelspec": {
70+
"display_name": ".venv",
71+
"language": "python",
72+
"name": "python3"
73+
},
74+
"language_info": {
75+
"codemirror_mode": {
76+
"name": "ipython",
77+
"version": 3
78+
},
79+
"file_extension": ".py",
80+
"mimetype": "text/x-python",
81+
"name": "python",
82+
"nbconvert_exporter": "python",
83+
"pygments_lexer": "ipython3",
84+
"version": "3.10.5"
85+
},
86+
"orig_nbformat": 4
87+
},
88+
"nbformat": 4,
89+
"nbformat_minor": 2
90+
}

playground/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ For Stable Diffusion, you need to add your `STABILITY_AI_KEY`. You can find it i
121121
## Using GPT APIs
122122

123123
- recreating a [simple ChatGPT clone](28-simple-chatgpt-clone.ipynb).
124+
- creating a [text summarization tool](29-text-summarization-tool.ipynb).
124125

125126
These examples are based on two courses:
126127

0 commit comments

Comments
 (0)