-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feature/add aisettings to django #927
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7a1f67a
add new AISettings Django model
rachaelcodes 5ed41e6
add migrations
rachaelcodes f5b74d8
send ai_settings to core_api
rachaelcodes ca86cc6
await ai settings
rachaelcodes 7341836
fix migrations
rachaelcodes f708e46
fix conftest
rachaelcodes e68cf0c
add data to non-streamed request
rachaelcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
django_app/redbox_app/redbox_core/migrations/0028_aisettings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Generated by Django 5.0.7 on 2024-08-07 12:33 | ||
|
||
import uuid | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def create_default_ai_settings(apps, schema_editor): | ||
AISettings = apps.get_model("redbox_core", "AISettings") | ||
AISettings.objects.create(label="default") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("redbox_core", "0027_alter_file_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="AISettings", | ||
fields=[ | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
primary_key=True, | ||
serialize=False, | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("modified_at", models.DateTimeField(auto_now=True)), | ||
("label", models.CharField(max_length=50, unique=True)), | ||
("context_window_size", models.PositiveIntegerField(default=8000)), | ||
("rag_k", models.PositiveIntegerField(default=30)), | ||
("rag_num_candidates", models.PositiveIntegerField(default=10)), | ||
("rag_desired_chunk_size", models.PositiveIntegerField(default=300)), | ||
("elbow_filter_enabled", models.BooleanField(default=False)), | ||
( | ||
"chat_system_prompt", | ||
models.TextField( | ||
default="You are an AI assistant called Redbox tasked with answering questions and providing information objectively." | ||
), | ||
), | ||
( | ||
"chat_question_prompt", | ||
models.TextField(default="{question}\n=========\n Response: "), | ||
), | ||
("stuff_chunk_context_ratio", models.FloatField(default=0.75)), | ||
( | ||
"chat_with_docs_system_prompt", | ||
models.TextField( | ||
default="You are an AI assistant called Redbox tasked with answering questions on user provided documents and providing information objectively." | ||
), | ||
), | ||
( | ||
"chat_with_docs_question_prompt", | ||
models.TextField( | ||
default="Question: {question}. \n\n Documents: \n\n {formatted_documents} \n\n Answer: " | ||
), | ||
), | ||
( | ||
"chat_with_docs_reduce_system_prompt", | ||
models.TextField( | ||
default="You are an AI assistant tasked with answering questions on user provided documents. Your goal is to answer the user question based on list of summaries in a coherent manner.Please follow these guidelines while answering the question: \n1) Identify and highlight key points,\n2) Avoid repetition,\n3) Ensure the answer is easy to understand,\n4) Maintain the original context and meaning.\n" | ||
), | ||
), | ||
( | ||
"retrieval_system_prompt", | ||
models.TextField( | ||
default="Given the following conversation and extracted parts of a long document and a question, create a final answer. \nIf you don't know the answer, just say that you don't know. Don't try to make up an answer. If a user asks for a particular format to be returned, such as bullet points, then please use that format. If a user asks for bullet points you MUST give bullet points. If the user asks for a specific number or range of bullet points you MUST give that number of bullet points. \nUse **bold** to highlight the most question relevant parts in your response. If dealing dealing with lots of data return it in markdown table format. " | ||
), | ||
), | ||
( | ||
"retrieval_question_prompt", | ||
models.TextField( | ||
default="{question} \n=========\n{formatted_documents}\n=========\nFINAL ANSWER: " | ||
), | ||
), | ||
( | ||
"condense_system_prompt", | ||
models.TextField( | ||
default="Given the following conversation and a follow up question, generate a follow up question to be a standalone question. You are only allowed to generate one question in response. Include sources from the chat history in the standalone question created, when they are available. If you don't know the answer, just say that you don't know, don't try to make up an answer. \n" | ||
), | ||
), | ||
( | ||
"condense_question_prompt", | ||
models.TextField( | ||
default="{question}\n=========\n Standalone question: " | ||
), | ||
), | ||
("map_max_concurrency", models.PositiveIntegerField(default=128)), | ||
( | ||
"chat_map_system_prompt", | ||
models.TextField( | ||
default="You are an AI assistant tasked with summarizing documents. Your goal is to extract the most important information and present it in a concise and coherent manner. Please follow these guidelines while summarizing: \n1) Identify and highlight key points,\n2) Avoid repetition,\n3) Ensure the summary is easy to understand,\n4) Maintain the original context and meaning.\n" | ||
), | ||
), | ||
( | ||
"chat_map_question_prompt", | ||
models.TextField( | ||
default="Question: {question}. \n Documents: \n {formatted_documents} \n\n Answer: " | ||
), | ||
), | ||
( | ||
"reduce_system_prompt", | ||
models.TextField( | ||
default="You are an AI assistant tasked with summarizing documents. Your goal is to write a concise summary of list of summaries from a list of summaries in a concise and coherent manner. Please follow these guidelines while summarizing: \n1) Identify and highlight key points,\n2) Avoid repetition,\n3) Ensure the summary is easy to understand,\n4) Maintain the original context and meaning.\n" | ||
), | ||
), | ||
("llm_max_tokens", models.PositiveIntegerField(default=1024)), | ||
("match_boost", models.PositiveIntegerField(default=1)), | ||
("knn_boost", models.PositiveIntegerField(default=1)), | ||
("similarity_threshold", models.PositiveIntegerField(default=0)), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.RunPython(create_default_ai_settings, migrations.RunPython.noop), | ||
migrations.AddField( | ||
model_name="user", | ||
name="ai_settings", | ||
field=models.ForeignKey( | ||
default="default", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL. nice |
||
on_delete=django.db.models.deletion.SET_DEFAULT, | ||
to="redbox_core.aisettings", | ||
to_field="label", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
CHAT_SYSTEM_PROMPT = ( | ||
"You are an AI assistant called Redbox tasked with answering questions and providing information objectively." | ||
) | ||
|
||
CHAT_WITH_DOCS_SYSTEM_PROMPT = ( | ||
"You are an AI assistant called Redbox tasked with answering questions on user provided documents and " | ||
"providing information objectively." | ||
) | ||
|
||
CHAT_WITH_DOCS_REDUCE_SYSTEM_PROMPT = ( | ||
"You are an AI assistant tasked with answering questions on user provided documents. " | ||
"Your goal is to answer the user question based on list of summaries in a coherent manner." | ||
"Please follow these guidelines while answering the question: \n" | ||
"1) Identify and highlight key points,\n" | ||
"2) Avoid repetition,\n" | ||
"3) Ensure the answer is easy to understand,\n" | ||
"4) Maintain the original context and meaning.\n" | ||
) | ||
|
||
RETRIEVAL_SYSTEM_PROMPT = ( | ||
"Given the following conversation and extracted parts of a long document and a question, create a final answer. \n" | ||
"If you don't know the answer, just say that you don't know. Don't try to make up an answer. " | ||
"If a user asks for a particular format to be returned, such as bullet points, then please use that format. " | ||
"If a user asks for bullet points you MUST give bullet points. " | ||
"If the user asks for a specific number or range of bullet points you MUST give that number of bullet points. \n" | ||
"Use **bold** to highlight the most question relevant parts in your response. " | ||
"If dealing dealing with lots of data return it in markdown table format. " | ||
) | ||
|
||
CHAT_MAP_SYSTEM_PROMPT = ( | ||
"You are an AI assistant tasked with summarizing documents. " | ||
"Your goal is to extract the most important information and present it in " | ||
"a concise and coherent manner. Please follow these guidelines while summarizing: \n" | ||
"1) Identify and highlight key points,\n" | ||
"2) Avoid repetition,\n" | ||
"3) Ensure the summary is easy to understand,\n" | ||
"4) Maintain the original context and meaning.\n" | ||
) | ||
|
||
REDUCE_SYSTEM_PROMPT = ( | ||
"You are an AI assistant tasked with summarizing documents. " | ||
"Your goal is to write a concise summary of list of summaries from a list of summaries in " | ||
"a concise and coherent manner. Please follow these guidelines while summarizing: \n" | ||
"1) Identify and highlight key points,\n" | ||
"2) Avoid repetition,\n" | ||
"3) Ensure the summary is easy to understand,\n" | ||
"4) Maintain the original context and meaning.\n" | ||
) | ||
|
||
CONDENSE_SYSTEM_PROMPT = ( | ||
"Given the following conversation and a follow up question, generate a follow " | ||
"up question to be a standalone question. " | ||
"You are only allowed to generate one question in response. " | ||
"Include sources from the chat history in the standalone question created, " | ||
"when they are available. " | ||
"If you don't know the answer, just say that you don't know, " | ||
"don't try to make up an answer. \n" | ||
) | ||
|
||
CHAT_QUESTION_PROMPT = "{question}\n=========\n Response: " | ||
|
||
CHAT_WITH_DOCS_QUESTION_PROMPT = "Question: {question}. \n\n Documents: \n\n {formatted_documents} \n\n Answer: " | ||
|
||
RETRIEVAL_QUESTION_PROMPT = "{question} \n=========\n{formatted_documents}\n=========\nFINAL ANSWER: " | ||
|
||
CHAT_MAP_QUESTION_PROMPT = "Question: {question}. \n Documents: \n {formatted_documents} \n\n Answer: " | ||
|
||
CONDENSE_QUESTION_PROMPT = "{question}\n=========\n Standalone question: " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears again in django_app/redbox_app/redbox_core/client.py ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't one for streamed and one for non-streamed requests?