#from langchain.chat_models import ChatOpenAI   #from langchain_community.chat_models import ChatOpenAI   from langchain_openai import ChatOpenAI from langchain.schema import AIMessage, HumanMessage import gradio as gr import os #print(os.getenv('API_URL')) os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY') # Replace with your key client = ChatOpenAI(temperature=1.0, model=os.getenv('MODEL'), base_url=os.getenv('API_URL')) # 免费版支持gpt-4o一天5次;支持deepseek-r1, deepseek-v3一天30次,支持gpt-4o-mini,gpt-3.5-turbo一天200次。 def predict(message, history): history_langchain_format = [] for human, ai in history: history_langchain_format.append(HumanMessage(content=human)) history_langchain_format.append(AIMessage(content=ai)) # Check if it's the first interaction if len(history_langchain_format) == 0: history_langchain_format.append(HumanMessage(content="下面请用中文回答我的问题!"))#界面看不到的消息,用于让机器预加载一些对话信息 history_langchain_format.append(HumanMessage(content=message)) gpt_response = client(history_langchain_format) return gpt_response.content gr.ChatInterface(predict,description="下面是用ChatGPT接口!友情提示:千仟惠递,快递6元发全国,快递小哥上门取件,全国通用,食用方法:微信搜索seenwon", theme="compact").launch()