GPT-4o: Research Preview (Short-Term Availability) If this app doesn't respond, consider…
- User
GPT-4o: Research Preview (Short-Term Availability) If this app doesn't respond, consider trying our other GPT-4O app: https://huggingface.co/spaces/yuntian-deng/ChatGPT4Turbo Chatbot Type an input and press Enter Hi there! Run Status code from OpenAI server
Parameters ▼ 通过 API 使用标志 · 使用 Gradio 构建标志
API documentation yuntian-deng/ChatGPT4
API Recorder
5 API endpoints
Choose a language to see the code snippets for interacting with the API.
- Install the Python client (docs) if you don't already have it installed.
copy $ pip install gradio_client 2. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data. If this is a private Space, you may need to pass your Hugging Face token as well (read more). Or use the API Recorder
to automatically generate your API requests.
api_name: /enable_inputs copy from gradio_client import Client
client = Client("yuntian-deng/ChatGPT4") result = client.predict( api_name="/enable_inputs" ) print(result) Accepts 0 parameters: Returns 1 element api_name: /reset_textbox copy from gradio_client import Client
client = Client("yuntian-deng/ChatGPT4") result = client.predict( api_name="/reset_textbox" ) print(result) Accepts 0 parameters: Returns 1 element str
The output value that appears in the "Type an input and press Enter" Textbox component.
api_name: /predict copy from gradio_client import Client
client = Client("yuntian-deng/ChatGPT4") result = client.predict( inputs="Hello!!", top_p=1, temperature=1, chat_counter=0, chatbot=[], api_name="/predict" ) print(result) Accepts 5 parameters: inputs str Required
The input value that is provided in the "Type an input and press Enter" Textbox component.
top_p float Default: 1
The input value that is provided in the "Top-p (nucleus sampling)" Slider component.
temperature float Default: 1
The input value that is provided in the "Temperature" Slider component.
chat_counter float Default: 0
The input value that is provided in the "parameter_16" Number component.
chatbot Tuple[str | Dict(file: filepath, alt_text: str | None) | Dict(component: str, value: Any, constructor_args: Dict(), props: Dict()) | None, str | Dict(file: filepath, alt_text: str | None) | Dict(component: str, value: Any, constructor_args: Dict(), props: Dict()) | None] Default: []
The input value that is provided in the "parameter_4" Chatbot component.
Returns tuple of 4 elements [0] Tuple[str | Dict(file: filepath, alt_text: str | None) | Dict(component: str, value: Any, constructor_args: Dict(), props: Dict()) | None, str | Dict(file: filepath, alt_text: str | None) | Dict(component: str, value: Any, constructor_args: Dict(), props: Dict()) | None]
- Assistant
- User
整理为python完整代码
- Assistant
下面是一个完整的 Python 代码示例,该示例展示如何使用
gradio_client库来调用yuntian-deng/ChatGPT4中的几个 API 端点:from gradio_client import Client # 创建一个客户端 client = Client("yuntian-deng/ChatGPT4") # 调用 /enable_inputs 端点 def enable_inputs(): result = client.predict(api_name="/enable_inputs") print("Enable Inputs Result:", result) # 调用 /reset_textbox 端点 def reset_textbox(): result = client.predict(api_name="/reset_textbox") print("Reset Textbox Result:", result) # 调用 /predict 端点 def predict(inputs, top_p=1, temperature=1, chat_counter=0, chatbot=[]): result = client.predict( inputs=inputs, top_p=top_p, temperature=temperature, chat_counter=chat_counter, chatbot=chatbot, api_name="/predict" ) print("Predict Result:", result) # 调用 /reset_textbox_1 端点 def reset_textbox_1(): result = client.predict(api_name="/reset_textbox_1") print("Reset Textbox 1 Result:", result) # 调用 /predict_1 端点 def predict_1(inputs, top_p=1, temperature=1, chat_counter=0, chatbot=[]): result = client.predict( inputs=inputs, top_p=top_p, temperature=temperature, chat_counter=chat_counter, chatbot=chatbot, api_name="/predict_1" ) print("Predict 1 Result:", result) # 示例调用 enable_inputs() # 调用 /enable_inputs reset_textbox() # 调用 /reset_textbox predict("Hello!!") # 调用 /predict,输入 "Hello!!" reset_textbox_1() # 调用 /reset_textbox_1 predict_1("Hello again!!") # 调用 /predict_1,输入 "Hello again!!" - User
使用中文变量
- Assistant
当然!以下是使用中文变量名的 Python 代码示例:
from gradio_client import Client # 创建一个客户端 客户端 = Client("yuntian-deng/ChatGPT4") # 调用 /enable_inputs 端点 def 启用输入(): 结果 = 客户端.predict(api_name="/enable_inputs") print("启用输入结果:", 结果) # 调用 /reset_textbox 端点 def 重置文本框(): 结果 = 客户端.predict(api_name="/reset_textbox") print("重置文本框结果:", 结果) # 调用 /predict 端点 def 预测(输入文本, 顶部概率=1, 温度=1, 对话计数=0, 聊天机器人=[]): 结果 = 客户端.predict( inputs=输入文本, top_p=顶部概率, temperature=温度, chat_counter=对话计数, chatbot=聊天机器人, api_name="/predict" ) print("预测结果:", 结果) # 调用 /reset_textbox_1 端点 def 重置文本框1(): 结果 = 客户端.predict(api_name="/reset_textbox_1") print("重置文本框1结果:", 结果) # 调用 /predict_1 端点 def 预测1(输入文本, 顶部概率=1, 温度=1, 对话计数=0, 聊天机器人=[]): 结果 = 客户端.predict( inputs=输入文本, top_p=顶部概率, temperature=温度, chat_counter=对话计数, chatbot=聊天机器人, api_name="/predict_1" ) print("预测1结果:", 结果) # 示例调用 启用输入() # 调用 /enable_inputs 重置文本框() # 调用 /reset_textbox 预测("Hello!!") # 调用 /predict,输入 "Hello!!" 重置文本框1() # 调用 /reset_textbox_1 预测1("Hello again!!") # 调用 /predict_1,输入 "Hello again!!"