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

网站框架怎么做网页赚钱

网站框架,怎么做网页赚钱,网页设计代做,境外 网站网站需求#xff1a; 使用java封装kimi接口为http接口#xff0c;并把调用kimi时的传参和返回数据#xff0c;保存到mysql数据库中 自己记录一下#xff0c;以做备忘。 具体步骤如下#xff1a; 1.申请apiKey 访问#xff1a;Moonshot AI - 开放平台使用手机号手机号验证…需求 使用java封装kimi接口为http接口并把调用kimi时的传参和返回数据保存到mysql数据库中 自己记录一下以做备忘。 具体步骤如下 1.申请apiKey 访问Moonshot AI - 开放平台使用手机号手机号验证码登录 登录后在如下界面申请 最多可以保留 5 个 API 密钥密钥只会在新建后显示一次请妥善保存。不要与他人共享 API Key或将其暴露在客户端代码中。为了账户安全一旦 API 密钥被发现泄露Moonshot AI 可能会将其禁用。 默认token数量如下 2.编写Java代码对接kimi 2.1对接kimi日志表 CREATE TABLE ai_api_log (id int(11) NOT NULL AUTO_INCREMENT COMMENT 主键,api_key varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT app_key,api_ip varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT API调用外网IP,api_method varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT API方法,api_para text COLLATE utf8mb4_unicode_ci COMMENT API参数,api_result text COLLATE utf8mb4_unicode_ci COMMENT API返回消息,create_time datetime DEFAULT NULL COMMENT 创建时间 ,PRIMARY KEY (id),KEY open_api_log_creat_time (create_time),KEY open_api_log_method (api_method),KEY open_api_log_app_key (api_key) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_unicode_ci COMMENTapi日志表对应的实体类 package com.example.ai.domain;import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode;import java.util.Date; Data EqualsAndHashCode(callSuper true) TableName(ai_api_log) public class AIApiLog extends BaseEntity {private static final long serialVersionUID1L;public static String METHOD_KIMI_CHATkimi_chat;private Integer id;private String apiKey;private String apiIp;private String apiMethod;private String apiPara;private String apiResult;private Date createTime;}2.2对接kimi核心代码 package com.example.ai.service;import cn.hutool.core.util.StrUtil; import cn.hutool.http.ContentType; import cn.hutool.json.JSONObject; import com.example.ai.config.AiConfig; import com.example.ai.constant.PathConstant; import com.example.ai.network.ChatMessage; import com.example.ai.util.JsonUtil; import com.example.ai.network.ChoicesInfo; import com.example.ai.network.HttpResponse; import com.example.ai.network.ResponseType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.*; import org.apache.commons.lang3.StringEscapeUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux;import javax.annotation.PostConstruct; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit;/*** date 2023/2/13**/ Service public class AiKimiService {AutowiredAiConfig aiConfig;AutowiredAIApiLogService aIApiLogService;//webflux的clientprivate WebClient webClient;//用于读取第三方的返回结果private ObjectMapper objectMapper new ObjectMapper();public String completions( String content)throws IOException{HttpResponse response this.getJsonResponse(content);ChoicesInfo choicesInfo response.getChoices().get(0);return StringEscapeUtils.unescapeJava(choicesInfo.getMessage().getContent());}public HttpResponse getJsonResponse(String message) throws IOException {ListChatMessage messagesnew ArrayList();ChatMessage chatMessagenew ChatMessage();chatMessage.setRole(user);chatMessage.setContent(message);messages.add(chatMessage);String requestBody new JSONObject().putOpt(model, moonshot-v1-8k).putOpt(messages, messages).putOpt(response_format,new ResponseType()).putOpt(frequency_penalty,0.5).putOpt(stream, false).toString();Request okhttpRequest new Request.Builder().url(aiConfig.getBaseUrl() PathConstant.COMPLETIONS.CREATE_CHAT_COMPLETION).post(RequestBody.create(requestBody, okhttp3.MediaType.get(ContentType.JSON.getValue()))).addHeader(Authorization, Bearer aiConfig.getApiKey()).build();OkHttpClient okHttpClient new OkHttpClient.Builder().connectTimeout(20, TimeUnit.SECONDS).readTimeout(60,TimeUnit.SECONDS).writeTimeout(60,TimeUnit.SECONDS).build();Call call okHttpClient.newCall(okhttpRequest);Response okhttpResponse call.execute();String json okhttpResponse.body().string();aIApiLogService.saveOrUpdate(requestBody,json);System.out.println(new SimpleDateFormat(yyyy-MM-dd HH:mm:ss).format(new Date())----json);return JsonUtil.jsonToClass(json,HttpResponse.class);}PostConstructpublic void postConstruct() {this.webClient WebClient.builder()//创建webflux的client.baseUrl(aiConfig.getBaseUrl())//填写对应的api地址.defaultHeader(Content-Type, application/json)//设置默认请求类型.build();}private FluxHttpResponse handleWebClientResponse(String resp) {if (StrUtil.equals([DONE],resp)){//[DONE]是消息结束标识return Flux.empty();}try {JsonNode jsonNode objectMapper.readTree(resp);HttpResponse result objectMapper.treeToValue(jsonNode, HttpResponse.class);//将获得的结果转成对象return Flux.just(result);//返回获得的结果} catch (Exception e) {throw new RuntimeException(e.getMessage());}} }2.3运行效果 3.完整项目源码 下载地址 Java对接kimi完整项目源码
http://www.w-s-a.com/news/259109/

相关文章:

  • 推广网站怎么建经济研究院网站建设方案
  • 网站建设商家淘宝客自建网站做还是用微信qq做
  • django做网站效率高吗涉县移动网站建设报价
  • 做外贸网站注册什么邮箱能够做渗透的网站
  • 购物网站 怎么做织梦网站会员功能
  • 北京市网站开发公司郑州联通网站备案
  • 温岭专业营销型网站建设地址wordpress小程序怎么不用认证审核
  • 网站建设主体设计要求微信公众号缴费
  • 网站建设的税率WordPress多用户建站
  • 专业门户网站的规划与建设网络培训
  • 东莞汽车总站停止营业crm管理系统在线使用
  • 深圳网站建设公司哪个网络优化是做什么的
  • 大连地区做网站自己怎么做电影网站
  • 成都APP,微网站开发手机要访问国外网站如何做
  • 网站app建设用discuz做的手机网站
  • vs 2008网站做安装包公众号登录超时
  • 银川做网站推广wordpress dux会员中心
  • 双辽做网站wordpress怎么写html代码
  • 建站公司哪家好 知道万维科技西安都有哪些公司
  • 设计网站官网入口佛山 品牌设计
  • 专用网站建设wordpress mega
  • 网站建设与优化推广方案内容网站整站下载带数据库后台的方法
  • 做网站PAAS系统外链是什么意思
  • 网页设计专业设计课程googleseo排名公司
  • 网站百度百科那些免费网站可以做国外贸易
  • 做视频的网站有哪些南京计算机培训机构哪个最好
  • ppt做视频 模板下载网站商业街网站建设方案
  • 佛山网站定制开发星光影视园网站建设案例
  • wordpress子站点商务网页设计与制作微课版答案
  • 山东省住房城乡和建设厅网站软件开发主要几个步骤