map.coffee

class Map
    constructor : -> 
        @entry = {}
        @count = 0
    
    size : -> 
        return @count
    
    isEmpty : -> 
        return @count == 0
    
    containsKey : (key) ->
        if @isEmpty()
            return false
        return @entry.hasOwnProperty key
    
    containsValue : (val)->
        if @isEmpty()
            return false
        for key,_val of @entry
            if _val == val
                return true
        return false
    
    get : (key)->
        if @isEmpty()
            return null
        if @containsKey key
            return @entry[key]     
        return null
    
    put : (key, val)->
        if !@entry.hasOwnProperty key
            @count += 1;  
        @entry[key] = val
        return @
    
    remove : (key)-> 
        if @isEmpty()
            return false
        if @containsKey key
            delete @entry[key]
            @count -= 1
            return true
        return false    
    
    putAll : (map)->  
        if !map instanceof Map
            return false
        entry = map.entry
        for key,val of entry
            @put(key, val)
        return true
    
    clear : ->
        @entry = {}
        @count = 0
        return @ 
    
    values : ->  
        vals = []
        for key,val of @entry
            vals.push val
        return vals
        
    keySet : ->  
        keys = []
        for key,val of @entry
            keys.push key
        return keys
    
    entrySet : ->  
        return @entry
    
    toString : ->  
        if typeof JSON == "undefined"
            throw new Error "JSON object is not supported. Please check your browser version (IE8+, Firefox11+, Chrome19+, Safari5.1+)."
        return JSON.stringify @entry
    
    valueOf : ->  
        return @toString()

package com.lwb.coffee.controller; import com.lwb.coffee.entity.PlantData; import com.lwb.coffee.service.PlantDataService; import com.lwb.coffee.utils.R; import org.springframework.ai.chat.messages.Message; import org.springframework.ai.chat.messages.SystemMessage; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.model.ChatResponse; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.chat.prompt.Prompt; import org.springframework.ai.zhipuai.ZhiPuAiChatModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; 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 org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @RestController public class ChatController { private static final Logger logger = LoggerFactory.getLogger(ChatController.class); private static final int MAX_ANALYSIS_RECORDS = 10; // 限制最大分析记录数 private final ZhiPuAiChatModel chatModel; private final PlantDataService plantDataService; private static final String SYSTEM_PROMPT = """ 你是一个专业的咖啡种植专家,请根据提供的咖啡种植环境数据进行分析,包括: 1. 环境参数是否适宜(温度、湿度、光照等) 2. 可能存在的问题 3. 改进建议 请用专业且易懂的语言回答。 """; @Autowired public ChatController(ZhiPuAiChatModel chatModel, PlantDataService plantDataService, @Qualifier("aiExecutorService") ExecutorService executorService) { this.chatModel = chatModel; this.plantDataService = plantDataService; } @GetMapping("/ai/generate") public Map generate(@RequestParam Map<String, Object> params) { R plantData = plantDataService.selectByAreaAndBatch(params); List<PlantData> dataList = (List<PlantData>) plantData.get("data"); return Map.of("generation", this.chatModel.call(dataList.toString())); } }
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值