Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|