kakuguo commited on
Commit
4170ee2
·
1 Parent(s): c8cc977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -1,25 +1,8 @@
1
- import openai
2
  import gradio as gr
3
 
4
- openai.api_key = "sk-R3HlMsYBk0NpAlLu2aA4B19054Ea4884A2Cf93D25662243d"
5
- openai.api_base="https://apai.zyai.online/v1"
6
-
7
- def predict(message, history):
8
- history_openai_format = []
9
- for human, assistant in history:
10
- history_openai_format.append({"role": "user", "content": human })
11
- history_openai_format.append({"role": "assistant", "content":assistant})
12
- history_openai_format.append({"role": "user", "content": message})
13
-
14
- response = openai.ChatCompletion.create(
15
- model="gpt-3.5-turbo", # 对话模型的名称
16
- messages=history_openai_format,
17
- temperature=1, # 值在[0,1]之间,越大表示回复越具有不确定性
18
- max_tokens=600, # 回复最大的字符数
19
- top_p=1,
20
- frequency_penalty=0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
21
- presence_penalty=0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
22
- )
23
- yield response.choices[0]['message']['content']
24
-
25
- gr.ChatInterface(predict).queue().launch()
 
 
1
  import gradio as gr
2
 
3
+ from transformers import AutoTokenizer, AutoModel
4
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
5
+ model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).half().cuda()
6
+ model = model.eval()
7
+ response, history = model.chat(tokenizer, "你好", history=[])
8
+ print(response)