js.util.Dictionary.js代码

本文介绍了一个基于JavaScript实现的字典类,该类提供了多种常用的方法如添加、删除、查询等,旨在帮助开发者减少重复代码,提高开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

js.util = (js.util || {});

 

js.util.Dictionary = newjs.lang.Class()  ({

   /** Utility class providing common java-like dictionary functionality tohelp keep code D-R-Y. **/

   __init__ : function( map )  {

       /** Initializer for Dictionary **/

       this.clear();

       

       // NOTE: be very careful when using the constructor as a wrapper for anexisting dictionary;

       //   this action iterates theentire dictionary.

       if( map )  {

           this.putAll( map );

       }

   },

   

   clear : function()  {

       /** Clear contents of this dict. **/

       this._size = 0;

       this._dictionary = {};

   },

 

   containsKey : function( key )  {

       /** Check if given key exists in this dict. **/

       return( this._dictionary.hasOwnProperty( key ) );

   },

   

   containsValue : function( value ) {

       /** Check if given value exists in this dict. **/

       var key;

       this.iterate(function( k, v )  {

           if( value === v )  {

                key = k;

                return( true );

           }

       });

       return( key !== undefined );

   },

   

   entrySet : function()  {

       /** Retrieve a unique list of values from this dict. **/

       var items = [];

       //  acquire entries

       this.iterate(function( k, v )  {

           items.push( v );

       });

       return( new js.util.Set( items ) );

   },

   

   get : function( key )  {

       /** Retrieve value associated with given key. **/

       return( this._dictionary[ key ] );

   },

   

   isEmpty : function()  {

       /** Check if this dict contains zero elements. **/

       return( this.size() === 0 );

   },

   

   keySet  : function()  {

       /** Retrieve a unique list of keys from this dict. **/

       var keys = [];

       //  acquire entries

       this.iterate( function( k, v )  {

           keys.push( k );

       });

       return( new js.util.Set( keys ) );

   },

   

   put : function( key, value )  {

       /** Assign given value to given key within this dict. **/

       if( ! this._dictionary.hasOwnProperty( key ) )  {

           this._size++;

       }

       

       this._dictionary[ key ] = value;

       

       return( this );

   },

   

   putAll : function( map )  {

       /** Assign every value within given map to their associated keys, withinthis dict. **/

       var that = this;

       map.iterate( function( k, v )  {

           that.put( k, v );

       });

   },

   

   iterate : function( callback )  {

       /** Convenient, unified method of iterating elements in this dict.

           This pattern is common to all collection classes. **/

       var dictionary = this._dictionary;

       for( var property in dictionary ) {

           if( ! dictionary.hasOwnProperty( property ) )  { continue; }

           

           if( callback( property, dictionary[ property ] ) )  {

                break;

           }

       }

   },

 

   remove : function( key )  {

       /** Remove key from this dict. **/

        var success = false;

       if( this._dictionary.hasOwnProperty( key ) )  {

           success = delete( this._dictionary[ key ] );

           this._size--;

       }

       return( success );

   },

   

   size : function()  {

       /** Retrieve the size of this dict. **/

       return( this._size );

   },

   

   values : function()  {

       /** Retrieve a list of all values within this dict. **/

       var values = [];

       for( var key in this._dictionary ) {

           if( ! this._dictionary.hasOwnProperty( key ) )  { continue; }

           

           values.push( key );

       }

       return( new js.util.ArrayList( values ) );

   },

   

   clone : function()  {

       /** Retrieve a deep-clone (if values implement a clone method), of thisdict. **/

       var dictionary = new js.util.Dictionary();

       this.iterate( function( k, v )  {

           dictionary.put( k, (v && (v.clone instanceof Function) ?v.clone() : v) );

       });

       return( dictionary );

   },

   

   toDict : function()  {

       /** Retrieve a deep-clone (if values implement a clone method), of

           this dict as an Object rather than a Dictionary. **/

       return( this.clone()._dictionary );

    }

})

.Static({

   Iterate : function( dictionary, callback )  {

       /** Iterate given dict, invoking given callback for each element.

           Helper method to avoid the requirement to instantiate this class forone-off use-cases. **/

       js.util.Dictionary.prototype.iterate.call( { _dictionary : dictionary },callback );

   },

   

   Iterator : function( dictionary ) {

       /** Retrieve an object which contains an 'iterate' method to be invokedat a later date. **/

       // TODO: implement full iterator capabilities.

       return({

           iterate : function( callback )  {

               js.util.Dictionary.prototype.iterate.call( { _dictionary : dictionary },callback );

           }

       });

    }

});

