Musa24 commited on
Commit
c27ad33
·
verified ·
1 Parent(s): cc194d9

Upload Echo and N.ipynb

Browse files
Files changed (1) hide show
  1. Echo and N.ipynb +218 -0
Echo and N.ipynb ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "4e85410b",
6
+ "metadata": {},
7
+ "source": [
8
+ "#### LEARNING"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "a6a3b6cc",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "from dotenv import load_dotenv\n",
19
+ "import os\n",
20
+ "load_dotenv(override=True)\n",
21
+ "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 2,
27
+ "id": "266e2995",
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "from openai import OpenAI\n",
32
+ "client = OpenAI()"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 3,
38
+ "id": "88b817b3",
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "# openai.Completion.create(\n",
43
+ "# model=\"text-davinci-003\", prompt=\"write me a poem\", max_tokens=100, n=3\n",
44
+ "# )\n",
45
+ "response1 = client.chat.completions.create(\n",
46
+ " model=\"gpt-3.5-turbo\",\n",
47
+ " messages=[{\"role\": \"user\", \"content\": \"write me a poem\"}],\n",
48
+ " max_tokens=100,\n",
49
+ " n=3,\n",
50
+ ")"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 4,
56
+ "id": "521f6be6",
57
+ "metadata": {},
58
+ "outputs": [
59
+ {
60
+ "data": {
61
+ "text/plain": [
62
+ "[Choice(finish_reason='length', index=0, logprobs=None, message=ChatCompletionMessage(content='In the depths of the night, when the stars shine bright,\\nI am lost in a world of wonder and delight.\\nThe moon whispers secrets in the shadows,\\nAnd the wind sings a haunting melody that echoes.\\n\\nI walk through fields of gold and emerald green,\\nWhere the flowers dance in the moonlight unseen.\\nThe trees hum a lullaby that soothes my soul,\\nAnd I become one with nature, feeling whole.\\n\\nThe night is a canvas, painted with dreams,\\nWhere reality fades and', refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None)),\n",
63
+ " Choice(finish_reason='length', index=1, logprobs=None, message=ChatCompletionMessage(content=\"In the stillness of the night\\nWhere shadows dance and flicker bright\\nI find solace in the quiet\\nAnd let my thoughts take flight\\n\\nA whispered breeze through branches tall\\nSings a lullaby to ease my soul\\nThe moon's soft glow, a gentle guide\\nAs I wander in the night\\n\\nStars twinkle in the velvet sky\\nLike diamonds scattered by the divine\\nI feel the universe's embrace\\nAnd know that everything's in place\\n\\nIn this moment of\", refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None)),\n",
64
+ " Choice(finish_reason='length', index=2, logprobs=None, message=ChatCompletionMessage(content=\"In the quiet of the night, \\nUnderneath the starry sky so bright, \\nI find solace in the peaceful air, \\nAnd let my thoughts wander without a care. \\n\\nI think of love that's pure and true, \\nOf friendships strong and skies so blue, \\nI dream of places far and near, \\nAnd let my worries disappear. \\n\\nThe gentle breeze whispers its song, \\nAnd I feel like I truly belong, \\nA part of this vast universe so grand,\", refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None))]"
65
+ ]
66
+ },
67
+ "execution_count": 4,
68
+ "metadata": {},
69
+ "output_type": "execute_result"
70
+ }
71
+ ],
72
+ "source": [
73
+ "response1.choices"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": 6,
79
+ "id": "644044f3",
80
+ "metadata": {},
81
+ "outputs": [
82
+ {
83
+ "data": {
84
+ "text/plain": [
85
+ "ChatCompletion(id='chatcmpl-Bqjy9FuXAxUI4ujseEQqZUEGnAosb', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='A: The tallest building in the world is the Burj Khalifa in Dubai, United Arab Emirates, standing at 828 meters (2,717 feet) tall.', refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None))], created=1751909461, model='gpt-3.5-turbo-0125', object='chat.completion', service_tier='default', system_fingerprint=None, usage=CompletionUsage(completion_tokens=34, prompt_tokens=18, total_tokens=52, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))"
86
+ ]
87
+ },
88
+ "execution_count": 6,
89
+ "metadata": {},
90
+ "output_type": "execute_result"
91
+ }
92
+ ],
93
+ "source": [
94
+ "# openai.Completion.create(\n",
95
+ "# model=\"text-davinci-003\",\n",
96
+ "# prompt=\"Q: What is the tallest building in the world?\",\n",
97
+ "# max_tokens=100,\n",
98
+ "# # echo=True\n",
99
+ "# )\n",
100
+ "client.chat.completions.create(\n",
101
+ " model=\"gpt-3.5-turbo\",\n",
102
+ " messages=[\n",
103
+ " {\"role\": \"user\", \"content\": \"Q: What is the tallest building in the world?\"}\n",
104
+ " ],\n",
105
+ " max_completion_tokens=100,\n",
106
+ " # max_tokens=100,\n",
107
+ ")"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 7,
113
+ "id": "9a4fc8b0",
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "data": {
118
+ "text/plain": [
119
+ "ChatCompletion(id='chatcmpl-BqjyYiRsmlYgY9NCpcRkyib88LPZ9', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Green', refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None))], created=1751909486, model='gpt-3.5-turbo-0125', object='chat.completion', service_tier='default', system_fingerprint=None, usage=CompletionUsage(completion_tokens=1, prompt_tokens=20, total_tokens=21, completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))"
120
+ ]
121
+ },
122
+ "execution_count": 7,
123
+ "metadata": {},
124
+ "output_type": "execute_result"
125
+ }
126
+ ],
127
+ "source": [
128
+ "# openai.Completion.create(\n",
129
+ "# model=\"text-davinci-003\",\n",
130
+ "# prompt=\"In a single word, what is the color of a pickle? \",\n",
131
+ "# max_tokens=100,\n",
132
+ "# # echo=True\n",
133
+ "# )\n",
134
+ "client.chat.completions.create(\n",
135
+ " model=\"gpt-3.5-turbo\",\n",
136
+ " messages=[\n",
137
+ " {\"role\": \"user\", \"content\": \"In a single word, what is the color of a pickle?\"}\n",
138
+ " ],\n",
139
+ " max_completion_tokens=100,\n",
140
+ ")"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 9,
146
+ "id": "04bdf334",
147
+ "metadata": {},
148
+ "outputs": [],
149
+ "source": [
150
+ "# openai.Completion.create(\n",
151
+ "# model=\"text-davinci-003\",\n",
152
+ "# prompt=\"In a single word, what is the color of a pickle? \",\n",
153
+ "# max_tokens=100,\n",
154
+ "# echo=True,\n",
155
+ "# )\n",
156
+ "\n",
157
+ "# With Chat Completions, OpenAI doesn't permit the echo parameter.\n",
158
+ "res = client.chat.completions.create(\n",
159
+ " model=\"gpt-3.5-turbo\",\n",
160
+ " messages=[\n",
161
+ " {\"role\": \"user\", \"content\": \"In a single word, what is the color of a pickle? \"}\n",
162
+ " ],\n",
163
+ " max_completion_tokens=100,\n",
164
+ ")"
165
+ ]
166
+ },
167
+ {
168
+ "cell_type": "code",
169
+ "execution_count": 10,
170
+ "id": "3ea8fde2",
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "'Green'"
177
+ ]
178
+ },
179
+ "execution_count": 10,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "res.choices[0].message.content"
186
+ ]
187
+ },
188
+ {
189
+ "cell_type": "code",
190
+ "execution_count": null,
191
+ "id": "388d27ee",
192
+ "metadata": {},
193
+ "outputs": [],
194
+ "source": []
195
+ }
196
+ ],
197
+ "metadata": {
198
+ "kernelspec": {
199
+ "display_name": "venv",
200
+ "language": "python",
201
+ "name": "python3"
202
+ },
203
+ "language_info": {
204
+ "codemirror_mode": {
205
+ "name": "ipython",
206
+ "version": 3
207
+ },
208
+ "file_extension": ".py",
209
+ "mimetype": "text/x-python",
210
+ "name": "python",
211
+ "nbconvert_exporter": "python",
212
+ "pygments_lexer": "ipython3",
213
+ "version": "3.11.7"
214
+ }
215
+ },
216
+ "nbformat": 4,
217
+ "nbformat_minor": 5
218
+ }