阿里云百炼这个问题怎么解决?
Error: InvalidParameter, Single round file-content exceeds token limit, please use fileid to supply lengthy input.
import tkinter as tk
from tkinter import scrolledtext
import dashscope
from dashscope import Generation
设置 API 密钥
dashscope.api_key = '' # 替换为你的实际 API 密钥
def send_message():
prompt = prompt_text.get("1.0", tk.END).strip()
content = content_text.get("1.0", tk.END).strip()
full_input = f"{prompt}\n{content}".strip()
result_text.delete("1.0", tk.END)
result_text.insert(tk.END, f"Sending request with input:\n{full_input}\n\n")
result_text.see(tk.END)
result_text.update()
if not full_input:
result_text.insert(tk.END, "Error: Input is empty. Please enter prompt or content.\n")
return
try:
response = Generation.call(
model='qwen-long',
messages=[
{"role": "user", "content": full_input}
],
max_tokens=1500,
top_p=0.8,
temperature=0.7,
result_format='message'
)
# 显示请求 ID
result_text.insert(tk.END, f"Request ID: {response.request_id}\n\n")
if response.status_code == 200:
result_text.insert(tk.END, f"Output: {response.output.choices[0].message.content}\n")
result_text.insert(tk.END, f"\nUsage: {response.usage}\n")
else:
result_text.insert(tk.END, f"Error: {response.code}, {response.message}\n")
except Exception as e:
result_text.insert(tk.END, f"Unexpected error: {str(e)}\n")
print(f"Full error details: {e}") # 在控制台打印完整错误信息
result_text.see(tk.END)
result_text.update()
创建主窗口
root = tk.Tk()
root.title("阿里通义千问 AI 助手")
root.geometry("800x900") # 设置窗口大小
创建并放置 Prompt 输入框
prompt_label = tk.Label(root, text="Prompt:")
prompt_label.pack(pady=(10, 0))
prompt_text = scrolledtext.ScrolledText(root, height=10, width=80, wrap=tk.WORD)
prompt_text.pack(padx=10, pady=(0, 10), fill=tk.BOTH, expand=True)
创建并放置内容输入框
content_label = tk.Label(root, text="内容:")
content_label.pack()
content_text = scrolledtext.ScrolledText(root, height=15, width=80, wrap=tk.WORD)
content_text.pack(padx=10, pady=(0, 10), fill=tk.BOTH, expand=True)
创建并放置发送按钮
send_button = tk.Button(root, text="发送", command=send_message)
send_button.pack(pady=10)
创建并放置结果显示区域
result_label = tk.Label(root, text="AI 回答:")
result_label.pack()
result_text = scrolledtext.ScrolledText(root, height=20, width=80, wrap=tk.WORD)
result_text.pack(padx=10, pady=(0, 10), fill=tk.BOTH, expand=True)
运行主循环
root.mainloop()
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。