转自http://code.google.com/p/javascript-classes/source/browse/trunk/js.util.Dictionary.js
上面的是我的项目结构,现在我想要加入开源的通义大模型,实现项目具有以下功能 自行准备本地知识库资料(如本专业相关资料内容)作为大模型本地知识库的输入 教师侧:备课与设计: 根据所提供的本地课程大纲、课程知识库文档等自动设计教学内容,包括知识讲解、实训练习与指导、时间分布等。 · 考核内容生成: 根据教学内容自动生成考核题目及参考答案,考核题目种类可多样化,根据学科设计,如计算机类可设计相关编程题和答案 · 学情数据分析: 对学生提交的答案进行自动化检测,提供错误定位与修正建议。对学生整体数据进行分析,总结知识掌握情况与教学建议。 学生侧: · 在线学习助手: 对学生的提出的问题,结合教学内容进行解答; · 实时练习评测助手: 根据学生历史练习情况,以及学生的练习要求,生成随练题目,并对练习纠错。 管理侧: 用户管理:管理员/教师/学生等用户的基本管理 课件资源管理:按学科列表教师备课产生的课件、练习等资源,可以导出。 大屏概览: · 教师使用次数统计/活跃板块(当日/本周) · 学生使用次数统计/活跃板块(当日/本周) · 教学效率指数(备课与修正耗时、课后练习设计与修正耗时、课程优化方向(如:某学科通过率持续偏低) · 学生学习效果(平均正确率趋势、知识点掌握情况,高频错误知识点等) 非功能性需求 需明确使用至少1个开源大模型作为核心技术组件; 需采用本地知识库作为输入,知识库资料总量不大于100M; 生成的内容、练习与答案与本地知识库的关联性和准确性;(对抽取知识点设计的题目验证关联性和与答案的准确性有知识点说明) 我该在哪里添加 下面我再对功能进行进一步的说明:1、首先本地知识库可以让用户自己上传(即用户自己可以控制本地知识库,但一开始会有一个默认的知识库,知识库是在项目中的某个目录中可以吗), 2、在备课与设计的功能上ai可以帮助教师设计教学内容,并且教师可以下载该教学内容 3、在考核内容生成中,考核题目同样可以进行下载,而且可以有带答案不带答案两种方式; 完整的项目结构又是怎样的,哪些内容需要更改 下面是我目前的项目结构卷 Windows-SSD 的文件夹 PATH 列表 卷序列号为 20C7-404E C:. | project_structure.txt | +---main | +---java | | \---com | | | Aiapp1Application.java | | | | | +---annotation | | | APPLoginUser.java | | | IgnoreAuth.java | | | LoginUser.java | | | | | +---config | | | InterceptorConfig.java | | | MybatisPlusConfig.java | | | MyMetaObjectHandler.java | | | | | +---controller | | | CommonController.java | | | ConfigController.java | | | DictionaryController.java | | | ExampaperController.java | | | ExamquestionController.java | | | ExamrecordController.java | | | ExamredetailsController.java | | | ExamrewrongquestionController.java | | | FileController.java | | | ForumController.java | | | JiaoshiController.java | | | KechengController.java | | | KechengLiuyanController.java | | | NewsController.java | | | UsersController.java | | | YonghuController.java | | | | | +---dao | | | CommonDao.java | | | ConfigDao.java | | | DictionaryDao.java | | | ExampaperDao.java | | | ExamquestionDao.java | | | ExamrecordDao.java | | | ExamredetailsDao.java | | | ExamrewrongquestionDao.java | | | ForumDao.java | | | JiaoshiDao.java | | | KechengDao.java | | | KechengLiuyanDao.java | | | NewsDao.java | | | TokenDao.java | | | UsersDao.java | | | YonghuDao.java | | | | | +---entity | | | | ConfigEntity.java | | | | DictionaryEntity.java | | | | EIException.java | | | | ExampaperEntity.java | | | | ExamquestionEntity.java | | | | ExamrecordEntity.java | | | | ExamredetailsEntity.java | | | | ExamrewrongquestionEntity.java | | | | ForumEntity.java | | | | JiaoshiEntity.java | | | | KechengEntity.java | | | | KechengLiuyanEntity.java | | | | NewsEntity.java | | | | TokenEntity.java | | | | UsersEntity.java | | | | YonghuEntity.java | | | | | | | +---model | | | | DictionaryModel.java | | | | ExampaperModel.java | | | | ExamquestionModel.java | | | | ExamrecordModel.java | | | | ExamredetailsModel.java | | | | ExamrewrongquestionModel.java | | | | ForumModel.java | | | | JiaoshiModel.java | | | | KechengLiuyanModel.java | | | | KechengModel.java | | | | NewsModel.java | | | | YonghuModel.java | | | | | | | +---view | | | | DictionaryView.java | | | | ExampaperView.java | | | | ExamquestionView.java | | | | ExamrecordView.java | | | | ExamredetailsView.java | | | | ExamrewrongquestionView.java | | | | ForumView.java | | | | JiaoshiView.java | | | | KechengLiuyanView.java | | | | KechengView.java | | | | NewsView.java | | | | YonghuView.java | | | | | | | \---vo | | | DictionaryVO.java | | | ExampaperVO.java | | | ExamquestionVO.java | | | ExamrecordVO.java | | | ExamredetailsVO.java | | | ExamrewrongquestionVO.java | | | ForumVO.java | | | JiaoshiVO.java | | | KechengLiuyanVO.java | | | KechengVO.java | | | NewsVO.java | | | YonghuVO.java | | | | | +---interceptor | | | AuthorizationInterceptor.java | | | | | +---model | | | \---enums | | | TypeEnum.java | | | | | +---service | | | | CommonService.java | | | | ConfigService.java | | | | DictionaryService.java | | | | ExampaperService.java | | | | ExamquestionService.java | | | | ExamrecordService.java | | | | ExamredetailsService.java | | | | ExamrewrongquestionService.java | | | | ForumService.java | | | | JiaoshiService.java | | | | KechengLiuyanService.java | | | | KechengService.java | | | | NewsService.java | | | | TokenService.java | | | | UsersService.java | | | | YonghuService.java | | | | | | | \---impl | | | CommonServiceImpl.java | | | ConfigServiceImpl.java | | | DictionaryServiceImpl.java | | | ExampaperServiceImpl.java | | | ExamquestionServiceImpl.java | | | ExamrecordServiceImpl.java | | | ExamredetailsServiceImpl.java | | | ExamrewrongquestionServiceImpl.java | | | ForumServiceImpl.java | | | JiaoshiServiceImpl.java | | | KechengLiuyanServiceImpl.java | | | KechengServiceImpl.java | | | NewsServiceImpl.java | | | TokenServiceImpl.java | | | UsersServiceImpl.java | | | YonghuServiceImpl.java | | | | | +---ServletContextListener | | | DictionaryServletContextListener.java | | | | | +---thread | | | MyThreadMethod.java | | | | | \---utils | | BaiduUtil.java | | CommonUtil.java | | FileUtil.java | | HttpClientUtils.java | | JQPageInfo.java | | MPUtil.java | | PageUtils.java | | PoiUtil.java | | Query.java | | R.java | | SpringContextUtils.java | | SQLFilter.java | | StringUtil.java | | ValidatorUtils.java | | | \---resources | | application.yml | | | +---front | | | index.html | | | | | +---css | | | bootstrap.min.css | | | common.css | | | front-kaoshi-style.css | | | homeworkPC.min.css | | | style.css | | | theme.css | | | | | +---elementui | | | | elementui.css | | | | elementui.js | | | | | | | \---fonts | | | element-icons.ttf | | | element-icons.woff | | | | | +---img | | | avator.png | | | banner.jpg | | | jianshe.png | | | jiaotong.png | | | line.jpg | | | nongye.png | | | seckilling.jpg | | | select.png | | | selectActive.png | | | unselect.png | | | weixin.png | | | yuan.png | | | zhifubao.png | | | zhongguo.png | | | | | +---js | | | bootstrap.AMapPositionPicker.js | | | bootstrap.min.js | | | config.js | | | jquery.js | | | utils.js | | | validate.js | | | vue.js | | | | | +---layui | | | | layui.all.js | | | | layui.js | | | | | | | +---css | | | | | layui.css | | | | | layui.mobile.css | | | | | | | | | \---modules | | | | | code.css | | | | | | | | | +---laydate | | | | | \---default | | | | | laydate.css | | | | | | | | | \---layer | | | | \---default | | | | icon-ext.png | | | | icon.png | | | | layer.css | | | | loading-0.gif | | | | loading-1.gif | | | | loading-2.gif | | | | | | | +---font | | | | iconfont.eot | | | | iconfont.svg | | | | iconfont.ttf | | | | iconfont.woff | | | | iconfont.woff2 | | | | | | | +---images | | | | \---face | | | | 0.gif | | | | 1.gif | | | | 10.gif | | | | 11.gif | | | | 12.gif | | | | 13.gif | | | | 14.gif | | | | 15.gif | | | | 16.gif | | | | 17.gif | | | | 18.gif | | | | 19.gif | | | | 2.gif | | | | 20.gif | | | | 21.gif | | | | 22.gif | | | | 23.gif | | | | 24.gif | | | | 25.gif | | | | 26.gif | | | | 27.gif | | | | 28.gif | | | | 29.gif | | | | 3.gif | | | | 30.gif | | | | 31.gif | | | | 32.gif | | | | 33.gif | | | | 34.gif | | | | 35.gif | | | | 36.gif | | | | 37.gif | | | | 38.gif | | | | 39.gif | | | | 4.gif | | | | 40.gif | | | | 41.gif | | | | 42.gif | | | | 43.gif | | | | 44.gif | | | | 45.gif | | | | 46.gif | | | | 47.gif | | | | 48.gif | | | | 49.gif | | | | 5.gif | | | | 50.gif | | | | 51.gif | | | | 52.gif | | | | 53.gif | | | | 54.gif | | | | 55.gif | | | | 56.gif | | | | 57.gif | | | | 58.gif | | | | 59.gif | | | | 6.gif | | | | 60.gif | | | | 61.gif | | | | 62.gif | | | | 63.gif | | | | 64.gif | | | | 65.gif | | | | 66.gif | | | | 67.gif | | | | 68.gif | | | | 69.gif | | | | 7.gif | | | | 70.gif | | | | 71.gif | | | | 8.gif | | | | 9.gif | | | | | | | \---lay | | | \---modules | | | carousel.js | | | code.js | | | colorpicker.js | | | element.js | | | flow.js | | | form.js | | | jquery.js | | | laydate.js | | | layedit.js | | | layer.js | | | laypage.js | | | laytpl.js | | | mobile.js | | | rate.js | | | slider.js | | | table.js | | | transfer.js | | | tree.js | | | upload.js | | | util.js | | | | | +---modules | | | | config.js | | | | | | | +---http | | | | http.js | | | | | | | +---layarea | | | | layarea.js | | | | | | | \---tinymce | | | | index.html | | | | tinymce.js | | | | | | | \---tinymce | | | | jquery.tinymce.min.js | | | | license.txt | | | | readme.md | | | | tinymce.js | | | | tinymce.min.js | | | | | | | +---langs | | | | readme.md | | | | zh_CN.js | | | | | | | +---plugins | | | | +---advlist | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---anchor | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---autolink | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---autoresize | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---autosave | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---bbcode | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---charmap | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---code | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---codesample | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---colorpicker | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---contextmenu | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---directionality | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---emoticons | | | | | | plugin.js | | | | | | plugin.min.js | | | | | | | | | | | \---js | | | | | emojis.js | | | | | emojis.min.js | | | | | | | | | +---fullpage | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---fullscreen | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---help | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---hr | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---image | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---imagetools | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---importcss | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---indent2em | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---insertdatetime | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---legacyoutput | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---link | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---lists | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---media | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---nonbreaking | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---noneditable | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---pagebreak | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---paste | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---preview | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---print | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---quickbars | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---save | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---searchreplace | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---spellchecker | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---tabfocus | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---table | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---template | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---textcolor | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---textpattern | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---toc | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---visualblocks | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | +---visualchars | | | | | plugin.js | | | | | plugin.min.js | | | | | | | | | \---wordcount | | | | plugin.js | | | | plugin.min.js | | | | | | | +---skins | | | | +---content | | | | | +---dark | | | | | | content.css | | | | | | content.min.css | | | | | | content.min.css.map | | | | | | | | | | | +---default | | | | | | content.css | | | | | | content.min.css | | | | | | content.min.css.map | | | | | | | | | | | +---document | | | | | | content.css | | | | | | content.min.css | | | | | | content.min.css.map | | | | | | | | | | | \---writer | | | | | content.css | | | | | content.min.css | | | | | content.min.css.map | | | | | | | | | \---ui | | | | +---oxide | | | | | | content.css | | | | | | content.inline.css | | | | | | content.inline.min.css | | | | | | content.inline.min.css.map | | | | | | content.min.css | | | | | | content.min.css.map | | | | | | content.mobile.css | | | | | | content.mobile.min.css | | | | | | content.mobile.min.css.map | | | | | | skin.css | | | | | | skin.min.css | | | | | | skin.min.css.map | | | | | | skin.mobile.css | | | | | | skin.mobile.min.css | | | | | | skin.mobile.min.css.map | | | | | | | | | | | \---fonts | | | | | tinymce-mobile.woff | | | | | | | | | \---oxide-dark | | | | | content.css | | | | | content.inline.css | | | | | content.inline.min.css | | | | | content.inline.min.css.map | | | | | content.min.css | | | | | content.min.css.map | | | | | content.mobile.css | | | | | content.mobile.min.css | | | | | content.mobile.min.css.map | | | | | skin.css | | | | | skin.min.css | | | | | skin.min.css.map | | | | | skin.mobile.css | | | | | skin.mobile.min.css | | | | | skin.mobile.min.css.map | | | | | | | | | \---fonts | | | | tinymce-mobile.woff | | | | | | | \---themes | | | +---mobile | | | | theme.js | | | | theme.min.js | | | | | | | \---silver | | | theme.js | | | theme.min.js | | | | | +---pages | | | +---chat | | | | chat.html | | | | | | | +---dictionary | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---exampaper | | | | add.html | | | | detail.html | | | | exam.html | | | | list.html | | | | | | | +---examquestion | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---examrecord | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---examredetails | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---examrewrongquestion | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---forum | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---home | | | | home.html | | | | | | | +---jiaoshi | | | | add.html | | | | center.html | | | | detail.html | | | | list.html | | | | register.html | | | | | | | +---kecheng | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---kechengLiuyan | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---login | | | | login.html | | | | | | | +---news | | | | add.html | | | | detail.html | | | | list.html | | | | | | | +---recharge | | | | recharge.html | | | | | | | \---yonghu | | | add.html | | | center.html | | | detail.html | | | list.html | | | register.html | | | | | \---xznstatic | | +---css | | | | bootstrap.min.css | | | | common.css | | | | element.min.css | | | | login.css | | | | public.css | | | | style.css | | | | swiper.min.css | | | | | | | \---fonts | | | element-icons.ttf | | | element-icons.woff | | | | | +---img | | | 162237296.jpg | | | 162240878.jpg | | | 19.jpg | | | 1_092ZZ2503138.jpg | | | 20.jpg | | | index_24.gif | | | index_35.gif | | | index_41.gif | | | index_44.gif | | | logo.png | | | news_list_time.jpg | | | service_btn.png | | | service_img.png | | | service_title.png | | | | | \---js | | bootstrap.min.js | | element.min.js | | index.js | | jquery-1.11.3.min.js | | jquery.SuperSlide.2.1.1.js | | swiper.min.js | | | +---img | | \---img | | back-img-bg.jpg | | front-img-bg.jpg | | logo.jpg | | | +---mapper | | CommonDao.xml | | ConfigDao.xml | | DictionaryDao.xml | | ExampaperDao.xml | | ExamquestionDao.xml | | ExamrecordDao.xml | | ExamredetailsDao.xml | | ExamrewrongquestionDao.xml | | ForumDao.xml | | JiaoshiDao.xml | | KechengDao.xml | | KechengLiuyanDao.xml | | NewsDao.xml | | TokenDao.xml | | UsersDao.xml | | YonghuDao.xml | | | +---static | | +---admin | | | | 1-install.bat | | | | 2-run.bat | | | | 3-build.bat | | | | babel.config.js | | | | package-lock.json | | | | package.json | | | | vue.config.js | | | | | | | +---dist | | | | | favicon.ico | | | | | index.html | | | | | | | | | +---css | | | | | app.381d2044.css | | | | | chunk-vendors.a72b0961.css | | | | | | | | | +---fonts | | | | | element-icons.535877f5.woff | | | | | element-icons.732389de.ttf | | | | | | | | | +---img | | | | | 404.3648f234.png | | | | | zhongguo.20798bfa.png | | | | | | | | | \---js | | | | app.b100d28f.js | | | | app.b100d28f.js.map | | | | chunk-vendors.213b68ba.js | | | | chunk-vendors.213b68ba.js.map | | | | | | | +---public | | | | favicon.ico | | | | index.html | | | | | | | \---src | | | | App.vue | | | | main.js | | | | | | | +---assets | | | | +---css | | | | | element-variables.scss | | | | | style.scss | | | | | | | | | \---img | | | | | 404.png | | | | | avator.png | | | | | bg.jpg | | | | | captcha.jpg | | | | | login.png | | | | | logo.png | | | | | password.png | | | | | role.png | | | | | username.png | | | | | | | | | \---test | | | | jianshe.png | | | | jiaotong.png | | | | nongye.png | | | | weixin.png | | | | zhifubao.png | | | | zhongguo.png | | | | | | | +---components | | | | +---common | | | | | BreadCrumbs.vue | | | | | Editor.vue | | | | | FileUpload.vue | | | | | | | | | +---home | | | | | HomeCard.vue | | | | | HomeChart.vue | | | | | HomeComment.vue | | | | | HomeProgress.vue | | | | | | | | | +---index | | | | | IndexAside.vue | | | | | IndexAsideStatic.vue | | | | | IndexAsideSub.vue | | | | | IndexHeader.vue | | | | | IndexMain.vue | | | | | | | | | \---SvgIcon | | | | index.vue | | | | | | | +---icons | | | | | index.js | | | | | svgo.yml | | | | | | | | | \---svg | | | | | 404.svg | | | | | articleEdit.svg | | | | | banner.svg | | | | | bug.svg | | | | | build.svg | | | | | cfg.svg | | | | | channel.svg | | | | | chart.svg | | | | | clipboard.svg | | | | | code.svg | | | | | component.svg | | | | | contacts.svg | | | | | dashboard.svg | | | | | date.svg | | | | | dept.svg | | | | | dict.svg | | | | | documentation.svg | | | | | download.svg | | | | | drag.svg | | | | | druid.svg | | | | | edit.svg | | | | | education.svg | | | | | email.svg | | | | | excel.svg | | | | | exit-fullscreen.svg | | | | | eye-open.svg | | | | | file.svg | | | | | form.svg | | | | | fullscreen.svg | | | | | icon.svg | | | | | international.svg | | | | | job.svg | | | | | language.svg | | | | | link.svg | | | | | list.svg | | | | | lock.svg | | | | | log.svg | | | | | logininfor.svg | | | | | menu.svg | | | | | message.svg | | | | | money.svg | | | | | monitor.svg | | | | | nested.svg | | | | | nested0.svg | | | | | online.svg | | | | | operation.svg | | | | | password.svg | | | | | password0.svg | | | | | pdf.svg | | | | | people.svg | | | | | peoples.svg | | | | | phone.svg | | | | | post.svg | | | | | qq.svg | | | | | search.svg | | | | | sender.svg | | | | | server.svg | | | | | shopping.svg | | | | | shoppingCard.svg | | | | | size.svg | | | | | skill.svg | | | | | star.svg | | | | | swagger.svg | | | | | system.svg | | | | | tab.svg | | | | | table.svg | | | | | table0.svg | | | | | task.svg | | | | | template.svg | | | | | theme.svg | | | | | tool.svg | | | | | tree-table.svg | | | | | tree.svg | | | | | user.svg | | | | | user0.svg | | | | | validCode.svg | | | | | wechat.svg | | | | | zip.svg | | | | | | | | | \---svg | | | | agricultureRegister.svg | | | | AI.svg | | | | AIDeviceLayout.svg | | | | area.svg | | | | base.svg | | | | batch.svg | | | | board.svg | | | | board1.svg | | | | boardConfig.svg | | | | cfg.svg | | | | code.svg | | | | company.svg | | | | crop.svg | | | | crops.svg | | | | dashboard.svg | | | | dataAbnormal.svg | | | | dataLack.svg | | | | dept.svg | | | | device.svg | | | | deviceMonitorData.svg | | | | dict.svg | | | | diseasesinsect.svg | | | | diseasesinsects.svg | | | | documentation.svg | | | | EIM.svg | | | | email.svg | | | | environmental.svg | | | | eye-open.svg | | | | farmingProject.svg | | | | finance.svg | | | | financeBudget.svg | | | | financeReality.svg | | | | firm.svg | | | | firms.svg | | | | harvestBatch.svg | | | | harvestDetection.svg | | | | harvestManage.svg | | | | harvestWorks.svg | | | | heavyMetalDetection.svg | | | | home.svg | | | | inspection.svg | | | | internet.svg | | | | internetActive.svg | | | | log.svg | | | | mainSystem.svg | | | | mainSystemActive.svg | | | | menu.svg | | | | monitorEquipment.svg | | | | news.svg | | | | order.svg | | | | password.svg | | | | peoples.svg | | | | pest.svg | | | | pestActive.svg | | | | pesticideResidue.svg | | | | pests.svg | | | | phone.svg | | | | plant.svg | | | | plants.svg | | | | plantsActive.svg | | | | residual.svg | | | | retroactiveCoding.svg | | | | scheme.svg | | | | source.svg | | | | sourceActive.svg | | | | system.svg | | | | task.svg | | | | tempFarm.svg | | | | traceability.svg | | | | traceabilityList.svg | | | | traceabilityStyle.svg | | | | user.svg | | | | user0.svg | | | | validCode.svg | | | | video.svg | | | | videoEquipment.svg | | | | videoKey.svg | | | | VIP.svg | | | | vipCustomized.svg | | | | warnings.svg | | | | workOrder.svg | | | | ┐┤?х╣▄└э.svg | | | | ╓╪╜Ё╩?╝ь▓т╣▄└э.svg | | | | | | | +---router | | | | router-static.js | | | | | | | +---store | | | | store.js | | | | | | | +---utils | | | | api.js | | | | base.js | | | | http.js | | | | i18n.js | | | | menu.js | | | | storage.js | | | | style.css | | | | style.js | | | | utils.js | | | | validate.js | | | | | | | \---views | | | | 404.vue | | | | center.vue | | | | home.vue | | | | index.vue | | | | login.vue | | | | pay.vue | | | | register.vue | | | | update-password.vue | | | | | | | \---modules | | | +---config | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionary | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionaryExampaper | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionaryExamquestion | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionaryForumState | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionaryKecheng | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionaryNews | | | | add-or-update.vue | | | | list.vue | | | | | | | +---dictionarySex | | | | add-or-update.vue | | | | list.vue | | | | | | | +---exampaper | | | | add-or-update.vue | | | | exam.vue | | | | list.vue | | | | | | | +---examquestion | | | | add-or-update.vue | | | | list.vue | | | | | | | +---examrecord | | | | add-or-update.vue | | | | list.vue | | | | | | | +---examredetails | | | | add-or-update.vue | | | | list.vue | | | | | | | +---examrewrongquestion | | | | add-or-update.vue | | | | list.vue | | | | | | | +---forum | | | | add-or-update.vue | | | | list.vue | | | | | | | +---jiaoshi | | | | add-or-update.vue | | | | list.vue | | | | | | | +---kecheng | | | | add-or-update.vue | | | | list.vue | | | | | | | +---kechengLiuyan | | | | add-or-update.vue | | | | list.vue | | | | | | | +---news | | | | add-or-update.vue | | | | list.vue | | | | | | | +---users | | | | add-or-update.vue | | | | list.vue | | | | | | | \---yonghu | | | add-or-update.vue | | | list.vue | | | | | \---upload | | a.txt | | config1.jpg | | config2.jpg | | config3.jpg | | file.rar | | jiaoshi.xls | | jiaoshi1.jpg | | jiaoshi2.jpg | | jiaoshi3.jpg | | jiaoshi4.jpg | | jiaoshi5.jpg | | jiaoshi6.jpg | | kecheng1.jpg | | kecheng2.jpg | | kecheng3.jpg | | kecheng4.jpg | | kecheng5.jpg | | kecheng6.jpg | | music.mp3 | | news1.jpg | | news2.jpg | | news3.jpg | | news4.jpg | | news5.jpg | | news6.jpg | | video.mp4 | | yonghu1.jpg | | yonghu2.jpg | | yonghu3.jpg | | | \---templates \---test \---java \---com Aiapp1ApplicationTests.java
最新发布
07-15
<think>根据需求,我们需要在项目中集成开源大模型(如通义大模型)来实现教师侧的备课与设计、考核内容生成、学情数据分析,学生侧的在线学习助手和实时练习评测助手,以及管理侧的大屏概览等功能。同时,需要支持本地知识库的上传和管理。 ### 分析现有项目结构 当前项目是一个典型的Spring Boot应用,包含以下主要部分: - `main/java/com/...`: 包含应用的主要Java代码,包括启动类、配置、控制器、实体、DAO、服务等。 - `main/resources`: 包含配置文件、前端资源、静态文件、MyBatis映射文件等。 - `test`: 测试代码。 ### 需要添加的功能模块 1. **大模型集成模块**:用于调用开源大模型(如通义)的API。 2. **本地知识库管理模块**:允许用户上传和管理知识库文件(默认知识库放在项目目录中,如`resources/knowledge`)。 3. **教师侧功能**: - 备课与设计:根据知识库生成教学内容(包括知识讲解、实训、时间分布等),并提供下载。 - 考核内容生成:生成题目和答案,支持下载(带答案和不带答案)。 4. **学生侧功能**: - 在线学习助手:回答学生问题,结合知识库和教学内容。 - 实时练习评测:生成练习题,并自动批改和纠错。 5. **管理侧功能**: - 用户管理(已有,可能需要扩展)。 - 课件资源管理:管理教师生成的课件和练习,支持导出。 - 大屏概览:统计教师和学生的使用情况,教学效率,学习效果等。 ### 项目结构调整建议 1. **在`com`包下新建包`ai`**,用于存放与大模型交互相关的代码。 - `service`: 大模型服务接口和实现。 - `controller`: 提供AI相关接口(如生成教学内容、题目等)。 - `utils`: 大模型调用工具类。 2. **知识库存储**: - 默认知识库:放在`resources/knowledge`目录下,项目启动时加载。 - 用户上传知识库:存储在服务器文件系统中(如`upload/knowledge`),并在数据库中记录知识库文件信息(可能需要新建实体和表)。 3. **教师侧功能**: - 在`controller`包下新建`TeacherAIController`,处理备课、生成题目等请求。 - 在`service`包下新建`TeacherAIService`,实现调用大模型生成教学内容和题目的逻辑。 4. **学生侧功能**: - 在`controller`包下新建`StudentAIController`,处理学生提问和练习评测请求。 - 在`service`包下新建`StudentAIService`,实现问题解答和练习评测逻辑。 5. **管理侧功能**: - 课件资源管理:在现有的`FileController`中增加对课件资源的管理,或新建`ResourceController`。 - 大屏概览:新建`DashboardController`,提供统计数据接口。 6. **数据库调整**: - 可能需要新增表来存储生成的教学内容、题目、答案、练习记录等。 - 例如:`teaching_content`, `exam_question`, `practice_record`等。 7. **前端调整**: - 在`resources/front/pages`下新增教师备课、学生练习等页面。 - 在管理后台的前端(`static/admin`)中添加课件资源管理和大屏概览的页面。 ### 代码示例 #### 1. 大模型服务接口 在`com.ai.service`包下创建`AIService`接口和实现类`AIServiceImpl`,用于封装大模型调用。 ```java package com.ai.service; public interface AIService { String generateTeachingContent(String knowledgeBase, String courseOutline); String generateExamQuestions(String knowledgeBase, int questionCount, boolean withAnswers); String answerQuestion(String question, String context); String generatePracticeExercise(String userId, String history); String evaluateAnswer(String answer, String correctAnswer); } ``` #### 2. 实现类(示例使用通义大模型,假设有对应的SDK) 这里假设我们使用HTTP API调用通义大模型,具体URL和参数需根据通义文档调整。 ```java package com.ai.service.impl; import com.ai.service.AIService; import com.utils.HttpClientUtils; import org.springframework.stereotype.Service; @Service public class AIServiceImpl implements AIService { private static final String TONGYI_API_URL = "https://api.tongyi.com/v1/chat/completions"; private static final String API_KEY = "your_api_key"; @Override public String generateTeachingContent(String knowledgeBase, String courseOutline) { String prompt = "根据以下知识库和课程大纲,设计教学内容:\n知识库:" + knowledgeBase + "\n课程大纲:" + courseOutline; return callTongyiAPI(prompt); } @Override public String generateExamQuestions(String knowledgeBase, int questionCount, boolean withAnswers) { String prompt = "根据以下知识库生成" + questionCount + "道题目" + (withAnswers ? "并附答案" : "") + ":\n" + knowledgeBase; return callTongyiAPI(prompt); } @Override public String answerQuestion(String question, String context) { String prompt = "问题:" + question + "\n上下文:" + context + "\n请回答:"; return callTongyiAPI(prompt); } @Override public String generatePracticeExercise(String userId, String history) { // 根据用户历史练习情况生成练习题 String prompt = "根据用户" + userId + "的练习历史:" + history + ",生成一道练习题"; return callTongyiAPI(prompt); } @Override public String evaluateAnswer(String answer, String correctAnswer) { String prompt = "判断学生答案是否正确,并给出解析。学生答案:" + answer + "\n参考答案:" + correctAnswer; return callTongyiAPI(prompt); } private String callTongyiAPI(String prompt) { // 构造请求体,这里以通义API为例,实际根据API文档调整 String requestBody = "{\"model\":\"qwen-turbo\",\"messages\":[{\"role\":\"user\",\"content\":\"" + prompt + "\"}]}"; Map<String, String> headers = new HashMap<>(); headers.put("Authorization", "Bearer " + API_KEY); headers.put("Content-Type", "application/json"); try { String response = HttpClientUtils.post(TONGYI_API_URL, requestBody, headers); // 解析响应,这里假设返回的JSON中choices[0].message.content是回答 // 实际解析需要根据通义API返回结构 JSONObject jsonResponse = new JSONObject(response); return jsonResponse.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content"); } catch (Exception e) { e.printStackTrace(); return "调用大模型失败"; } } } ``` #### 3. 教师侧控制器 在`com.controller`包下创建`TeacherAIController`: ```java package com.controller; import com.ai.service.AIService; import com.utils.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/ai/teacher") public class TeacherAIController { @Autowired private AIService aiService; @PostMapping("/generateContent") public R generateContent(String courseOutline) { // 从默认知识库或用户上传的知识库中读取内容(这里简化,实际需要从数据库或文件中读取) String knowledgeBase = "从知识库中读取的内容"; String content = aiService.generateTeachingContent(knowledgeBase, courseOutline); return R.ok().put("content", content); } @PostMapping("/generateExam") public R generateExam(int questionCount, boolean withAnswers) { String knowledgeBase = "从知识库中读取的内容"; String exam = aiService.generateExamQuestions(knowledgeBase, questionCount, withAnswers); return R.ok().put("exam", exam); } } ``` #### 4. 学生侧控制器 在`com.controller`包下创建`StudentAIController`: ```java package com.controller; import com.ai.service.AIService; import com.utils.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/ai/student") public class StudentAIController { @Autowired private AIService aiService; @PostMapping("/ask") public R askQuestion(String question) { // 结合当前课程的知识库内容作为上下文 String context = "相关知识点上下文"; String answer = aiService.answerQuestion(question, context); return R.ok().put("answer", answer); } @PostMapping("/generatePractice") public R generatePractice(String userId) { // 获取用户历史练习记录 String history = "用户历史练习记录"; String exercise = aiService.generatePracticeExercise(userId, history); return R.ok().put("exercise", exercise); } @PostMapping("/evaluate") public R evaluateAnswer(String answer, String correctAnswer) { String result = aiService.evaluateAnswer(answer, correctAnswer); return R.ok().put("result", result); } } ``` #### 5. 知识库管理 在`FileController`中增加知识库上传接口,或新建`KnowledgeBaseController`。 ```java // 在FileController中添加 @PostMapping("/uploadKnowledge") public R uploadKnowledge(@RequestParam("file") MultipartFile file) throws IOException { // 保存知识库文件到指定目录,如upload/knowledge // 记录到数据库,关联用户 return R.ok(); } ``` ### 数据库表设计建议 1. **知识库表(knowledge_base)**: - id, user_id, file_name, file_path, create_time 2. **教学内容表(teaching_content)**: - id, teacher_id, title, content, create_time 3. **题目表(exam_question)**: - id, content_id, question, answer, options (如果是选择题), type (题型), difficulty 4. **练习记录表(practice_record)**: - id, student_id, question_id, answer, is_correct, feedback, time ### 前端调整 - 教师备课页面:调用`/ai/teacher/generateContent`生成内容,并提供下载按钮(可生成Word或PDF)。 - 题目生成页面:调用`/ai/teacher/generateExam`生成题目,提供下载(带答案和不带答案)。 - 学生提问页面:调用`/ai/student/ask`获取答案。 - 练习页面:调用`/ai/student/generatePractice`生成练习,提交后调用`/ai/student/evaluate`进行批改。 ### 注意事项 1. **大模型选择**:通义大模型需要申请API Key,注意API调用频率和费用。 2. **本地知识库处理**:上传的知识库文件需要解析(如TXT、PDF、Word等),提取文本供大模型使用。可以使用Apache Tika等工具。 3. **性能考虑**:大模型调用可能较慢,考虑异步处理(如使用Spring的@Async)。 4. **安全性**:对上传的文件进行安全检查,防止恶意文件。 ### 项目结构变化 - 新增`ai`包,包含大模型相关代码。 - 新增控制器`TeacherAIController`和`StudentAIController`。 - 新增数据库表(需在entity包下新增实体,并创建Mapper和Service)。 - 前端新增页面。 ### 默认知识库放置 在`resources`目录下创建`knowledge`文件夹,存放默认知识库文件。在应用启动时,可以加载这些文件到内存或数据库。 ### 相关依赖 在`pom.xml`中添加HTTP客户端(如OkHttp或Apache HttpClient)和JSON处理库(如fastjson)。 ```xml <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.9.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.78</version> </dependency> ``` ### 总结 以上方案将大模型集成到现有项目中,实现了教师备课、题目生成,学生问答和练习评测等功能。同时,通过文件上传管理知识库,并提供下载功能。需要根据实际的大模型API调整调用方式,并完善前后端交互。 §§相关问题§§: 1. 如何解析上传的PDF、Word等格式的知识库文件? 2. 如何设计数据库表来存储生成的教学内容和题目? 3. 如何实现异步调用大模型API以避免阻塞请求? 4. 如何保证大模型生成的内容与知识库的关联性和准确性?</think>为了将开源通义大模型集成到您的项目中,并实现所需功能,以下是详细的解决方案和项目结构调整建议: ### 1. 本地知识库管理 **实现方案:** - 在`resources`目录下创建`knowledge-base`文件夹存放默认知识库 - 新增知识库管理模块(实体、DAO、Service、Controller) - 实现文件上传接口管理用户上传的知识库 **代码示例:** `KnowledgeBaseController.java`: ```java @RestController @RequestMapping("/knowledge") public class KnowledgeBaseController { @Autowired private KnowledgeService knowledgeService; // 上传知识库文件 @PostMapping("/upload") public R uploadKnowledge(@RequestParam("file") MultipartFile file) { return knowledgeService.uploadKnowledge(file); } // 获取知识库列表 @GetMapping("/list") public R listKnowledge() { return knowledgeService.getKnowledgeList(); } } ``` `KnowledgeService.java`: ```java @Service public class KnowledgeService { @Value("${knowledge.base.path}") private String basePath; public R uploadKnowledge(MultipartFile file) { // 文件大小校验(<100MB) if (file.getSize() > 100 * 1024 * 1024) { return R.error("文件大小不能超过100MB"); } // 保存文件到知识库目录 String fileName = FileUtil.saveFile(file, basePath); // 保存记录到数据库 KnowledgeEntity entity = new KnowledgeEntity(); entity.setFileName(fileName); entity.setOriginalName(file.getOriginalFilename()); knowledgeDao.insert(entity); return R.ok().put("path", fileName); } } ``` ### 2. 教师备课功能集成 **实现方案:** - 新增`AIController`处理AI相关请求 - 集成通义大模型SDK(如通义千问) - 实现教学内容生成接口 **代码示例:** `AIController.java`: ```java @RestController @RequestMapping("/ai") public class AIController { @Autowired private AIService aiService; // 生成教学内容 @PostMapping("/generate-teaching-plan") public R generateTeachingPlan(@RequestBody TeachingPlanRequest request) { TeachingContent content = aiService.generateTeachingContent( request.getCourseId(), request.getKnowledgeIds() ); return R.ok().put("data", content); } } ``` `AIServiceImpl.java`: ```java @Service public class AIServiceImpl implements AIService { @Autowired private KnowledgeDao knowledgeDao; @Override public TeachingContent generateTeachingContent(Long courseId, List<Long> knowledgeIds) { // 1. 获取知识库内容 List<String> knowledgeContents = knowledgeDao.getContentsByIds(knowledgeIds); String context = String.join("\n\n", knowledgeContents); // 2. 构造大模型提示词 String prompt = "你是一名专业教师,请根据以下课程大纲和知识库内容设计教学方案:\n" + context + "\n\n" + "要求包含:知识讲解框架、实训练习设计、时间分配建议(总课时90分钟)"; // 3. 调用通义大模型API String aiResponse = TongyiClient.generateText(prompt); // 4. 解析响应并生成结构化教学内容 return TeachingContentParser.parse(aiResponse); } } ``` ### 3. 考核内容生成 **实现方案:** - 新增题目生成接口 - 支持带答案/不带答案两种模式 - 实现题目下载功能(PDF/Word) **代码示例:** `AIController.java` 新增: ```java // 生成考核题目 @PostMapping("/generate-exam") public R generateExamQuestions(@RequestBody ExamRequest request) { ExamContent exam = aiService.generateExam( request.getCourseId(), request.getQuestionTypes(), request.isIncludeAnswers() ); return R.ok().put("data", exam); } // 下载题目(PDF) @GetMapping("/download-exam/{examId}") public void downloadExam(@PathVariable Long examId, HttpServletResponse response) { ExamContent exam = examService.getExamById(examId); PdfUtil.generateExamPdf(exam, response); } ``` ### 4. 项目结构调整 需要新增/修改的模块: ``` src/main/java/com/ ├── ai │ ├── controller │ │ └── AIController.java │ ├── service │ │ ├── AIService.java │ │ └── impl │ │ └── AIServiceImpl.java │ └── client │ └── TongyiClient.java ├── knowledge │ ├── entity │ │ └── KnowledgeEntity.java │ ├── dao │ │ └── KnowledgeDao.java │ └── service │ └── KnowledgeService.java └── teaching ├── entity │ ├── TeachingContent.java │ └── ExamContent.java └── util └── PdfUtil.java ``` ### 5. 配置文件修改 `application.yml` 新增配置: ```yaml tongyi: api-key: YOUR_API_KEY endpoint: https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation knowledge: base-path: classpath:knowledge-base/ max-size-mb: 100 ``` ### 6. 前端调整建议 1. 教师侧新增页面: - `resources/front/pages/teaching/ai-teaching-plan.html` 备课页面 - `resources/front/pages/exam/ai-exam-generator.html` 题目生成页面 2. 学生侧新增页面: - `resources/front/pages/learning/ai-assistant.html` 学习助手 - `resources/front/pages/practice/ai-practice.html` 智能练习 3. 管理侧新增: - `static/admin/src/views/modules/dashboard.vue` 教学数据大屏 - `static/admin/src/views/modules/knowledge` 知识库管理 ### 7. 通义大模型集成 **通义千问集成示例:** `TongyiClient.java`: ```java public class TongyiClient { private static final Logger logger = LoggerFactory.getLogger(TongyiClient.class); public static String generateText(String prompt) { OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json"); // 构造请求体 String json = "{\"model\":\"qwen-turbo\",\"input\":{\"messages\":[" + "{\"role\":\"system\",\"content\":\"你是一名专业助教\"}," + "{\"role\":\"user\",\"content\":\"" + prompt + "\"}]}}"; Request request = new Request.Builder() .url("https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation") .post(RequestBody.create(mediaType, json)) .addHeader("Authorization", "Bearer " + apiKey) .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); JSONObject jsonResponse = new JSONObject(response.body().string()); return jsonResponse.getJSONObject("output") .getJSONArray("choices") .getJSONObject(0) .getJSONObject("message") .getString("content"); } catch (Exception e) { logger.error("调用通义API失败", e); return "生成失败,请稍后重试"; } } } ``` ### 8. 非功能性需求实现 1. **知识库关联性验证**: ```java // 在生成题目后验证关联性 public void validateQuestionRelevance(Question question, List<Long> knowledgeIds) { List<String> knowledgePoints = knowledgeDao.getKeyPoints(knowledgeIds); String prompt = "请验证以下题目是否涉及这些知识点:\n知识点: " + String.join(",", knowledgePoints) + "\n题目: " + question.getContent(); String validation = TongyiClient.generateText(prompt); if (validation.contains("不相关")) { throw new ValidationException("生成题目与知识库关联性不足"); } } ``` 2. **教学效率指数计算**: ```sql -- 在DashboardController中使用的SQL SELECT AVG(TIMESTAMPDIFF(MINUTE, start_time, end_time)) AS avg_prep_time, SUM(CASE WHEN correctness < 60 THEN 1 ELSE 0 END) * 100.0 / COUNT(*) AS low_score_rate FROM teaching_sessions WHERE course_id = #{courseId} ``` ### 完整项目结构调整 ``` C:. ├── main │ ├── java │ │ └── com │ │ ├── ai │ │ ├── knowledge │ │ ├── teaching │ │ └── utils # 新增AI相关工具类 │ └── resources │ ├── knowledge-base # 知识库默认目录 │ ├── mapper │ │ └── KnowledgeDao.xml # 新增 │ └── templates │ └── exam-template.ftl # 考题模板 └── test └── java └── com └── ai └── AIServiceTest.java # 新增测试 ``` ### 关键注意事项 1. **知识库存储**: - 默认知识库:`resources/knowledge-base/` - 用户上传:存储在外部目录(如`/data/knowledge/`),避免打包时包含 2. **大模型调用优化**: - 使用异步调用避免阻塞:`@Async` - 实现结果缓存:`@Cacheable` - 添加限流保护:Resilience4j 3. **安全性**: - 知识库文件类型白名单(PDF/DOCX/TXT) - 文件内容病毒扫描 - API调用频率限制 4. **性能考虑**: - 大模型响应可能较慢(>5s),前端需要加载状态提示 - 大量知识库处理时分块调用API
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值