开发者社区 > 百炼大模型 > 正文

阿里云百炼这个问题怎么解决?

阿里云百炼这个问题怎么解决?
Error: InvalidParameter, Single round file-content exceeds token limit, please use fileid to supply lengthy input. lQLPKeXKtCDp2SsxzQIEsP75YmV-qWhfBnizCZ0VcwA_516_49.png
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()

展开
收起
三分钟热度的鱼 2024-07-18 08:49:18 47 0
1 条回答
写回答
取消 提交回答
  • 您好,辛苦您加入“阿里云百炼使用体验”群的钉钉群号: 65295003032,在钉钉群内反馈您的问题

    2024-08-08 14:06:24
    赞同 展开评论 打赏
问答分类:
问答地址:

基于通义系列大模型和开源大模型的一站式大模型服务平台,提供「生成式大模型的全流程应用工具」和「企业大模型的全链路训练工具」。为大模型,也为小应用。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载