pr-context-engine 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ """Google Gemini-backed LLMProvider implementation (model: gemini-2.5-flash)."""
2
+ import logging
3
+
4
+ from google import genai
5
+
6
+ from src.llm.base import LLMProvider
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ _MODEL = "gemini-2.5-flash"
11
+
12
+
13
+ class GeminiProvider(LLMProvider):
14
+ """Calls the Gemini API via google-genai to satisfy the LLMProvider contract."""
15
+
16
+ def __init__(self, api_key: str) -> None:
17
+ """Build a Gemini client from an explicit API key."""
18
+ self._client = genai.Client(api_key=api_key)
19
+
20
+ def generate(self, prompt: str) -> str:
21
+ """Send `prompt` to Gemini and return the completion text."""
22
+ logger.info("Requesting Gemini completion (model=%s)", _MODEL)
23
+ response = self._client.models.generate_content(
24
+ model=_MODEL,
25
+ contents=prompt,
26
+ )
27
+ try:
28
+ text = response.text
29
+ except ValueError as exc:
30
+ raise RuntimeError("Gemini blocked the response (safety/recitation filter)") from exc
31
+ if not text:
32
+ raise RuntimeError("Gemini returned an empty completion")
33
+ return text
@@ -0,0 +1,30 @@
1
+ """Groq-backed LLMProvider implementation (model: llama-3.3-70b-versatile)."""
2
+ import logging
3
+
4
+ from groq import Groq
5
+
6
+ from src.llm.base import LLMProvider
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ _MODEL = "llama-3.3-70b-versatile"
11
+
12
+
13
+ class GroqProvider(LLMProvider):
14
+ """Calls the Groq chat-completions API to satisfy the LLMProvider contract."""
15
+
16
+ def __init__(self, api_key: str) -> None:
17
+ """Build a Groq client from an explicit API key."""
18
+ self._client = Groq(api_key=api_key)
19
+
20
+ def generate(self, prompt: str) -> str:
21
+ """Send `prompt` as a single user message and return the completion text."""
22
+ logger.info("Requesting Groq completion (model=%s)", _MODEL)
23
+ response = self._client.chat.completions.create(
24
+ model=_MODEL,
25
+ messages=[{"role": "user", "content": prompt}],
26
+ )
27
+ content = response.choices[0].message.content
28
+ if content is None:
29
+ raise RuntimeError("Groq returned an empty completion")
30
+ return content
@@ -0,0 +1,41 @@
1
+ """Ollama-backed LLMProvider for local development (default model: qwen2.5-coder:7b)."""
2
+ import logging
3
+
4
+ import requests
5
+
6
+ from src.llm.base import LLMProvider
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ _DEFAULT_BASE_URL = "http://localhost:11434"
11
+ _DEFAULT_MODEL = "qwen2.5-coder:7b"
12
+
13
+
14
+ class OllamaProvider(LLMProvider):
15
+ """Calls a local Ollama instance via REST to satisfy the LLMProvider contract.
16
+
17
+ No API key required — runs entirely offline. Suitable for dev/iteration.
18
+ """
19
+
20
+ def __init__(
21
+ self,
22
+ base_url: str = _DEFAULT_BASE_URL,
23
+ model: str = _DEFAULT_MODEL,
24
+ ) -> None:
25
+ """Configure the Ollama endpoint and model."""
26
+ self._base_url = base_url.rstrip("/")
27
+ self._model = model
28
+
29
+ def generate(self, prompt: str) -> str:
30
+ """POST the prompt to Ollama's /api/generate and return the response text."""
31
+ logger.info("Requesting Ollama completion (model=%s)", self._model)
32
+ response = requests.post(
33
+ f"{self._base_url}/api/generate",
34
+ json={"model": self._model, "prompt": prompt, "stream": False},
35
+ timeout=120,
36
+ )
37
+ response.raise_for_status()
38
+ text = response.json().get("response", "")
39
+ if not text:
40
+ raise RuntimeError("Ollama returned an empty response")
41
+ return text