Merge branch 'wp4-prompts'
This commit is contained in:
commit
7939b99a5c
11 files changed
+658
-133
No files matched your search
+54
-1
@@ -877,6 +877,59 @@ def test_agents_are_created_updated_listed_and_deleted(client: TestClient) -> No
|
||||
assert client.delete(f"/api/agents/{agent['id']}").status_code == 404
|
||||
|
||||
|
||||
def test_agents_take_and_serve_prompts_and_still_take_an_intent(client: TestClient) -> None:
|
||||
prompts = [{"name": "AI and data leadership", "text": "VP, Head or Director of AI"},
|
||||
{"name": "Forward deployed", "text": ""}]
|
||||
created = client.post("/api/agents", json={"name": "Wolf", "prompts": prompts})
|
||||
assert created.status_code == 200
|
||||
assert created.json()["prompts"] == prompts and "intent" not in created.json()
|
||||
listed = client.get("/api/agents").json()
|
||||
assert listed[0]["prompts"] == prompts and "intent" not in listed[0]
|
||||
|
||||
# Reordered in place; then the body from before prompts, which becomes one.
|
||||
agent_id = created.json()["id"]
|
||||
swapped = client.post("/api/agents", json={"id": agent_id, "name": "Wolf",
|
||||
"prompts": prompts[::-1]})
|
||||
assert swapped.json()["prompts"] == prompts[::-1]
|
||||
legacy = client.post("/api/agents", json={"id": agent_id, "name": "Wolf",
|
||||
"intent": "python backend"})
|
||||
assert legacy.json()["prompts"] == [{"name": "Wolf", "text": "python backend"}]
|
||||
# `prompts` wins over `intent` when both are sent.
|
||||
both = client.post("/api/agents", json={"id": agent_id, "name": "Wolf", "prompts": [],
|
||||
"intent": "python backend"})
|
||||
assert both.json()["prompts"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prompts, says", [
|
||||
([{"name": "AI", "text": "a"}, {"name": "ai", "text": "b"}], "two prompts are named 'ai'"),
|
||||
([{"name": " ", "text": "a"}], "a prompt needs a name"),
|
||||
])
|
||||
def test_a_duplicate_or_empty_prompt_name_is_a_422_sentence(
|
||||
client: TestClient, prompts: list[dict[str, str]], says: str) -> None:
|
||||
res = client.post("/api/agents", json={"name": "Bad", "prompts": prompts})
|
||||
assert res.status_code == 422 and says in res.json()["detail"]
|
||||
assert client.get("/api/agents").json() == []
|
||||
|
||||
|
||||
def test_the_role_endpoint_serves_the_agents_score_and_its_prompt(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
uid = posting("1").uid
|
||||
agent = store.save_agent("A", prompts=[])
|
||||
store.replace_scores(agent.id, [(uid, 0.8, "", "Forward deployed")])
|
||||
|
||||
role = client.get(f"/api/roles/{uid}", params={"agent": agent.id}).json()
|
||||
assert (role["score"], role["gated_reason"], role["prompt"]) == \
|
||||
(0.8, "", "Forward deployed")
|
||||
row = client.get("/api/roles", params={"agent": agent.id}).json()["items"][0]
|
||||
assert row["prompt"] == "Forward deployed"
|
||||
voted = client.post(f"/api/roles/{uid}/vote", json={"value": 1, "agent": agent.id})
|
||||
assert voted.json()["score"] == pytest.approx(0.96)
|
||||
other = store.save_agent("B")
|
||||
unscored = client.get(f"/api/roles/{uid}", params={"agent": other.id}).json()
|
||||
assert (unscored["score"], unscored["prompt"]) == (None, "")
|
||||
|
||||
|
||||
def test_deleting_an_agent_takes_its_votes_and_affinities_with_it(
|
||||
client: TestClient, store: Store) -> None:
|
||||
store.upsert_role(posting("1"))
|
||||
@@ -950,7 +1003,7 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
|
||||
assert set(row) == {
|
||||
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
|
||||
"salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"original_url", "posted_at", "score", "gated_reason", "vote",
|
||||
"original_url", "posted_at", "score", "gated_reason", "prompt", "vote",
|
||||
"voted_at", "read_at", "tags", "excerpt",
|
||||
}
|
||||
assert row["uid"] == uid
|
||||
|
||||
Reference in new issue
Block a user