Spring AI默认gpt版本源码探究

Spring AI默认gpt版本源码探究

调试代码

  • 通过调试,可以看到默认mdel为gpt-3.5-turbo
    在这里插入图片描述

源码探究

  1. 进入OpenAiChatClient类查看具体的代码信息
    在这里插入图片描述
  2. 可以看到如下代码,在有参构造方法中可以看到,model默认使用OpenAiApi.DEFAULT_CHAT_MODEL
    public class OpenAiChatClient extends AbstractFunctionCallSupport<OpenAiApi.ChatCompletionMessage, OpenAiApi.ChatCompletionRequest, ResponseEntity<OpenAiApi.ChatCompletion>> implements ChatClient, StreamingChatClient {
        private static final Logger logger = LoggerFactory.getLogger(OpenAiChatClient.class);
        private OpenAiChatOptions defaultOptions;
        public final RetryTemplate retryTemplate;
        private final OpenAiApi openAiApi;
    
        public OpenAiChatClient(OpenAiApi openAiApi) {
            this(openAiApi, OpenAiChatOptions.builder().withModel(OpenAiApi.DEFAULT_CHAT_MODEL).withTemperature(0.7F).build());
        }
    }    
    

在这里插入图片描述

  1. 继续进入OpenAiApi类查看DEFAULT_CHAT_MODEL的具体信息,可以看到使用枚举类ChatModel为DEFAULT_CHAT_MODEL赋值
    在这里插入图片描述
  2. 点击查看ChatModel的具体内容,可以看到这里列举了常用的gpt版本
public enum ChatModel {
		/**
		 * (New) GPT-4 Turbo - latest GPT-4 model intended to reduce cases
		 * of “laziness” where the model doesn’t complete a task.
		 * Returns a maximum of 4,096 output tokens.
		 * Context window: 128k tokens
		 */
		GPT_4_0125_PREVIEW("gpt-4-0125-preview"),

		/**
		 * Currently points to gpt-4-0125-preview - model featuring improved
		 * instruction following, JSON mode, reproducible outputs,
		 * parallel function calling, and more.
		 * Returns a maximum of 4,096 output tokens
		 * Context window: 128k tokens
		 */
		GPT_4_TURBO_PREVIEW("gpt-4-turbo-preview"),

		/**
		 * GPT-4 with the ability to understand images, in addition
		 * to all other GPT-4 Turbo capabilities. Currently points
		 * to gpt-4-1106-vision-preview.
		 * Returns a maximum of 4,096 output tokens
		 * Context window: 128k tokens
		 */
		GPT_4_VISION_PREVIEW("gpt-4-vision-preview"),

		/**
		 * Currently points to gpt-4-0613.
		 * Snapshot of gpt-4 from June 13th 2023 with improved
		 * function calling support.
		 * Context window: 8k tokens
		 */
		GPT_4("gpt-4"),

		/**
		 * Currently points to gpt-4-32k-0613.
		 * Snapshot of gpt-4-32k from June 13th 2023 with improved
		 * function calling support.
		 * Context window: 32k tokens
		 */
		GPT_4_32K("gpt-4-32k"),

		/**
		 *Currently points to gpt-3.5-turbo-0125.
		 * model with higher accuracy at responding in requested
		 * formats and a fix for a bug which caused a text
		 * encoding issue for non-English language function calls.
		 * Returns a maximum of 4,096
		 * Context window: 16k tokens
		 */
		GPT_3_5_TURBO("gpt-3.5-turbo"),

		/**
		 * (new) The latest GPT-3.5 Turbo model with higher accuracy
		 * at responding in requested formats and a fix for a bug
		 * which caused a text encoding issue for non-English
		 * language function calls.
		 * Returns a maximum of 4,096
		 * Context window: 16k tokens
		 */
		GPT_3_5_TURBO_0125("gpt-3.5-turbo-0125"),

		/**
		 * GPT-3.5 Turbo model with improved instruction following,
		 * JSON mode, reproducible outputs, parallel function calling,
		 * and more. Returns a maximum of 4,096 output tokens.
		 * Context window: 16k tokens.
		 */
		GPT_3_5_TURBO_1106("gpt-3.5-turbo-1106");

		public final String  value;

		ChatModel(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}
	}

model配置

  • 官方的OpenAiApi.ChatModel列举了常用gpt 版本,我们可以在配置model时直接使用,避免手动输入的错误
  • 当然application.yaml配置时还需要使用字符串定义
@RequestMapping("/ai/chat5")
public Object chatStream(@RequestParam(value = "msg") String msg){
    Flux<ChatResponse> flux = openAiChatClient.stream(new Prompt(msg,
                    OpenAiChatOptions.builder()
                            .withModel(OpenAiApi.ChatModel.GPT_4_VISION_PREVIEW.getValue()) //gpt版本 "gpt-4-vision-preview"
                            .withTemperature(0.5F) //温度高,回答创新型越高;越低,越准确
                            .withMaxTokens(4096) //显示最大token
                            .build()
            )
    );
    flux.toStream().forEach(chatResponse -> {
        System.out.print(chatResponse.getResult().getOutput().getContent());
    });
    return flux.collectList();
}

相关推荐

  1. 安装git

    2024-05-14 16:02:10       37 阅读
  2. 【黄啊】宝塔设置默认php版本无效?

    2024-05-14 16:02:10       32 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-14 16:02:10       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-14 16:02:10       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-14 16:02:10       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-14 16:02:10       18 阅读

热门阅读

  1. js怎么判断视频链接是否能播放

    2024-05-14 16:02:10       11 阅读
  2. obsidian 使用 git 进行多终端同步

    2024-05-14 16:02:10       9 阅读
  3. AI编程工具为什么选github copilot?

    2024-05-14 16:02:10       15 阅读
  4. curl获取http请求的响应头

    2024-05-14 16:02:10       9 阅读
  5. Go语言数值类型教程

    2024-05-14 16:02:10       10 阅读
  6. 算法训练营day52,204. 计数质数

    2024-05-14 16:02:10       12 阅读
  7. Spring AOP切面实现为mapper层指定方法入参字段赋值

    2024-05-14 16:02:10       11 阅读
  8. 如何隐藏一个元素的滚动条

    2024-05-14 16:02:10       7 阅读
  9. 【sql】复习题

    2024-05-14 16:02:10       8 阅读
  10. 策略模式实战

    2024-05-14 16:02:10       10 阅读
  11. 学习嵌入式开发必须掌握的基础硬件知识

    2024-05-14 16:02:10       12 阅读