Download qwen_response.py from allinaigc/text2sql: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/allinaigc/text2sql/resolve/main/qwen_response.py
- Command line
-
hf download hf://spaces/allinaigc/text2sql/qwen_response.py
-
curl -L -o qwen_response.py https://huggingface.co/spaces/allinaigc/text2sql/resolve/main/qwen_response.py
1.8 kB
| import random | |
| from http import HTTPStatus | |
| import dashscope | |
| ### 参考: | |
| ## export DASHSCOPE_API_KEY="sk-948adb3e65414e55961a9ad9d22d186b" | |
| dashscope.api_key = "sk-948adb3e65414e55961a9ad9d22d186b" | |
| # qwen_sys_prompt = """ | |
| # 1. 你是一个将文字转换成SQL语句的人工智能。 | |
| # 2. 此外你需要注意:你只需要用纯文本回复代码的内容,即你不允许回复代码以外的任何信息。 | |
| # 3. 你不能将将字段名翻译成英文,而是必须使用如下的名词:长度,宽度,价格,产品ID,比率,类别,* | |
| # 4. 你不能写IF, THEN的SQL语句,需要使用CASE。 | |
| # """ | |
| qwen_sys_prompt = """你是一个将文字转换成SQL语句的人工智能。""" | |
| def call_with_messages(prompt): | |
| messages = [{'role': 'system', 'content': qwen_sys_prompt}, | |
| {'role': 'user', 'content': prompt}] | |
| # {'role': 'user', 'content': '如何做西红柿炒鸡蛋?'}] | |
| response = dashscope.Generation.call( | |
| "qwen-turbo", | |
| messages=messages, | |
| # set the random seed, optional, default to 1234 if not set | |
| seed=random.randint(1, 10000), | |
| # set the result to be "message" format. | |
| result_format='message', | |
| ) | |
| if response.status_code == HTTPStatus.OK: | |
| print(response) | |
| else: | |
| print('Request id: %s, Status code: %s, error code: %s, error message: %s' % ( | |
| response.request_id, response.status_code, | |
| response.code, response.message | |
| )) | |
| return response['output']['choices'][0]['message']['content'] ### 这里是content的内容,不是message的全部内容。 | |
| # if __name__ == '__main__': | |
| # # call_with_messages() ### original code here. | |
| # res = call_with_messages() ## working. | |
| # # print(res) |