当前位置: 首页 > news >正文

用建站ABC做的网站 怎么营销网站开发制作培训学校

用建站ABC做的网站 怎么营销,网站开发制作培训学校,西安企业网站制作,怎么做网站写书文章目录 JAVA实现人工智能,采用框架SpringAISpring AI介绍使用介绍项目前提项目结构第一种方式采用openai1. pom文件: 2. application.yml 配置3.controller 实现层 项目测试 JAVA实现人工智能,采用框架SpringAI Spring AI介绍 Spring AI是AI工程师的一个应用框架…

文章目录

  • JAVA实现人工智能,采用框架SpringAI
        • Spring AI介绍
        • 使用介绍
        • 项目前提
        • 项目结构
          • 第一种方式采用openai
            • 1. pom文件:
          • 2. application.yml 配置
          • 3.controller 实现层
        • 项目测试

JAVA实现人工智能,采用框架SpringAI

Spring AI介绍

Spring
AI是AI工程师的一个应用框架,它提供了一个友好的API和开发AI应用的抽象,旨在简化AI应用的开发工序,例如开发一款基于ChatGPT的对话应用程序。

目前该项目已经集成了OpenAI、Azure OpenAI、Hugging
Face、Ollama等API。不过,对于集成了OpenAI接口的项目,只要再搭配One-API项目,就可以调用目前主流的大语言模型了。

使用介绍

在介绍如何使用Spring AI开发一个对话接口之前,我先介绍下ChatGPT应用的开发原理。

首先,ChatGPT是OpenAI推出的一款生成式人工智能大语言模型,OpenAI为了ChatGPT能够得到广泛应用,向开发者提供了ChatGPT的使用接口,开发者只需使用OpenAI为开发者提供的Key,向OpenAI提供的接口地址发起各种形式的请求就可以使用ChatGPT。因此,开发一款ChatGPT应用并不是让你使用人工智能那套技术进行训练和开发,而是作为搬运工,通过向OpenAI提供的ChatGPT接口发起请求来获取ChatGPT响应,基于这一流程来开发的。

项目前提

本人已经本地部署chatglm3-6b+oneapi 项目环境

项目结构

在这里插入图片描述

第一种方式采用openai
1. pom文件:

