forked from retoor/devplacepy
fix: correct "bugs" to "issues" in routing table and README references across multiple documentation files
This commit is contained in:
@@ -5,10 +5,11 @@ import logging
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from devplacepy import stealth
|
||||
from devplacepy.services.bot.config import (
|
||||
GIST_LANGUAGES,
|
||||
GIST_MIN_LINES,
|
||||
@@ -17,6 +18,9 @@ from devplacepy.services.bot.config import (
|
||||
SEARCH_TERMS,
|
||||
TRIVIAL_GIST_TERMS,
|
||||
)
|
||||
from devplacepy.services.bot.handles import MAX_HANDLE_LEN, sanitize_handle
|
||||
|
||||
HANDLE_CANDIDATE_TARGET = 8
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -61,19 +65,15 @@ class LLMClient:
|
||||
json.dumps(system[:500]),
|
||||
json.dumps(prompt[:500]),
|
||||
)
|
||||
data = json.dumps(payload).encode()
|
||||
req = urllib.request.Request(
|
||||
self.api_url,
|
||||
data=data,
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=30) as resp:
|
||||
raw = resp.read()
|
||||
with stealth.stealth_sync_client(timeout=30) as client:
|
||||
resp = client.post(
|
||||
self.api_url,
|
||||
json=payload,
|
||||
headers={"Authorization": f"Bearer {self.api_key}"},
|
||||
)
|
||||
raw = resp.content
|
||||
logger.info("LLM <<< %s", raw[:2000].decode(errors="replace"))
|
||||
result = json.loads(raw)
|
||||
result = resp.json()
|
||||
usage = result.get("usage", {})
|
||||
in_tokens = usage.get("prompt_tokens", 0)
|
||||
out_tokens = usage.get("completion_tokens", 0)
|
||||
@@ -86,8 +86,7 @@ class LLMClient:
|
||||
self.total_out_tokens += out_tokens
|
||||
return result["choices"][0]["message"]["content"]
|
||||
except (
|
||||
urllib.error.HTTPError,
|
||||
urllib.error.URLError,
|
||||
httpx.HTTPError,
|
||||
json.JSONDecodeError,
|
||||
KeyError,
|
||||
) as e:
|
||||
@@ -126,7 +125,7 @@ class LLMClient:
|
||||
"snippet",
|
||||
"headline",
|
||||
"gist",
|
||||
"bug",
|
||||
"issue",
|
||||
)
|
||||
result = (text or "").strip().strip('"').strip("'").strip()
|
||||
changed = True
|
||||
@@ -476,6 +475,38 @@ class LLMClient:
|
||||
data = self._parse_json(self._raw_call(system, prompt, temperature=0.9))
|
||||
return self._normalize_identity(data, archetype)
|
||||
|
||||
def generate_handle_candidates(self, archetype: str) -> list[str]:
|
||||
interests = ", ".join(SEARCH_TERMS.get(archetype, []))
|
||||
system = (
|
||||
"You invent online handles for a developer signing up to a programmer "
|
||||
"community in the style of devRant or Hacker News. The handles read like a "
|
||||
"real nerd picked them, never like a person's full name. Lean on programming "
|
||||
"and hacker culture: tech nouns (null, kernel, segfault, daemon), occasional "
|
||||
"leetspeak (c0d3r, h4x), an adjective plus noun, a creature, or a short word "
|
||||
f"with a number. Lowercase mostly, {MAX_HANDLE_LEN} characters or fewer, only "
|
||||
"letters, digits, underscores and hyphens, no spaces and no dots. Return ONLY "
|
||||
f'a JSON object {{"handles": ["...", "..."]}} with {HANDLE_CANDIDATE_TARGET} '
|
||||
"distinct handles, no prose, no markdown fences. No em dashes."
|
||||
)
|
||||
prompt = (
|
||||
f"Archetype: {archetype}\n"
|
||||
f"Their interests: {interests}\n"
|
||||
"Create the handles JSON:"
|
||||
)
|
||||
try:
|
||||
data = self._parse_json(
|
||||
self._raw_call(system, prompt, temperature=1.0)
|
||||
)
|
||||
except (ValueError, json.JSONDecodeError) as exc:
|
||||
logger.warning("Handle candidate generation failed: %s", exc)
|
||||
return []
|
||||
handles: list[str] = []
|
||||
for raw in data.get("handles", []):
|
||||
handle = sanitize_handle(raw)
|
||||
if handle and handle.lower() not in {h.lower() for h in handles}:
|
||||
handles.append(handle)
|
||||
return handles
|
||||
|
||||
@staticmethod
|
||||
def _identity_card(identity: dict) -> str:
|
||||
lines = [
|
||||
@@ -586,13 +617,13 @@ class LLMClient:
|
||||
break
|
||||
return result
|
||||
|
||||
def generate_bug(self, topic: str) -> tuple[str, str]:
|
||||
def generate_issue(self, topic: str) -> tuple[str, str]:
|
||||
text = self._call(
|
||||
"Write a bug report. One line title. Then 2-3 sentences describing what happened and what should have happened. Like a real dev reporting a bug. No em dashes.",
|
||||
f"Bug: {topic}",
|
||||
"Write an issue report. One line title. Then 2-3 sentences describing what happened and what should have happened. Like a real dev reporting an issue. No em dashes.",
|
||||
f"Issue: {topic}",
|
||||
)
|
||||
lines = text.strip().split("\n")
|
||||
title = lines[0].strip().lstrip("#").strip()[:120] or f"Bug report: {topic}"
|
||||
title = lines[0].strip().lstrip("#").strip()[:120] or f"Issue report: {topic}"
|
||||
desc = " ".join(
|
||||
line.lstrip("-* ").strip() for line in lines[1:] if line.strip()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user