Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Heading from "../framework/heading.jsx";
import Footer from "../framework/Footer.jsx";
import CommentList from "../lists/commentList.jsx";
import * as globals from "../globals";
import LocalModelNote from "../localModelNote/LocalModelNote.jsx";

const CollectiveStatementsReport = ({ conversation, report_id, math, comments, ptptCount, formatTid, voteColors }) => {
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -235,6 +236,7 @@ const CollectiveStatementsReport = ({ conversation, report_id, math, comments, p
Generated {new Date(statement.created_at).toLocaleDateString()} at {new Date(statement.created_at).toLocaleTimeString()}
{statement.model && ` • ${statement.model.includes('claude') ? 'Claude Opus 4' : statement.model}`}
</p>
<LocalModelNote provider={statement.provider} model={statement.model} />
</div>

{/* Content */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useReportId } from "../framework/useReportId";
import CommentList from "../lists/commentList.jsx";
import { jwtDecode } from "jwt-decode"
import "./CommentsReport.css";
import LocalModelNote from "../localModelNote/LocalModelNote.jsx";

const decodedJwt = (token) => {
if (token) {
Expand Down Expand Up @@ -1120,6 +1121,7 @@ const CommentsReport = ({ math, comments, conversation, ptptCount, formatTid, vo
<span> | Model: {report.model || "N/A"}</span>
</div>
)}
{report && <LocalModelNote provider={report.metadata?.provider} model={report.model} />}
{selectedSection.topicMetadata && (
<div className="metadata-row">
<span className="metadata-label">Topic Info:</span>
Expand Down
22 changes: 22 additions & 0 deletions client-report/src/components/localModelNote/LocalModelNote.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";

// Shown under a narrative section or collective statement written by a local
// model (LLM_PROVIDER=ollama on the server and Delphi). Hosted output gets no note.
export const localModelNoteText = (model) =>
`Generated by a local model (${model || "unknown model"}); quality differs from the hosted model.`;

// ``as="span"`` renders inside an existing paragraph (a <p> cannot hold a <p>).
const LocalModelNote = ({ provider, model, style, as: Tag = "p" }) => {
if (provider !== "ollama") return null;
return (
<Tag
className="local-model-note"
data-testid="local-model-note"
style={{ display: "block", margin: "4px 0", fontSize: "0.85em", color: "#666", fontStyle: "italic", ...style }}
>
{localModelNoteText(model)}
</Tag>
);
};

export default LocalModelNote;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import LocalModelNote from "./LocalModelNote.jsx";

describe("LocalModelNote", () => {
it("names the local model and the quality difference", () => {
render(<LocalModelNote provider="ollama" model="llama3.1:8b" />);
expect(screen.getByTestId("local-model-note")).toHaveTextContent(
"Generated by a local model (llama3.1:8b); quality differs from the hosted model."
);
});

it("renders as a span inside an existing paragraph", () => {
render(
<p data-testid="outer">
text <LocalModelNote as="span" provider="ollama" model="llama3.1:8b" />
</p>
);
const note = screen.getByTestId("local-model-note");
expect(note.tagName).toBe("SPAN");
expect(screen.getByTestId("outer").querySelector("p")).toBeNull();
});

it("renders nothing for hosted or unrecorded provenance", () => {
const { container, rerender } = render(<LocalModelNote provider="anthropic" model="claude-opus-4-8" />);
expect(container).toBeEmptyDOMElement();
rerender(<LocalModelNote model="claude-opus-4-8" />);
expect(container).toBeEmptyDOMElement();
});
});
13 changes: 11 additions & 2 deletions client-report/src/components/topicPage/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TopicBeeswarm from "../topicStats/visualizations/TopicBeeswarm.jsx";
import AllCommentsScatterplot from "../topicStats/visualizations/AllCommentsScatterplot.jsx";
import CommentList from "../lists/commentList.jsx";
import * as globals from "../globals";
import LocalModelNote from "../localModelNote/LocalModelNote.jsx";
import { canGenerateCollectiveStatement, getTopicConsensusValues } from "../../util/consensusThreshold";

const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCount, formatTid, voteColors, onBack, token }) => {
Expand All @@ -19,6 +20,7 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
const [topicComments, setTopicComments] = useState([]);
const [sortedComments, setSortedComments] = useState([]);
const [topicNarrative, setTopicNarrative] = useState(null);
const [narrativeProvenance, setNarrativeProvenance] = useState(null);
const [narrativeLoading, setNarrativeLoading] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -160,7 +162,8 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
setStatementGenerated(true);
setStatementMetadata({
created_at: existingStatement.created_at,
model: existingStatement.model
model: existingStatement.model,
provider: existingStatement.provider
});
setLoadingStatement(false);
return;
Expand Down Expand Up @@ -214,7 +217,8 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
setStatementGenerated(true);
setStatementMetadata({
created_at: response.created_at,
model: response.model
model: response.model,
provider: response.provider
});
} else if (response.statement) {
setCollectiveStatement(response.statement);
Expand Down Expand Up @@ -256,6 +260,7 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
? JSON.parse(sectionData.report_data)
: sectionData.report_data;
setTopicNarrative(reportData);
setNarrativeProvenance({ provider: sectionData.metadata?.provider, model: sectionData.model });
}
}
} catch (err) {
Expand Down Expand Up @@ -469,6 +474,9 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
{statementMetadata.model && ` (${statementMetadata.model.includes('claude') ? 'Claude Opus 4' : statementMetadata.model})`}
</span>
)}
{statementMetadata && (
<LocalModelNote as="span" provider={statementMetadata.provider} model={statementMetadata.model} style={{ fontSize: "13px" }} />
)}
</p>

{loadingStatement && (
Expand Down Expand Up @@ -632,6 +640,7 @@ const TopicPage = ({ conversation, report_id, topic_key, math, comments, ptptCou
letterSpacing: "0.5px",
textTransform: "uppercase"
}}>Narrative Summary</p>
<LocalModelNote provider={narrativeProvenance?.provider} model={narrativeProvenance?.model} />

{/* Extract all citations from the narrative */}
{(() => {
Expand Down
4 changes: 4 additions & 0 deletions client-report/src/components/topicReport/TopicReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import CommentList from "../lists/commentList.jsx";
import TopicDataProvider from "./TopicDataProvider.jsx";
import TopicSectionsBuilder from "./TopicSectionsBuilder.jsx";
import TopicSelector from "./TopicSelector.jsx";
import LocalModelNote from "../localModelNote/LocalModelNote.jsx";

const TopicReport = ({ report_id, math, comments, conversation, ptptCount, formatTid, voteColors }) => {
const [selectedTopic, setSelectedTopic] = useState("");
const [topicContent, setTopicContent] = useState(null);
const [contentProvenance, setContentProvenance] = useState(null);
const [contentLoading, setContentLoading] = useState(false);

// Extract content fetching logic for reuse
Expand All @@ -34,6 +36,7 @@ const TopicReport = ({ report_id, math, comments, conversation, ptptCount, forma
? JSON.parse(sectionData.report_data)
: sectionData.report_data;
setTopicContent(reportData);
setContentProvenance({ provider: sectionData.metadata?.provider, model: sectionData.model });
} else {
setTopicContent({
error: true,
Expand Down Expand Up @@ -109,6 +112,7 @@ const TopicReport = ({ report_id, math, comments, conversation, ptptCount, forma
<div className="topic-layout-container">
<div className="topic-text-content">
<div className="topic-content">
<LocalModelNote provider={contentProvenance?.provider} model={contentProvenance?.model} />
{topicContent.paragraphs && topicContent.paragraphs.map((paragraph, idx) => (
<div key={idx} className="paragraph">
<h3>{paragraph.title}</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
import net from "../../util/net";
import CommentList from "../lists/commentList.jsx";
import { canGenerateCollectiveStatement, getTopicConsensusValues } from "../../util/consensusThreshold";
import LocalModelNote from "../localModelNote/LocalModelNote.jsx";

const CollectiveStatementModal = ({
isOpen,
Expand Down Expand Up @@ -82,7 +83,8 @@ const CollectiveStatementModal = ({
setCommentsData(existingStatement.comments_data);
setStatementMetadata({
created_at: existingStatement.created_at,
model: existingStatement.model
model: existingStatement.model,
provider: existingStatement.provider
});
setLoading(false);
return;
Expand Down Expand Up @@ -133,7 +135,8 @@ const CollectiveStatementModal = ({
setCommentsData(response.commentsData);
setStatementMetadata({
created_at: response.created_at,
model: response.model
model: response.model,
provider: response.provider
});
} else {
setError(response.message || "Failed to generate statement");
Expand Down Expand Up @@ -310,6 +313,9 @@ const CollectiveStatementModal = ({
{statementMetadata.model && ` (${statementMetadata.model.includes('claude') ? 'Claude Opus 4' : statementMetadata.model})`}
</p>
)}
{statementMetadata && (
<LocalModelNote provider={statementMetadata.provider} model={statementMetadata.model} />
)}
</div>
<div
style={{
Expand Down
16 changes: 14 additions & 2 deletions delphi/scripts/job_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def _postgres_vote_to_delphi(pg_vote):
import urllib


def narrative_model_for_provider(env) -> str:
"""The --model 801 runs with. LLM_PROVIDER=ollama uses OLLAMA_MODEL (the
topic-naming default when unset) and generates the narrative inline; any
other provider keeps the Anthropic batch path, which requires
ANTHROPIC_MODEL."""
if (env.get("LLM_PROVIDER") or "anthropic").strip().lower() == "ollama":
return env.get("OLLAMA_MODEL") or "llama3.1:8b"
model = env.get("ANTHROPIC_MODEL")
if not model:
raise ValueError("ANTHROPIC_MODEL must be set")
return model


class PostgresConfig:
"""Configuration for PostgreSQL connection."""

Expand Down Expand Up @@ -1242,8 +1255,7 @@ def process_job(self, job: Dict[str, Any]) -> None:
exclude_comment_selections = job_config.get('exclude_comment_selections', True)
app_path = os.environ.get('DELPHI_APP_PATH', '/app')
if job_type == 'CREATE_NARRATIVE_BATCH':
model = os.environ.get("ANTHROPIC_MODEL")
if not model: raise ValueError("ANTHROPIC_MODEL must be set")
model = narrative_model_for_provider(os.environ)
max_batch_size = job_config.get('max_batch_size', 20)
cmd = ['python', f'{app_path}/umap_narrative/801_narrative_report_batch.py', f'--conversation_id={conversation_id}', f'--model={model}', f'--include_moderation={include_moderation}', f'--exclude_comment_selections={exclude_comment_selections}', f'--max-batch-size={str(max_batch_size)}']
if job_config.get('no_cache'): cmd.append('--no-cache')
Expand Down
5 changes: 5 additions & 0 deletions delphi/tests/test_compose_math_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ def test_math_python_forwards_the_shared_memory_admission_settings(monkeypatch):
"OLLAMA_HOST": "",
"OLLAMA_ENDPOINT": "",
"OLLAMA_MODEL": "",
# Local narrative knobs: "" means the code default (narrative_local.py).
"OLLAMA_NARRATIVE_CONCURRENCY": "",
"OLLAMA_REQUEST_TIMEOUT_SECONDS": "",
"OLLAMA_NARRATIVE_JOB_TIMEOUT_SECONDS": "",
"OLLAMA_NUM_CTX": "",
}
_LLM_KEY_READ = re.compile(
r"""(?:environ\.get|getenv|environ\[)\(?\s*["'](?P<key>(?:LLM_|ANTHROPIC_|OLLAMA_)[A-Z_]+|SENTENCE_TRANSFORMER_MODEL|TOPIC_BATCH_[A-Z_]+)["']"""
Expand Down
Loading
Loading