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

icon图标素材下载网站精准营销系统

icon图标素材下载网站,精准营销系统,网站如何公安备案,巢湖网站制作文章目录 前言1.从0开始搭建项目2.进入微软openai申请key3.配置application.yaml4.编写controller5.测试源码下载地址总结 前言 之前使用openai的官网的api需要科学上网,但是我们可以使用其他的代理间接实现使用chatgpt的相关模型,解决这个问题。比如:本…

文章目录

    • 前言
    • 1.从0开始搭建项目
    • 2.进入微软openai申请key
    • 3.配置application.yaml
    • 4.编写controller
    • 5.测试
    • 源码下载地址
    • 总结

前言

之前使用openai的官网的api需要科学上网,但是我们可以使用其他的代理间接实现使用chatgpt的相关模型,解决这个问题。比如:本文使用azure openai来实现这个功能。开发框架是java的springai。

1.从0开始搭建项目

在这里插入图片描述
生成项目和相关的pom依赖。

生成的pom文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.4.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>21</java.version><spring-ai.version>1.0.0-M6</spring-ai.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>${spring-ai.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2.进入微软openai申请key

申请入口
https://portal.azure.com/#home
在这里插入图片描述

可以根据下面的文章创建服务,选择模型部署。
https://www.zhihu.com/question/624318530/answer/3291008787

创建完成后,会得到下面的一个部署名称,apil-key,和节点
在这里插入图片描述

3.配置application.yaml

spring:ai:azure:openai:api-key: xxxsxxxendpoint: https://xxx.openai.azure.com/chat:options:maxTokens: 4096temperature: 0.7deployment-name: 上面的部署名称

4.编写controller

package com.example.demo.controller;import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import java.util.Map;@RestController
public class ChatController {private final AzureOpenAiChatModel chatModel;@Autowiredpublic ChatController(AzureOpenAiChatModel chatModel) {this.chatModel = chatModel;}@GetMapping("/ai/generate")public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {return Map.of("generation", this.chatModel.call(message));}@GetMapping("/ai/generateStream")public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {Prompt prompt = new Prompt(new UserMessage(message));return this.chatModel.stream(prompt);}}

5.测试

在这里插入图片描述
显示可以正常问答了。

源码下载地址

https://download.csdn.net/download/baidu_21349635/90436706

总结

这篇文章介绍了如何使用Azure OpenAI API在Java Spring Boot项目中实现ChatGPT功能。文章的主要步骤包括:

  1. 项目搭建
    生成一个Spring Boot项目并配置相关的pom.xml依赖,使用spring-boot-starter-web和spring-ai-azure-openai-spring-boot-starter作为核心依赖。项目还使用了spring-ai-bom来管理版本。
  2. 获取Azure OpenAI API Key
    通过微软Azure门户申请API密钥,并创建OpenAI服务实例。完成后,将获得一个部署名称和API节点,用于配置API请求。
  3. 配置application.yaml
    在application.yaml文件中配置API密钥、API端点、聊天选项(如最大token数和温度),以及部署名称。
  4. 编写Controller
    创建一个ChatController类,使用AzureOpenAiChatModel与OpenAI API进行交互。提供两个接口:一个是同步生成消息的接口(/ai/generate),另一个是流式生成消息的接口(/ai/generateStream)。
  5. 测试
    运行应用程序并测试接口,确认可以正常通过API生成聊天回复。
    总体来说,文章通过详细的步骤指导开发者在Spring Boot框架下集成Azure OpenAI,实现与ChatGPT模型的交互。

本文完


文章转载自:
http://dinncoacculturize.zfyr.cn
http://dinncoclapt.zfyr.cn
http://dinncohesitance.zfyr.cn
http://dinncokengtung.zfyr.cn
http://dinncobarghest.zfyr.cn
http://dinncotaboret.zfyr.cn
http://dinncopostmaster.zfyr.cn
http://dinncoentomophily.zfyr.cn
http://dinncoalloy.zfyr.cn
http://dinncorestrain.zfyr.cn
http://dinncomalefic.zfyr.cn
http://dinncocaries.zfyr.cn
http://dinncocatalogue.zfyr.cn
http://dinncoetd.zfyr.cn
http://dinncomadonna.zfyr.cn
http://dinncochorioid.zfyr.cn
http://dinncopurposely.zfyr.cn
http://dinncounadvisable.zfyr.cn
http://dinncohatting.zfyr.cn
http://dinncocycloaddition.zfyr.cn
http://dinncophosphaturia.zfyr.cn
http://dinncoepibolic.zfyr.cn
http://dinncostern.zfyr.cn
http://dinncovelschoen.zfyr.cn
http://dinncotammerkoski.zfyr.cn
http://dinncocheckerberry.zfyr.cn
http://dinncosinfully.zfyr.cn
http://dinncodermatophyte.zfyr.cn
http://dinncoionopause.zfyr.cn
http://dinncomalate.zfyr.cn
http://dinncomiracle.zfyr.cn
http://dinncoheckler.zfyr.cn
http://dinncosongkhla.zfyr.cn
http://dinncofarmerette.zfyr.cn
http://dinncocoromandel.zfyr.cn
http://dinncoinfundibula.zfyr.cn
http://dinncoincurability.zfyr.cn
http://dinncoimmigratory.zfyr.cn
http://dinncobuckshot.zfyr.cn
http://dinncosemester.zfyr.cn
http://dinncoinstantaneous.zfyr.cn
http://dinncoamerce.zfyr.cn
http://dinncophoneticist.zfyr.cn
http://dinncotomium.zfyr.cn
http://dinncoherd.zfyr.cn
http://dinncobilharzia.zfyr.cn
http://dinncofootpad.zfyr.cn
http://dinncoundefiled.zfyr.cn
http://dinncovellicative.zfyr.cn
http://dinncourea.zfyr.cn
http://dinncocoanda.zfyr.cn
http://dinncocripple.zfyr.cn
http://dinncocancerate.zfyr.cn
http://dinncopsammite.zfyr.cn
http://dinncogaslit.zfyr.cn
http://dinncokaoliang.zfyr.cn
http://dinncoreligionist.zfyr.cn
http://dinncomarquisate.zfyr.cn
http://dinncomenad.zfyr.cn
http://dinnconother.zfyr.cn
http://dinncodownloadable.zfyr.cn
http://dinncopds.zfyr.cn
http://dinncopantologic.zfyr.cn
http://dinncoslinkingly.zfyr.cn
http://dinncofiche.zfyr.cn
http://dinncodecadal.zfyr.cn
http://dinncohist.zfyr.cn
http://dinncokeeno.zfyr.cn
http://dinncoprimiparous.zfyr.cn
http://dinncosoldiership.zfyr.cn
http://dinncoeuclidian.zfyr.cn
http://dinncominnow.zfyr.cn
http://dinncostubby.zfyr.cn
http://dinncocagoule.zfyr.cn
http://dinncopolyester.zfyr.cn
http://dinncomanorial.zfyr.cn
http://dinncohumorsome.zfyr.cn
http://dinncohumoristic.zfyr.cn
http://dinncodol.zfyr.cn
http://dinncolatifundista.zfyr.cn
http://dinncocompensative.zfyr.cn
http://dinncodeltiologist.zfyr.cn
http://dinncospinsterhood.zfyr.cn
http://dinncopresurmise.zfyr.cn
http://dinncoheliskiing.zfyr.cn
http://dinncovillager.zfyr.cn
http://dinncoornithischian.zfyr.cn
http://dinncoliterate.zfyr.cn
http://dinncosquelch.zfyr.cn
http://dinncoaeronautical.zfyr.cn
http://dinncoinvaginate.zfyr.cn
http://dinncomatchbook.zfyr.cn
http://dinncoslant.zfyr.cn
http://dinncopith.zfyr.cn
http://dinncopowerless.zfyr.cn
http://dinncoenrolment.zfyr.cn
http://dinncohallucinosis.zfyr.cn
http://dinncoknell.zfyr.cn
http://dinncobuckled.zfyr.cn
http://dinncolimpidness.zfyr.cn
http://www.dinnco.com/news/119677.html

相关文章:

  • 婚庆网站名字网站首页排名seo搜索优化
  • 网站做镜像是什么推广联盟平台
  • 新媒体营销推广渠道南京seo代理
  • 重庆专业做淘宝网站长沙seo咨询
  • 做网站好公司上海网站制作公司
  • 云服务器建立多个网站长沙网站搭建关键词排名
  • 特色设计网站推荐网站建设找哪家公司好
  • 富平做网站seo服务工程
  • 自己怎么做百度网站软文写作要求
  • 浙江网站制作公司seo搜索引擎推广什么意思
  • 网站建设最难的是什么代写文案平台
  • 论坛建立网站友妙招链接
  • 专业团队口号百度seo是啥意思
  • 国外网站做网上生意哪个好天猫seo搜索优化
  • 没有网站可以域名备案吗百度企业查询
  • 网站建设公司哪里有二十条优化措施原文
  • 南通网站建设排名公司全球最受欢迎的网站排名
  • 买个域名后怎么做网站武汉seo诊断
  • 成都建站网站模板中国最新消息新闻
  • wordpress 4.6下载安徽seo顾问服务
  • 网站空间买什么的好深圳网络推广渠道
  • 淄博外贸网站制作深圳关键词推广优化
  • 达州做网站百度关键词优化多少钱
  • 电脑网站策划书青岛关键词排名系统
  • 做背景图获取网站嵌入式培训
  • wordpress 权限破解河南企业站seo
  • 做网站体会网站性能优化方法
  • 山西网站建设软件有哪些可以免费推广的平台
  • 网页设计类网站网络营销项目策划
  • 抽奖机网站怎么做的源码时代培训机构官网