-
Notifications
You must be signed in to change notification settings - Fork 689
Expand file tree
/
Copy pathgeneration_example.py
More file actions
42 lines (34 loc) · 1.12 KB
/
generation_example.py
File metadata and controls
42 lines (34 loc) · 1.12 KB
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
# encoding:utf-8
import json
import requests
"""
Code Generation
"""
API_KEY = "" # Get from Tianqi console. 从控制台获取
API_SECRET = "" # Get from Tianqi console. 从控制台获取
PROMPT = (
"from typing import List\n\ndef has_close_elements(numbers: List[float], threshold: float) -> bool:\n "
'""" Check if in given list of numbers, are any two numbers closer to each other than\n given '
"threshold.\n >>> has_close_elements([1.0, 2.0, 3.0], 0.5)\n False\n >>> has_close_elements("
'[1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)\n True\n """\n'
)
NUMBER = 3
LANG = "Python"
request_url = "https://tianqi.aminer.cn/api/v2/"
api = "multilingual_code_generate"
# Request is in json format. 指定请求参数格式为json
headers = {"Content-Type": "application/json"}
request_url = request_url + api
data = {
"apikey": API_KEY,
"apisecret": API_SECRET,
"prompt": PROMPT,
"n": NUMBER,
"lang": LANG,
}
def main():
response = requests.post(request_url, headers=headers, data=json.dumps(data))
if response:
print(response.json())
if __name__ == "__main__":
main()