-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathlab_llms_call.py
95 lines (84 loc) · 3.15 KB
/
lab_llms_call.py
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
from http import HTTPStatus
import dashscope
from zhipuai import ZhipuAI
dashscope.api_key='<your api key>'
def send_chat_request_qwen(query):
'''
You can generate API keys in https://bailian.console.aliyun.com/
'''
messages = [
{'role': 'system', 'content': 'You are an useful AI assistant that helps people solve the problem step by step.'},
{'role': 'user', 'content': query}]
response = dashscope.Generation.call(
'qwen-72b-chat',
messages=messages,
result_format='message',
)
if response.status_code == HTTPStatus.OK:
data_res = response['output']['choices'][0]['message']['content']
#print(data_res)
return data_res
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
def send_chat_request_chatglm3_6b(query):
'''
You can generate API keys in https://bailian.console.aliyun.com/
'''
messages = [
{'role': 'system', 'content': 'You are an useful AI assistant that helps people solve the problem step by step.'},
{'role': 'user', 'content': query}]
response = dashscope.Generation.call(
'chatglm3-6b',
messages=messages,
result_format='message',
)
if response.status_code == HTTPStatus.OK:
data_res = response['output']['choices'][0]['message']['content']
print(data_res)
return data_res
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
def send_chat_request_chatglm_6b(query):
'''
You can generate API keys in https://bailian.console.aliyun.com/
'''
messages = [
{'role': 'system', 'content': 'You are an useful AI assistant that helps people solve the problem step by step.'},
{'role': 'user', 'content': query}]
response = dashscope.Generation.call(
'chatglm-6b-v2',
messages=messages,
result_format='message',
)
if response.status_code == HTTPStatus.OK:
data_res = response['output']['choices'][0]['message']['content']
# print(data_res)
return data_res
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
client = ZhipuAI(api_key="<your api key>")
def send_chat_request_glm(query):
'''
You can generate API keys in https://open.bigmodel.cn/
'''
response = client.chat.completions.create(
model="glm-3-turbo",
messages=[
{'role': 'system', 'content': '你是一个有用的人工智能助手,帮助人们逐步解决问题.'},
{'role': 'user', 'content': query}],
)
response=response.choices[0].message.content
return response
if __name__ == '__main__':
# response=send_chat_request_qwen("hello")
response=send_chat_request_glm("你好")
print(response)