pycharm编写ai大模型api调用程序及常见错误

发布于:2025-02-28 ⋅ 阅读:(18) ⋅ 点赞:(0)

一级目录

1. 访问Django项目,python web url时,报错

<div id="explanation">
		<p>
			You’re seeing this error because you have <code>DEBUG = True</code> in
			your Django settings file. Change that to <code>False</code>, and Django
			will display a standard 404 page.
		</p>
	</div>

原程序如下 :

from django.urls import path

from ltjt_aiseek_app.com.ltjt.web import views

# from. import views

urlpatterns = [
    # 这里可以添加具体的路由映射,例如:
    # path('chat/', views.chat, name='chat'),
    # 不行的话 再把views 放到根目录下来
    # 'chat/' 后面带不带/ 决定了访问时 http://localhost:9000/api/chat 的最后要不要 http://localhost:9000/api/chat/
    path('chat/', views.chat, name='chat'),
    # path('chat', views.chat, name='chat'),
]

在这里插入图片描述
第1次访问Url 结尾不带 ”/“

http://localhost:9000/api/chat

在这里插入图片描述
第2次访问Url 结尾不带 ”/“

http://localhost:9000/api/chat/

在这里插入图片描述

带 ”/" 不方便,选择修改程序 urls.py,路由映射中去年 “/”
在这里插入图片描述

2. 传参报名,python web url时,报错

Internal Server Error: /api/chat
Traceback (most recent call last):
  File "D:\Users\wang\IdeaProjects\ltkj_git\ltjt-ai-seek\seek_backend_py\ltjt_aiseek_app\com\ltjt\web\views.py", line 37, in chat
    tongyi_response = tongyi_llm.chat(messages)
  File "D:\Users\wang\IdeaProjects\ltkj_git\ltjt-ai-seek\seek_backend_py\ltjt_aiseek_app\com\ltjt\models\tongyiqianwen.py", line 24, in chat
    "role": msg["role"],
TypeError: string indices must be integers
During handling of the above exception, another exception occurred:

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

messages = [
                {
                    "role": "user",
                    "content": "介绍一下故宫"
                }
            ]

在这里插入图片描述

正确访问结果:

哪些是有用的值,哪些需要保存
在这里插入图片描述

二、购买价格 和 见错误码

在这里插入图片描述