|
import gradio as gr |
|
from openai import OpenAI |
|
from dotenv import load_dotenv |
|
import os |
|
|
|
load_dotenv() |
|
|
|
client = OpenAI( |
|
api_key = os.getenv("MOONSHOT_API_KEY"), |
|
base_url = "https://api.moonshot.cn/v1", |
|
) |
|
|
|
def chatbot(question): |
|
completion = client.chat.completions.create( |
|
model = "moonshot-v1-8k", |
|
messages = [ |
|
{"role": "system", "content": "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"}, |
|
{"role": "user", "content": question} |
|
], |
|
temperature = 0.3, |
|
) |
|
return completion.choices[0].message.content |
|
|
|
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text") |
|
iface.launch(share=True) |
|
|
|
file_path = "/d:/liteli/chatGPT/Code/ai-assisdant-book/ch7/kimi_chat/chatbot.py" |