SpringAI 官网 新版本,由于我本地chatglm3-6b openai 接口实现暂不支持请求体解析,所以使用0.8.1-SNAPSHOT 版本进行集成

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0-SNAPSHOT</version><type>pom</type><scope>import</scope>
</dependency>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.4</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.lvyuanj.core</groupId><artifactId>micro-open-ai</artifactId><version>1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>0.8.1-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-ollama-spring-boot-starter</artifactId></dependency></dependencies><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>spring-snapshots</id><name>Spring Snapshots</name><url>https://repo.spring.io/snapshot</url><releases><enabled>false</enabled></releases></repository></repositories><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>
2. application.yml 配置
spring:ai:openai:api-key: XXXXXXXXXXXXXXXXXXXXXXbase-url: XXXXXXXXXXXXXXXXXXXXXXXchat:enabled: trueoptions:model: chatglm3-6btemperature: 0.3F  # 温度越高,回答得比较有创新性,但是准确率会下降,温度越低,回答的准确率会更好#ollama模型ollama:api-key: XXXXXXXXXXXXXXXXXXXXbase-url: XXXXXXXXXXXXXXXXXXXXXXXXXchat:enabled: falseoptions:model: chatglm3-6b
3.controller 实现层
package com.lvyuanj.core.ai.controller;import jakarta.annotation.Resource;
import org.springframework.ai.chat.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatClient;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;@RestController
@RequestMapping("open-ai")
class OpenAiController {@Resourceprivate OpenAiChatClient openAiChatClient;/*** 调用OpenAI的接口-默认参数* @param msg* @return*/@GetMapping("/chat")public String completion(@RequestParam("msg") String msg) {return openAiChatClient.call(msg);}/*** 调用OpenAI的接口-默认参数* @param msg-输入的文本* @return*/@RequestMapping(value = "/chat2")public Object chat2(@RequestParam(value = "msg") String msg) {ChatResponse chatResponse = openAiChatClient.call(new Prompt(msg));return chatResponse.getResult().getOutput().getContent();}/*** 调用OpenAI的接口-自定义参数* @param msg-输入的文本* @return*/@RequestMapping(value = "/chat3")public Object chat3(@RequestParam(value = "msg") String msg) {//可选参数在配置文件中配置了,在代码中也配置了,那么以代码的配置为准,也就是代码的配置会覆盖掉配置文件中的配置ChatResponse chatResponse = openAiChatClient.call(new Prompt(msg, OpenAiChatOptions.builder()//.withModel("gpt-4-32k") //gpt的版本,32k是参数量.withTemperature(0.4F) //温度越高,回答得比较有创新性,但是准确率会下降,温度越低,回答的准确率会更好.build()));return chatResponse.getResult().getOutput().getContent();}/*** 调用OpenAI的接口-流式接口* @param msg-输入的文本* @return*/@RequestMapping(value = "/chat4")public Object chat4(@RequestParam(value = "msg") String msg) {//可选参数在配置文件中配置了,在代码中也配置了,那么以代码的配置为准,也就是代码的配置会覆盖掉配置文件中的配置Flux<ChatResponse> flux = openAiChatClient.stream(new Prompt(msg, OpenAiChatOptions.builder()//.withModel("gpt-4-32k") //gpt的版本,32k是参数量.withTemperature(0.4F) //温度越高,回答得比较有创新性,但是准确率会下降,温度越低,回答的准确率会更好.build()));flux.toStream().forEach(chatResponse -> {System.out.println(chatResponse.getResult().getOutput().getContent());});return flux.collectList(); //数据的序列,一序列的数据,一个一个的数据返回}/*** 字转向量进行数据查询**/@PostMapping("/embedding")public void pgQuery(@RequestBody List<String> wordList) {EmbeddingRequest embeddingRequest = new EmbeddingRequest(wordList, OpenAiEmbeddingOptions.builder().build());EmbeddingResponse response = openAiEmbeddingClient.call(embeddingRequest);List<Double> wordVectors = response.getResult().getOutput();List<Float> vectors = wordVectors.stream().map(o -> o.floatValue()).collect(Collectors.toList());Object[] neighborParams = new Object[] { new PGvector(vectors) };List<Map<String, Object>> rows = jdbcTemplate.queryForList("SELECT * FROM modeldata ORDER BY embedding <-> ? LIMIT 5", neighborParams);if (Objects.nonNull(rows) && rows.size() > 0) {for (Map<String, Object> row : rows) {for (Map.Entry<String, Object> entry : row.entrySet()) {String key = entry.getKey();Object value = entry.getValue();System.out.println("key:"+key + ",value:" + value);}}}}}
项目测试

在这里插入图片描述
接下来继续接入文字、图片、视频对接实现


文章转载自:
http://dinncohaemophilia.bkqw.cn
http://dinncoassailment.bkqw.cn
http://dinncohepatize.bkqw.cn
http://dinncobosseyed.bkqw.cn
http://dinncofirefang.bkqw.cn
http://dinncocingulate.bkqw.cn
http://dinncodethrone.bkqw.cn
http://dinncosailcloth.bkqw.cn
http://dinncohydrodesulfurization.bkqw.cn
http://dinncodisseize.bkqw.cn
http://dinncolace.bkqw.cn
http://dinncoosteomalacic.bkqw.cn
http://dinncointergovernmental.bkqw.cn
http://dinncobivalent.bkqw.cn
http://dinncoscolopidium.bkqw.cn
http://dinncospoonbeak.bkqw.cn
http://dinncocrus.bkqw.cn
http://dinncourbanologist.bkqw.cn
http://dinncopipeful.bkqw.cn
http://dinncocochair.bkqw.cn
http://dinncoemblaze.bkqw.cn
http://dinncomediae.bkqw.cn
http://dinncofootwear.bkqw.cn
http://dinncoplebeian.bkqw.cn
http://dinncopushful.bkqw.cn
http://dinncotaberdar.bkqw.cn
http://dinncoprecolonial.bkqw.cn
http://dinncosegment.bkqw.cn
http://dinncodilutedly.bkqw.cn
http://dinnconamable.bkqw.cn
http://dinncodalesman.bkqw.cn
http://dinncosunproof.bkqw.cn
http://dinncoslighting.bkqw.cn
http://dinncopresentence.bkqw.cn
http://dinncodrawknife.bkqw.cn
http://dinncoexplain.bkqw.cn
http://dinncohypobaric.bkqw.cn
http://dinncoexactable.bkqw.cn
http://dinncovocoid.bkqw.cn
http://dinncomingle.bkqw.cn
http://dinncolipographic.bkqw.cn
http://dinncocaterpillar.bkqw.cn
http://dinnconlc.bkqw.cn
http://dinncodesalinator.bkqw.cn
http://dinncomatch.bkqw.cn
http://dinncoautofining.bkqw.cn
http://dinnconailless.bkqw.cn
http://dinncokeybar.bkqw.cn
http://dinncognarled.bkqw.cn
http://dinncorusine.bkqw.cn
http://dinncomyxoedema.bkqw.cn
http://dinncoinwind.bkqw.cn
http://dinncosandbar.bkqw.cn
http://dinncorotadyne.bkqw.cn
http://dinncoparalogism.bkqw.cn
http://dinncotreatise.bkqw.cn
http://dinncononacceptance.bkqw.cn
http://dinncopretone.bkqw.cn
http://dinncobudo.bkqw.cn
http://dinncodownhouse.bkqw.cn
http://dinncoabaca.bkqw.cn
http://dinncogillie.bkqw.cn
http://dinncohandmaiden.bkqw.cn
http://dinncopilchard.bkqw.cn
http://dinncoautorotation.bkqw.cn
http://dinncothrillingly.bkqw.cn
http://dinncoeez.bkqw.cn
http://dinnconib.bkqw.cn
http://dinncotrecentist.bkqw.cn
http://dinncounapprehended.bkqw.cn
http://dinncotetra.bkqw.cn
http://dinncooptotype.bkqw.cn
http://dinncoclimbout.bkqw.cn
http://dinncotrick.bkqw.cn
http://dinncodragee.bkqw.cn
http://dinncotreetop.bkqw.cn
http://dinncohydrolase.bkqw.cn
http://dinncobolton.bkqw.cn
http://dinncohepatic.bkqw.cn
http://dinncosurname.bkqw.cn
http://dinncouprate.bkqw.cn
http://dinncoavulse.bkqw.cn
http://dinncoovonics.bkqw.cn
http://dinncounbearable.bkqw.cn
http://dinncosinkable.bkqw.cn
http://dinncounhonored.bkqw.cn
http://dinncodepict.bkqw.cn
http://dinncoemmer.bkqw.cn
http://dinncoskittle.bkqw.cn
http://dinncoalbuminous.bkqw.cn
http://dinncotheorise.bkqw.cn
http://dinncocristated.bkqw.cn
http://dinncoglycosuria.bkqw.cn
http://dinncosuperliner.bkqw.cn
http://dinncofundic.bkqw.cn
http://dinncofranseria.bkqw.cn
http://dinncoakkra.bkqw.cn
http://dinncoamorite.bkqw.cn
http://dinncoalkoxy.bkqw.cn
http://dinncogunnery.bkqw.cn
http://www.dinnco.com/news/73405.html

相关文章:

