Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai-help): use GPT-3.5 for free users #393

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ai-test/src/ai_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ pub async fn ai_help_all(
function_call: None,
})
.collect();
if let Some(req) = prepare_ai_help_req(openai_client, supabase_pool, messages).await? {
if let Some(req) =
prepare_ai_help_req(openai_client, supabase_pool, true, messages).await?
{
let mut res = openai_client.chat().create(req.req.clone()).await?;
let res = res.choices.pop().map(|res| res.message);
let storage = Storage { req, res };
Expand Down
12 changes: 12 additions & 0 deletions src/ai/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ pub struct AIHelpConfig {
pub make_context: fn(Vec<RelatedDoc>) -> String,
}

pub const AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig {
name: "20230901-full_doc-new_prompt",
model: "gpt-3.5-turbo-1106",
full_doc: true,
system_prompt: include_str!("prompts/new_prompt/system.md"),
user_prompt: None,
token_limit: 16_384,
context_limit: 12_000,
max_completion_tokens: 2_048,
make_context: |related_docs| related_docs.into_iter().map(|d| d.content).join("\n"),
};

pub const AI_HELP_GPT4_FULL_DOC_NEW_PROMPT: AIHelpConfig = AIHelpConfig {
name: "20230901-gpt4-full_doc-new_pormpt",
model: "gpt-4-1106-preview",
Expand Down
10 changes: 8 additions & 2 deletions src/ai/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};

use crate::{
ai::{
constants::AI_HELP_GPT4_FULL_DOC_NEW_PROMPT,
constants::{AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT, AI_HELP_GPT4_FULL_DOC_NEW_PROMPT},
embeddings::{get_related_docs, get_related_macro_docs},
error::AIError,
helpers::{cap_messages, into_user_messages, sanitize_messages},
Expand All @@ -35,9 +35,15 @@ pub struct AIHelpRequest {
pub async fn prepare_ai_help_req(
client: &Client<OpenAIConfig>,
pool: &SupaPool,
is_subscriber: bool,
messages: Vec<ChatCompletionRequestMessage>,
) -> Result<Option<AIHelpRequest>, AIError> {
let config = AI_HELP_GPT4_FULL_DOC_NEW_PROMPT;
let config = if is_subscriber {
AI_HELP_GPT4_FULL_DOC_NEW_PROMPT
} else {
AI_HELP_GPT3_5_FULL_DOC_NEW_PROMPT
};

let open_ai_messages = sanitize_messages(messages);

// TODO: sign messages os we don't check again
Expand Down
2 changes: 1 addition & 1 deletion src/api/ai_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ pub async fn ai_help(
)?;
}

match prepare_ai_help_req(client, pool, messages).await? {
match prepare_ai_help_req(client, pool, user.is_subscriber(), messages).await? {
Some(ai_help_req) => {
let sources = ai_help_req.refs;
let created_at = match record_sources(
Expand Down