From 0e57060d7ecf9d5d27d0c8bc5d7eb279adedfeaa Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:07:22 +0200 Subject: [PATCH] feat(ai-help): upgrade from GPT-3.5 Turbo to GPT-4o mini (#546) --- src/ai/constants.rs | 18 ++++++++---------- src/ai/explain.rs | 4 ++-- src/ai/help.rs | 10 ++++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/ai/constants.rs b/src/ai/constants.rs index 9f30e71d..1ded521e 100644 --- a/src/ai/constants.rs +++ b/src/ai/constants.rs @@ -5,7 +5,6 @@ use crate::ai::embeddings::RelatedDoc; // Whenever changing the model: bump the AI_EXPLAIN_VERSION! #[derive(Debug, Copy, Clone)] pub struct AIHelpConfig { - pub name: &'static str, pub model: &'static str, pub full_doc: bool, pub system_prompt: &'static str, @@ -24,9 +23,12 @@ fn join_with_tags(related_docs: Vec) -> String { .join("\n") } -pub const AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig { - name: "20230901-full_doc-new_prompt", - model: "gpt-3.5-turbo-0125", +pub const BASIC_MODEL: &str = "gpt-4o-mini-2024-07-18"; +pub const ADVANCED_MODEL: &str = "gpt-4o-2024-05-13"; +pub const EMBEDDING_MODEL: &str = "text-embedding-3-small"; + +pub const AI_HELP_BASIC: AIHelpConfig = AIHelpConfig { + model: BASIC_MODEL, full_doc: true, system_prompt: include_str!("prompts/new_prompt/system.md"), user_prompt: None, @@ -37,9 +39,8 @@ pub const AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig { make_context: join_with_tags, }; -pub const AI_HELP_GPT4_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig { - name: "20240125-gpt4-full_doc-new_prompt", - model: "gpt-4o-2024-05-13", +pub const AI_HELP_ADVANCED: AIHelpConfig = AIHelpConfig { + model: ADVANCED_MODEL, full_doc: true, system_prompt: include_str!("prompts/new_prompt/system.md"), user_prompt: None, @@ -50,9 +51,6 @@ pub const AI_HELP_GPT4_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig { make_context: join_with_tags, }; -pub const MODEL: &str = "gpt-3.5-turbo"; -pub const EMBEDDING_MODEL: &str = "text-embedding-3-small"; - pub const AI_HELP_SYSTEM_MESSAGE: &str = "You are a very enthusiastic MDN AI who loves \ to help people! Given the following information from MDN, answer the user's question \ using only that information, outputted in markdown format.\ diff --git a/src/ai/explain.rs b/src/ai/explain.rs index a1870a53..07200335 100644 --- a/src/ai/explain.rs +++ b/src/ai/explain.rs @@ -13,7 +13,7 @@ use sha2::{Digest, Sha256}; use crate::{ ai::{ - constants::{EXPLAIN_SYSTEM_MESSAGE, MODEL}, + constants::{BASIC_MODEL, EXPLAIN_SYSTEM_MESSAGE}, error::AIError, }, api::error::ApiError, @@ -103,7 +103,7 @@ pub async fn prepare_explain_req( .build() .unwrap(); let req = CreateChatCompletionRequestArgs::default() - .model(MODEL) + .model(BASIC_MODEL) .messages(vec![system_message, context_message, user_message]) .temperature(0.0) .build()?; diff --git a/src/ai/help.rs b/src/ai/help.rs index 9504ccb1..645740a3 100644 --- a/src/ai/help.rs +++ b/src/ai/help.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; use crate::{ ai::{ - constants::{AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT, AI_HELP_GPT4_FULL_DOC_NEW_PROMPT}, + constants::{AI_HELP_ADVANCED, AI_HELP_BASIC}, embeddings::{get_related_docs, get_related_macro_docs}, error::AIError, helpers::{cap_messages, into_user_messages, sanitize_messages}, @@ -23,6 +23,8 @@ use crate::{ settings::SETTINGS, }; +use super::constants::BASIC_MODEL; + #[derive(Eq, Hash, PartialEq, Serialize, Deserialize, Debug, Clone)] pub struct RefDoc { pub url: String, @@ -54,9 +56,9 @@ pub async fn prepare_ai_help_req( request_meta: &mut AIHelpRequestMeta, ) -> Result { let config = if is_subscriber { - AI_HELP_GPT4_FULL_DOC_NEW_PROMPT + AI_HELP_ADVANCED } else { - AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT + AI_HELP_BASIC }; // // check for secret error trigger in the last message @@ -197,7 +199,7 @@ pub fn prepare_ai_help_summary_req( let messages = [&[system_message], &messages[..], &[user_message]].concat(); let req = CreateChatCompletionRequestArgs::default() - .model("gpt-3.5-turbo") + .model(BASIC_MODEL) .messages(messages) .temperature(0.0) .build()?;