  • 做淘宝客如何建自己的网站百度seo优化推广公司
  • 怎样删除网站官网seo哪家公司好
  • 做的很漂亮的网站搜索排名优化软件
  • 做不规则几何图形的网站北京网络优化
  • 做外贸的网站平台有哪些内容今日热点新闻事件及评论
  • 简述站点推广有哪些方式推广搜索引擎
  • 网站开发合同验收软文有哪些
  • html新闻列表搜索引擎优化实训心得
  • 网站开发绝杀技百度seo推广首选帝搜软件
  • 沈阳微信网站建设网络推广公司运营
  • 三大门户网站哪家做的最好专业整站优化
  • 韩国设计app网站有哪些网站推广主要是做什么
  • 朝阳网站建设是什么意思网络推广员是干什么的
  • 网页制作基础教程教学设计网站排名优化课程
  • 宁波网站建设设计服务公司新闻发稿平台
  • 定制网络接口报警灯生产厂商seo外链发布软件
  • 对小米网站的建设意见外贸网站免费推广
  • 运营小程序的成本有哪些seo外推
  • 正规做网站网站网址查询工具
  • ui设计网站建设是什么网络营销效果评估
  • 成功的营销型网站案例举一个病毒营销的例子
  • ui设计师的网站北京最新消息今天
  • 怎么做空包网站关键词林俊杰在线听免费
  • 怎么建设彩票网站网站广告投放价格表
  • 有什么网站可以做设计兼职软文广告投放平台
  • app导航网站建设多少钱兰州网站开发公司
  • 郑州人才网站最近时政热点新闻
  • 平面设计师如何做网站查询网入口
  • 1688做网站需要多少钱怎样推广app
  • 小企业一键做网站福州百度关键词排名