diff options
Diffstat (limited to 'src/ollama_web/prompts')
| -rw-r--r-- | src/ollama_web/prompts/__init__.py | 57 | ||||
| -rw-r--r-- | src/ollama_web/prompts/en.json | 18 | ||||
| -rw-r--r-- | src/ollama_web/prompts/ja.json | 18 |
3 files changed, 93 insertions, 0 deletions
diff --git a/src/ollama_web/prompts/__init__.py b/src/ollama_web/prompts/__init__.py new file mode 100644 index 0000000..59bdb48 --- /dev/null +++ b/src/ollama_web/prompts/__init__.py @@ -0,0 +1,57 @@ +"""Localized prompt management for LLM prompts. + +Prompts live in JSON files under ``prompts/``. The default language is read from +``config.settings.language`` and can be overridden per-call via the ``lang`` +argument. +""" + +from __future__ import annotations + +import json +from pathlib import Path +from typing import Any + +from ollama_web.config import settings + +_DIR = Path(__file__).resolve().parent + +_PROMPTS_CACHE: dict[str, dict[str, Any]] = {} + + +def _load_prompts(lang: str) -> dict[str, Any]: + """Load prompts for a language, falling back to an empty dict on error.""" + path = _DIR / f"{lang}.json" + try: + with path.open("r", encoding="utf-8") as f: + return json.load(f) + except (FileNotFoundError, json.JSONDecodeError): + return {} + + +def get_prompts(lang: str | None = None) -> dict[str, Any]: + """Return the full prompt dictionary for the requested language.""" + lang = lang or settings.language or "ja" + if lang not in _PROMPTS_CACHE: + _PROMPTS_CACHE[lang] = _load_prompts(lang) + return _PROMPTS_CACHE[lang] + + +def get_prompt(key: str, lang: str | None = None, fallback: str | None = None) -> str: + """Return a localized LLM prompt string. + + Args: + key: Dot-separated path, e.g. ``"tool_system"``. + lang: Optional language override. Uses ``settings.language`` when omitted. + fallback: Value returned when the key is missing. Defaults to the key itself. + + Returns: + The localized prompt string, or the fallback value if missing. + """ + current: Any = get_prompts(lang) + for part in key.split("."): + if not isinstance(current, dict) or part not in current: + return fallback if fallback is not None else key + current = current[part] + if isinstance(current, str): + return current + return fallback if fallback is not None else key diff --git a/src/ollama_web/prompts/en.json b/src/ollama_web/prompts/en.json new file mode 100644 index 0000000..53af74b --- /dev/null +++ b/src/ollama_web/prompts/en.json @@ -0,0 +1,18 @@ +{ + "tool_system": "You can use web search, scraping, and file fetch tools. Do not run more searches than necessary in a single response; review the results before conducting the next investigation. Tool results are summarized, so grasp the important points and use them effectively.", + "tool_limit_instruction": "The tool call limit has been reached. Based on the search results and conversation so far, please summarize the final answer the user requested.", + "attachment_prefix": "The following is the content of files attached by the user:", + "fetch": { + "candidate": "Candidate", + "title": "Title", + "status": "Status", + "fetch_failed": "Failed to fetch", + "type": "Type", + "size": "Size", + "chars": "Characters", + "separator": "---", + "no_results": "No {file_type} files found for query: {query}", + "empty_query": "Empty query.", + "invalid_type": "Invalid file type." + } +} diff --git a/src/ollama_web/prompts/ja.json b/src/ollama_web/prompts/ja.json new file mode 100644 index 0000000..40f6c7c --- /dev/null +++ b/src/ollama_web/prompts/ja.json @@ -0,0 +1,18 @@ +{ + "tool_system": "あなたはWeb検索・スクレイピング・ファイル取得ツールを利用できます。一度の回答で必要以上に多くの検索を同時に行わず、結果を確認してから次の調査を行ってください。各ツール結果は要約されて提供されるため、重要なポイントを把握して活用してください。", + "tool_limit_instruction": "ツール呼び出しの上限に達しました。これまでの検索結果と会話を元に、ユーザーが求めた回答を最終的にまとめてください。", + "attachment_prefix": "以下はユーザーが添付したファイルの内容です:", + "fetch": { + "candidate": "候補", + "title": "タイトル", + "status": "状態", + "fetch_failed": "取得失敗", + "type": "形式", + "size": "サイズ", + "chars": "文字数", + "separator": "---", + "no_results": "No {file_type} files found for query: {query}", + "empty_query": "Empty query.", + "invalid_type": "Invalid file type." + } +} |
