Skip to content

Commit c976725

Browse files
authored
feat: org info (#5694)
1 parent 243f0bb commit c976725

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

backend/onyx/agents/agent_search/dr/nodes/dr_a0_clarification.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from onyx.prompts.dr_prompts import REPEAT_PROMPT
7575
from onyx.prompts.dr_prompts import TOOL_DESCRIPTION
7676
from onyx.prompts.prompt_template import PromptTemplate
77+
from onyx.prompts.prompt_utils import handle_company_awareness
7778
from onyx.server.query_and_chat.streaming_models import MessageStart
7879
from onyx.server.query_and_chat.streaming_models import OverallStop
7980
from onyx.server.query_and_chat.streaming_models import SectionEnd
@@ -490,6 +491,7 @@ def clarifier(
490491
+ PROJECT_INSTRUCTIONS_SEPARATOR
491492
+ graph_config.inputs.project_instructions
492493
)
494+
assistant_system_prompt = handle_company_awareness(assistant_system_prompt)
493495

494496
chat_history_string = (
495497
get_chat_history_string(

backend/onyx/chat/prompt_builder/answer_prompt_builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from onyx.prompts.chat_prompts import REQUIRE_CITATION_STATEMENT
2525
from onyx.prompts.direct_qa_prompts import HISTORY_BLOCK
2626
from onyx.prompts.prompt_utils import drop_messages_history_overflow
27+
from onyx.prompts.prompt_utils import handle_company_awareness
2728
from onyx.prompts.prompt_utils import handle_onyx_date_awareness
2829
from onyx.tools.force import ForceUseTool
2930
from onyx.tools.models import ToolCallFinalResult
@@ -54,6 +55,8 @@ def default_build_system_message_v2(
5455
if not tag_handled_prompt:
5556
return None
5657

58+
tag_handled_prompt = handle_company_awareness(tag_handled_prompt)
59+
5760
return SystemMessage(content=tag_handled_prompt)
5861

5962

@@ -78,6 +81,8 @@ def default_build_system_message(
7881
if not tag_handled_prompt:
7982
return None
8083

84+
tag_handled_prompt = handle_company_awareness(tag_handled_prompt)
85+
8186
return SystemMessage(content=tag_handled_prompt)
8287

8388

backend/onyx/prompts/direct_qa_prompts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
{GENERAL_SEP_PAT}
5555
"""
5656

57+
COMPANY_NAME_BLOCK = """
58+
The user works at {company_name}.
59+
"""
60+
61+
COMPANY_DESCRIPTION_BLOCK = """Organization description: {company_description}
62+
"""
5763

5864
# This has to be doubly escaped due to json containing { } which are also used for format strings
5965
EMPTY_SAMPLE_JSON = {

backend/onyx/prompts/prompt_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from onyx.prompts.chat_prompts import ADDITIONAL_INFO
1414
from onyx.prompts.chat_prompts import CITATION_REMINDER
1515
from onyx.prompts.constants import CODE_BLOCK_PAT
16+
from onyx.prompts.direct_qa_prompts import COMPANY_DESCRIPTION_BLOCK
17+
from onyx.prompts.direct_qa_prompts import COMPANY_NAME_BLOCK
18+
from onyx.server.settings.store import load_settings
1619
from onyx.utils.logger import setup_logger
1720

1821

@@ -89,6 +92,23 @@ def handle_onyx_date_awareness(
8992
return prompt_str
9093

9194

95+
def handle_company_awareness(prompt_str: str) -> str:
96+
try:
97+
workspace_settings = load_settings()
98+
company_name = workspace_settings.company_name
99+
company_description = workspace_settings.company_description
100+
if company_name:
101+
prompt_str += COMPANY_NAME_BLOCK.format(company_name=company_name)
102+
if company_description:
103+
prompt_str += COMPANY_DESCRIPTION_BLOCK.format(
104+
company_description=company_description
105+
)
106+
return prompt_str
107+
except Exception as e:
108+
logger.error(f"Error handling company awareness: {e}")
109+
return prompt_str
110+
111+
92112
def build_task_prompt_reminders(
93113
prompt: Persona | PromptConfig,
94114
use_language_hint: bool,

backend/onyx/server/settings/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Settings(BaseModel):
4545

4646
# is float to allow for fractional days for easier automated testing
4747
maximum_chat_retention_days: float | None = None
48+
company_name: str | None = None
49+
company_description: str | None = None
4850
gpu_enabled: bool | None = None
4951
application_status: ApplicationStatus = ApplicationStatus.ACTIVE
5052
anonymous_user_enabled: bool | None = None

web/src/app/admin/settings/SettingsForm.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export function SettingsForm() {
8282
const [showConfirmModal, setShowConfirmModal] = useState(false);
8383
const [settings, setSettings] = useState<Settings | null>(null);
8484
const [chatRetention, setChatRetention] = useState("");
85+
const [companyName, setCompanyName] = useState("");
86+
const [companyDescription, setCompanyDescription] = useState("");
8587
const { popup, setPopup } = usePopup();
8688
const isEnterpriseEnabled = usePaidEnterpriseFeaturesEnabled();
8789

@@ -101,6 +103,10 @@ export function SettingsForm() {
101103
setChatRetention(
102104
combinedSettings.settings.maximum_chat_retention_days?.toString() || ""
103105
);
106+
setCompanyName(combinedSettings.settings.company_name || "");
107+
setCompanyDescription(
108+
combinedSettings.settings.company_description || ""
109+
);
104110
}
105111
// We don't need to fetch vision providers here anymore as the hook handles it
106112
}, []);
@@ -190,10 +196,58 @@ export function SettingsForm() {
190196
]);
191197
}
192198

199+
function handleCompanyNameBlur() {
200+
updateSettingField([
201+
{ fieldName: "company_name", newValue: companyName || null },
202+
]);
203+
}
204+
205+
// NOTE: at the moment there's a small bug where if you click another admin panel page after typing
206+
// the field doesn't update correctly
207+
function handleCompanyDescriptionBlur() {
208+
updateSettingField([
209+
{
210+
fieldName: "company_description",
211+
newValue: companyDescription || null,
212+
},
213+
]);
214+
}
215+
193216
return (
194217
<div className="flex flex-col pb-8">
195218
{popup}
196219
<Title className="mb-4">Workspace Settings</Title>
220+
<label className="flex flex-col text-sm mb-4">
221+
<Label>Company Name</Label>
222+
<SubLabel>
223+
Set the company name used for search and chat context.
224+
</SubLabel>
225+
<input
226+
type="text"
227+
className="mt-1 p-2 border rounded w-full max-w-xl"
228+
value={companyName}
229+
onChange={(e) => setCompanyName(e.target.value)}
230+
onBlur={handleCompanyNameBlur}
231+
placeholder="Enter company name"
232+
/>
233+
</label>
234+
235+
<label className="flex flex-col text-sm mb-4">
236+
<Label>Company Description</Label>
237+
<SubLabel>
238+
Provide a short description of the company for search and chat
239+
context.
240+
</SubLabel>
241+
<textarea
242+
className="mt-1 p-2 border rounded w-full max-w-xl"
243+
value={companyDescription}
244+
onChange={(e) => setCompanyDescription(e.target.value)}
245+
onBlur={handleCompanyDescriptionBlur}
246+
placeholder="Enter company description"
247+
rows={4}
248+
/>
249+
</label>
250+
197251
<Checkbox
198252
label="Auto-scroll"
199253
sublabel="If set, the chat window will automatically scroll to the bottom as new lines of text are generated by the AI model. This can be overridden by individual user settings."

web/src/app/admin/settings/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface Settings {
1414
anonymous_user_enabled: boolean;
1515
anonymous_user_path?: string;
1616
maximum_chat_retention_days?: number | null;
17+
company_name?: string | null;
18+
company_description?: string | null;
1719
notifications: Notification[];
1820
needs_reindexing: boolean;
1921
gpu_enabled: boolean;

0 commit comments

Comments
 (0)