-
Notifications
You must be signed in to change notification settings - Fork 0
added bedrock llm connection #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||
| import os | ||||||
|
|
||||||
| try: | ||||||
| from ventis.utils.redis_client import RedisClient | ||||||
| import ventis.ventis_context as ventis_context | ||||||
| except ImportError: | ||||||
| from redis_client import RedisClient | ||||||
| import ventis_context | ||||||
|
|
||||||
| _redis = RedisClient( | ||||||
| host=os.environ.get("VENTIS_REDIS_HOST", "localhost"), | ||||||
| port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win Use a string environment default. Ruff PLW1508 flags the integer default passed to Proposed fix- port=int(os.environ.get("VENTIS_REDIS_PORT", 6379)),
+ port=int(os.environ.get("VENTIS_REDIS_PORT", "6379")),📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: CI / test[error] 12-12: Ruff PLW1508: Invalid type for environment variable default; expected 🤖 Prompt for AI AgentsSource: Pipeline failures |
||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def call_bedrock(model_id: str, messages: list, inference_config: dict, region: str = "us-east-1") -> dict: | ||||||
| """Call Bedrock's converse() API and log token/error telemetry onto the | ||||||
| currently executing future's Redis hash (future:<future_id>).""" | ||||||
| import boto3 | ||||||
|
|
||||||
| client = boto3.client("bedrock-runtime", region_name=region) | ||||||
| future_id = ventis_context.get_current_future_id() | ||||||
| error_count = 0 | ||||||
| response = None | ||||||
| try: | ||||||
| response = client.converse( | ||||||
| modelId=model_id, messages=messages, inferenceConfig=inference_config | ||||||
| ) | ||||||
| return response | ||||||
| except Exception: | ||||||
| # Counts failed attempts for this call. With no retry logic today this is | ||||||
| # always 0 or 1, matching `failed`; once retries are added, a call that | ||||||
| # eventually succeeds can still report error_count > 0 while failed stays 0. | ||||||
| error_count += 1 | ||||||
| agent_id = ventis_context.get_current_agent_id() | ||||||
| if agent_id: | ||||||
| _redis.client.incr(f"{agent_id}:llm_errors") | ||||||
| raise | ||||||
| finally: | ||||||
| if future_id: | ||||||
| usage = (response or {}).get("usage", {}) | ||||||
| _redis.hset_multiple(f"future:{future_id}", { | ||||||
| "model": model_id, | ||||||
| "input_token_count": str(usage.get("inputTokens", "")), | ||||||
| "output_token_count": str(usage.get("outputTokens", "")), | ||||||
| "token_count": str(usage.get("totalTokens", "")), | ||||||
| "errors": str(error_count), | ||||||
| "input_cache_tokens": str(usage.get("cacheReadInputTokens", "")), | ||||||
| "input_cache_write_tokens": str(usage.get("cacheWriteInputTokens", "")), | ||||||
| }) | ||||||
|
Comment on lines
+35
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Locate file and relevant symbols"
fd -a 'bedrock.py|redis.py|context.py' . | sed 's#^\./##' | head -100
echo
echo "Relevant source outline"
ast-grep outline ventis/llm/bedrock.py --view expanded || true
echo
echo "Relevant bedrock.py"
cat -n ventis/llm/bedrock.py | sed -n '1,140p'
echo
echo "Search for _redis usage"
rg -n "_redis\\.(incr|hset_multiple|get_client|client)|hset_multiple\\(" ventis -SRepository: CanyonCodeCoreAI/canyoncodecore Length of output: 3622 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "ventis/utils/redis_client.py"
cat -n ventis/utils/redis_client.py | sed -n '1,180p'
echo
echo "Search import and exception handling around call_bedrock"
rg -n "call_bedrock\\(|Bedrock|bedrock" ventis -S
echo
echo "Python exception semantics probe: exception in except/finally blocks and finally exception suppresses original"
python3 - <<'PY'
def original_error():
try:
raise RuntimeError("bedrock")
except RuntimeError as e:
raise RuntimeError("redis")
finally:
try:
original_error()
except RuntimeError:
...
try:
original_error()
except Exception as exc:
print(type(exc).__name__, str(exc))
print("has __cause__:", hasattr(exc, "__cause__"), getattr(exc, "__cause__", None))
PYRepository: CanyonCodeCoreAI/canyoncodecore Length of output: 4042 Make Redis telemetry best-effort and preserve Bedrock errors.
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -313,6 +313,7 @@ def generate_docker( | |||||
| "local_controller_frontend.py", | ||||||
| ), | ||||||
| (os.path.join(script_dir, "utils", "redis_client.py"), "redis_client.py"), | ||||||
| (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py,"), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Remove the trailing comma from the destination filename. This copies the module as 🐛 Proposed fix- (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py,"),
+ (os.path.join(script_dir, "llm", "bedrock.py"), "bedrock.py"),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| ] | ||||||
|
|
||||||
| # Copy provided agent stubs | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Fix the import block so CI passes.
Ruff reports I001 and PLR0402 here. Use the canonical package import and format both branches while preserving the intended fallback.
Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: CI / 0_test.txt
[error] 5-7: Ruff (PLR0402): Use
from ventis import ventis_contextin lieu of alias.🪛 GitHub Actions: CI / test
[error] 4-6: Ruff I001: Import block is un-sorted or un-formatted.
[error] 5-5: Ruff PLR0402: Use
from ventis import ventis_contextin lieu of alias.[error] 7-8: Ruff I001: Import block is un-sorted or un-formatted.
🤖 Prompt for AI Agents
Source: Pipeline failures