drclab commited on
Commit
d7af055
1 Parent(s): f1a7843

ChatCompletion

Browse files
Files changed (2) hide show
  1. hugging_face.ipynb +2 -2
  2. prompt.ipynb +96 -3
hugging_face.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 2,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -13,7 +13,7 @@
13
  },
14
  {
15
  "cell_type": "code",
16
- "execution_count": 3,
17
  "metadata": {},
18
  "outputs": [
19
  {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
13
  },
14
  {
15
  "cell_type": "code",
16
+ "execution_count": 2,
17
  "metadata": {},
18
  "outputs": [
19
  {
prompt.ipynb CHANGED
@@ -10,15 +10,108 @@
10
  },
11
  {
12
  "cell_type": "code",
13
- "execution_count": null,
14
  "metadata": {},
15
  "outputs": [],
16
- "source": []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
  ],
19
  "metadata": {
 
 
 
 
 
20
  "language_info": {
21
- "name": "python"
 
 
 
 
 
 
 
 
 
22
  },
23
  "orig_nbformat": 4
24
  },
 
10
  },
11
  {
12
  "cell_type": "code",
13
+ "execution_count": 2,
14
  "metadata": {},
15
  "outputs": [],
16
+ "source": [
17
+ "from auth import API_KEY\n",
18
+ "import openai"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 3,
24
+ "metadata": {},
25
+ "outputs": [],
26
+ "source": [
27
+ "openai.api_key = API_KEY"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type": "code",
32
+ "execution_count": 8,
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "def get_completion(prompt, model='gpt-3.5-turbo'):\n",
37
+ " messages = [{'role':'user', 'content': prompt}]\n",
38
+ " response = openai.ChatCompletion.create(\n",
39
+ " model=model,\n",
40
+ " messages = messages,\n",
41
+ " temperature = 0, # this is the degree of randomness of the model's output\n",
42
+ " )\n",
43
+ " return response.choices[0].message['content']"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 5,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "text = f\"\"\"\n",
53
+ "You should express what you want a model to do by \\ \n",
54
+ "providing instructions that are as clear and \\ \n",
55
+ "specific as you can possibly make them. \\ \n",
56
+ "This will guide the model towards the desired output, \\ \n",
57
+ "and reduce the chances of receiving irrelevant \\ \n",
58
+ "or incorrect responses. Don't confuse writing a \\ \n",
59
+ "clear prompt with writing a short prompt. \\ \n",
60
+ "In many cases, longer prompts provide more clarity \\ \n",
61
+ "and context for the model, which can lead to \\ \n",
62
+ "more detailed and relevant outputs.\n",
63
+ "\"\"\""
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 6,
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "prompt = f\"\"\"\n",
73
+ "Summarize the text delimited by triple backticks \\ \n",
74
+ "into a single sentence.\n",
75
+ "```{text}```\n",
76
+ "\"\"\""
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 9,
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "name": "stdout",
86
+ "output_type": "stream",
87
+ "text": [
88
+ "Clear and specific instructions should be provided to guide a model towards the desired output, and longer prompts can provide more clarity and context for the model, leading to more detailed and relevant outputs.\n"
89
+ ]
90
+ }
91
+ ],
92
+ "source": [
93
+ "response = get_completion(prompt)\n",
94
+ "print(response)"
95
+ ]
96
  }
97
  ],
98
  "metadata": {
99
+ "kernelspec": {
100
+ "display_name": "Python 3",
101
+ "language": "python",
102
+ "name": "python3"
103
+ },
104
  "language_info": {
105
+ "codemirror_mode": {
106
+ "name": "ipython",
107
+ "version": 3
108
+ },
109
+ "file_extension": ".py",
110
+ "mimetype": "text/x-python",
111
+ "name": "python",
112
+ "nbconvert_exporter": "python",
113
+ "pygments_lexer": "ipython3",
114
+ "version": "3.10.6"
115
  },
116
  "orig_nbformat": 4
117
  },