如何做慕课网站,招聘网58同城招聘,网站优化内容有哪些,wordpress调模板用钩子课程
《生成式 AI》课程 第3講#xff1a;訓練不了人工智慧嗎#xff1f;你可以訓練你自己-CSDN博客
任务1:总结 1.我们希望你创建一个可以执行文章摘要的机器人。 2.设计一个提示符#xff0c;使语言模型能够对文章进行总结。 model: gpt-4o-mini,#gpt-3.5-turbo, import…课程
《生成式 AI》课程 第3講訓練不了人工智慧嗎你可以訓練你自己-CSDN博客
任务1:总结 1.我们希望你创建一个可以执行文章摘要的机器人。 2.设计一个提示符使语言模型能够对文章进行总结。 model: gpt-4o-mini,#gpt-3.5-turbo, import requests
import gradio as gr
import jsondef get_response(input_text):url https://openai.api2d.net/v1/chat/completionsheaders {Content-Type: application/json,Authorization: Bearer f # -- 把 fkxxxxx 替换成你自己的 Forward Key注意前面的 Bearer 要保留并且和 Key 中间有一个空格。}data {model: gpt-4o-mini,#gpt-3.5-turbo,messages: [{role: user, content: f对输入内容总结{input_text}}]}response requests.post(url, headersheaders, jsondata)status_code response.status_codetry:json_data response.json()# 提取模型名称model_name json_data.get(model, 未知模型)# 提取助手回复的内容assistant_content json_data.get(choices, [])[0].get(message, {}).get(content, 无回复内容)# 提取各类token数量prompt_tokens json_data.get(usage, {}).get(prompt_tokens, 0)completion_tokens json_data.get(usage, {}).get(completion_tokens, 0)total_tokens json_data.get(usage, {}).get(total_tokens, 0)return status_code, f模型: {model_name}\n回复内容: {assistant_content}\n提示词token数: {prompt_tokens}\n回复内容token数: {completion_tokens}\n总token数: {total_tokens}except json.JSONDecodeError:return status_code, 解析JSON出错iface gr.Interface(fnget_response,inputsgr.Textbox(lines2, placeholder请输入你想发送的内容),outputs[gr.Textbox(label状态码), gr.Textbox(label解析后的响应内容)]
)iface.launch()
执行的结果