Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目运行的问题,前端界面报错:SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON #23

Open
duxueyuan7802632 opened this issue Apr 22, 2024 · 8 comments

Comments

@duxueyuan7802632
Copy link

按照项目说明的步骤:

  1. Run npm run start 。 浏览器自动弹出界面。
  2. cd back-end and Run python run.py. 。弹出提示:Running on http://127.0.0.1:3000/ (Press CTRL+C to quit),进入链接http://127.0.0.1:3000,界面内容为:Not Found。The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
  3. 我的key,openai.proxy都设置完成了。
    4.我在前端尝试输入一段话,就报错:http://localhost:5000/ says SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON。后端也报错:TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
@threeColorFr
Copy link
Member

前端网址端口应该是5000吧? 你是什么平台,linux?,看看包的版本之类的?

@duxueyuan7802632
Copy link
Author

感谢回复,我是windows11,后端启动的时候,有个警告,但我觉得不是这个原因吧

: UserWarning: The current Python is not a recommended version, 3.10+ is recommended
import("warnings").warn(

  • Serving Flask app "run" (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    前端启动的界面:
    front
    hou后端的运行界面:
    back

@threeColorFr
Copy link
Member

你现在前后端可以打通吗。能看看具体报错位置在哪行代码和原因吗。

@duxueyuan7802632
Copy link
Author

老师!前端执行没问题,http://localhost:5000/,但clear那个按钮失效。后端一直就not found http://127.0.0.1:3000/ (Press CTRL+C to quit)。当我在前端输入一端文字的时候,就报出我上面截图的错误,完后在后端就有如下错误提示:
"{"sentence":"你好","type":"","access":"","task":"NER","lang":"chinese"}"
<class 'str'>
后端传入数据: {'sentence': '你好', 'type': '', 'access': '', 'task': 'NER', 'lang': 'chinese'}
127.0.0.1 - - [30/Apr/2024 11:13:34] "POST /api/v1/updateStaff HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 2464, in call
return self.wsgi_app(environ, start_response)
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
return self.finalize_request(rv)
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 1968, in finalize_request
response = self.make_response(rv)
File "C:\ProgramData\Anaconda3\Lib\site-packages\flask\app.py", line 2097, in make_response
raise TypeError(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

在run.py代码中,我修改了静态模版和动态模版的路径,也没好使:app = Flask(name, template_folder='../front-end/public', static_folder='../front-end/src'),路径设置的有问题啊?

@threeColorFr
Copy link
Member

threeColorFr commented Apr 30, 2024

你的意思是前后端可以打通跑出结果,但是clear没用是吗?
这个问题我复现不出来,我之前试的windows上运行也是没问题的。
你看看修改一下port proxy之类的呢。还有你的port有没有开。
截屏2024-04-30 11 31 29

@duxueyuan7802632
Copy link
Author

duxueyuan7802632 commented Apr 30, 2024

大佬,跑通了,呵呵!代码问题!
1.可能是我 npm install 之后,直接调试,导致不知名的错误,应该重启电脑,现开启前端,再开启后端。
2.易错的点是KEY,我是买的第三方的key, proxy代理,应该在您 openai.api_base 里面设置,而不是 openai.proxy里面设置。
3.关于clear 按钮,功能没问题,我理解错了,当我跑通了才知道他的作用,他是清理下面的显示,而不是清理输入框的信息。谢谢大佬回复,让我排除了问题!

@duxueyuan7802632
Copy link
Author

duxueyuan7802632 commented Apr 30, 2024 via email

@ytWu1314
Copy link

ytWu1314 commented May 3, 2024

大佬,跑通了,呵呵!代码问题! 1.可能是我 npm install 之后,直接调试,导致不知名的错误,应该重启电脑,现开启前端,再开启后端。 2.易错的点是KEY,我是买的第三方的key, proxy代理,应该在您 openai.api_base 里面设置,而不是 openai.proxy里面设置。 3.关于clear 按钮,功能没问题,我理解错了,当我跑通了才知道他的作用,他是清理下面的显示,而不是清理输入框的信息。谢谢大佬回复,让我排除了问题!

大佬,您的proxy怎么成功的?openai.api_base = "这里要填什么呀?" #或者利用反向代理openai.com(代理获取:https://github.com/justjavac/openai-proxy
(注释掉上面那句代码)

反向代理那个教程我只在deno 弄了一个域名,openai api的key我申请了,但是布吉岛怎么用,是填到df_access = []里面吗?(为啥列表要分成两块?)

Snipaste_2024-05-03_11-10-08

Snipaste_2024-05-03_11-10-46

您整体的流程是咋样的?我到现在还是跑不起来作者的这个项目

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants