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)