1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 02 May 2023 00:42:59 GMT
Connection: close
{
"content": "Here's the code to output \"Hello World\" in Java:\n\n```
\npublic class HelloWorld {\n public static void main(String[] args) {\n System.out.println(\"Hello World\");\n }\n}\n
```"
}
```
## 生成SQL语句
SQL是开发过程中不可或缺的一部分,我们可以通过API来辅助编写SQL语句。下面是一个简单的示例:在学生表中查询所有学生的姓名。
### 请求参数
以下是请求参数的详细说明:
- **表名**:学生表
- **查询字段**:姓名
### SQL语句示例
根据上述请求参数,我们可以生成如下的SQL查询语句:
```sql
SELECT 姓名 FROM 学生表;
```
这个SQL语句的作用是从学生表中选择所有学生的姓名字段。
```xml
POST http://localhost:8080/v1/chat/completions
Content-Type: application/json
{
"apiKey": "sk-xxxxxx",
"content": "Please select all students' name from Student table in SQL"
}
```
返回结果如下:
```xml
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 02 May 2023 00:50:11 GMT
Connection: close
{
"content": "SELECT name FROM Student;"
}
```
1. 查找图片
我们还可以通过描述查询对应的图片,一般描述越精确,图片准确度越高。你可以看一下这个示例。
请求参数:
```xml
POST http://localhost:8080/v1/images/generations
Content-Type: application/json
{
"apiKey": "sk-xxxxxx",
"prompt": "find a tiger image",
"n": 1
}
```
返回参数如下:
```xml
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 02 May 2023 04:12:48 GMT
Connection: close
{
"urls": [
"https://oaidalleapiprodscus.blob.core.windows.net/private/org-mnyBsdtqxGUtwxCfi4SnEVIR/user-TapQIQ3nCgz483OGGnKll1N3/img-szYL9tqKuKPKZ00ywwofigLY.png?st=2023-05-02T03%3A12%3A48Z&se=2023-05-02T05%3A12%3A48Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-05-01T17%3A37%3A04Z&ske=2023-05-02T17%3A37%3A04Z&sks=b&skv=2021-08-06&sig=qnREx8BFjeikttJyA71Qp4WrXT3RuvRHhzU1xUr1Le8%3D"
]
}
```
## 图片搜索功能说明
可以通过特定的API接口来获取与请求参数中语义尽可能一致的图片URL数组。返回的图片URL数量将根据请求参数`n`的值来确定。
### 拼写检查功能
拼写错误是文本编辑中常见的问题,通常难以被发现。为此,我们提供了一个拼写检查接口来帮助用户识别并修正这些错误。
#### 请求参数
在使用拼写检查接口时,请确保提供正确的请求参数。具体的参数详情请参考相关文档。
以上是对图片搜索和拼写检查功能的简要介绍。
```xml
POST http://8.218.233.184:8080/v1/edits
Content-Type: application/json
{
"apiKey": "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",
"input": "It is an rainn day",
"instruction": "Fix the spell mistakes"
}
```
返回参数如下:
```xml
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 02 May 2023 05:25:38 GMT
Connection: close
{
"text": "It is a rainy day\n"
}
```
# 冒泡排序算法实现
这是一个简单的冒泡排序算法实现。为了解析方便,我们使用了很多换行符来将多行代码压缩到一行。以下是代码及其注释:
```python
# 定义冒泡排序函数
def bubble_sort(arr):
# 获取数组长度
n = len(arr)
# 遍历所有数组元素
for i in range(n):
# 最后i个元素已经是排好序的了,不需要再比较
for j in range(0, n-i-1):
# 遍历数组从0到n-i-1
# 交换如果发现元素e[j]比e[j+1]大,则交换之
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
# 测试冒泡排序函数
arr = [64, 34, 25, 12, 22, 11, 90]
sorted_arr = bubble_sort(arr)
print("Sorted array is: ", sorted_arr)
```
请求参数:
- `arr`: 待排序的数组。
```xml
POST http://localhost:8080/v1/edits
Content-Type: application/json
{
"apiKey": "sk-xxxxx",
"input": "public static void sort(int[] arrays) { \nif (arrays.length == 0) { \nreturn; \n} \nfor (int i = 0; i < arrays.length; i++) { \nfor (int j = 0; j < i; j++) { \nif (arrays[j] > arrays[j + 1]) { \n int temp = arrays[j]; \narrays[j] = arrays[j + 1]; \narrays[j + 1] = temp;\n}\n}\n}\n}",
"instruction": "Explain this Java code"
}
```
返回参数如下:
```xml
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 02 May 2023 23:45:37 GMT
Connection: close
{
"text": "/** Java\nI discovered this code from a tutorial from edx from Havard but the idea is based of \ntheese steps:\n1) Complete these steps in the *sort* method:\n* Compare the first two elements of the array\n* If elem 1 is greater than elem 2, swap them\n* Repeat this step until all pairs are sorted\n* Repeat this step while traversing the array\n\n2) Complete these steps in the *sort2* method:\n* Create the two arrays needed (one with the first half the size of the original array, one with the \nsecond half of the array)\n* Use a for loop to find the first half of the array\n* Use another for loop to find the second half of the array\n\n3) Complete the rest of the *mergeSortedArrays* method\n* Merge the arrays back into a single sorted array\n*/\n\n// Try recreating it without looking at the code\n\npublic static void sort(int[] arrays) { \nif (arrays.length == 0) { \nreturn; \n}\nfor (int i = 0; i < arrays.length; i++) { \n for (int j = 0; j < i; j++) {\n if (arrays[j] > arrays[j + 1]) {\n int temp = arrays[j]; \n arrays[j] = arrays[j + 1]; \n arrays[j + 1] = temp;\n }\n }\n }\n}\n}\n\n/**\nThis algorithm can also sort lists but to use list you have to type this code at the top\npublic static void sort(List<Integer> list) {\t\nThis is how array list works: \nFirst is the value of the array and the array name which is list, in the similiar fashion\nof calling a array and giving it a value.\n\npublic static void main(String[] args) {\n List<Integer> list = new ArrayList<>();\n list.add(10);\n list.add(5);\n list.add(1);\n list.add(12);\n list.add(6);\t\nSo you call a add function from ArrayList and set the number to the array list,\nalthough this is not setting the values it is just an example.\n\nint[] arrays = new int[]{10, 5, 1, 12, 6};\nsort(arrays);\nfor (int elem:arrays) {\n System.out.print(elem + \" \");\n} \nThis code is basically traversing through the array to print the output and to add the sort function\nand it prints out this output: 1 5 6 10 12 (To show that it is sorted)\n\nThe intarray code is similiar but it defines the construtor of the array and gives it a \nvalue like this: new int []{10, 5, 1, 12, 6}\n\nThe sort function is is sorted algorithm which is just one function of the sort method.\nHowever, to get this work without the arrays you have to call a public static void\nsort method but with a list instead or you varible name for the array.\nExample: \npublic static void sort(List<Integer> varible) {\n\nCreated a mergeSortedArrays\n\nif (firstArray.length == 0 || secondArray.length == 0'd) {\n return; \n } \n\nThis makes sure that nothing is printed if the first array length or second array\nlength is empty.\n\nint[] mergedArray = new int[firstArray.length + secondArray.length];\nint firstArrayPointer = 0;\nint secondArrayPointer = 0;\t\nAs said above, we stick values to the array to merge into a storeage usage. The first part\nis the array name which is mergedArray and the second is the value. The plus method is used to \nadd variables and make them a whole array.\n\nfor (int mergedArrayPointer = 0; mergedArrayPointer < firstArray.length \n + secondArray.length; mergedArrayPointer++) {\n\tThis code is saying is that if the count of the array pointer is going to be smaller that\n\tthe leangth of the firstArray and secondArray then the array pointer is going to count \n\tand only going to contine to one not adding any more to the count.\n\tsecondArrayPointer++ means adding one more to the count and on so forth. \n\t\n\tmergedArray[mergedArrayPointer] = (firstArray[firstArrayPointer] <= \n secondArray[secondArrayPointer])?firstArray[firstArrayPointer\n ]:secondArray[secondArrayPointer];\t\nIf the value of firstArray is greater than secondArrayPointer OR equal to then it is going to\nmerge to the mergedArray so we got an array sorting inside another array. \n */\n"
}
```
# 课程总结
在这节课中,我们深入探讨了OpenAI API的强大功能,包括内容生成、摘要、分类及语义分析、翻译等。以下是本节课的核心内容和收获。
## OpenAI API的基础能力
- **内容生成**:利用API生成各种文本内容。
- **摘要**:自动提取文本的核心要点。
- **分类及语义分析**:对文本进行分类和深入分析。
- **翻译**:实现不同语言之间的文本转换。
## 实际应用
- **编程助手**:通过API辅助编写代码、生成SQL语句、查找图片、检查拼写等。
- **工作效率提升**:自动化繁琐任务,提高编程效率。
- **低代码平台**:构建基于API的低代码平台和工具集。
- **业务领域模型训练**:训练特定业务领域的大模型以适应不同需求。
## 拥抱变化
- 将GPT视为编程助手,提高工作效率。
- 编写标准程序单元、测试用例、生成注释说明。
- 利用API构建低代码平台和工具集,进一步训练特定业务领域的大模型。
## 结语
- 引用软件大师Alan Kay的话:"The best way to predict the future is to invent it."
- 鼓励大家积极参与到这个变化中,共同推动新时代的到来。
## 互动邀请
- 如果你觉得这节课的内容对你有帮助,欢迎分享给朋友。
- 同时,也欢迎你在评论区分享你的感悟和思考,与我一起讨论。
|