forked from UT-InfraAI/ventis
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(llm-proxy): resolve $0 token costs and add Anthropic/OpenAI streaming (CAN-356) #112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5fdff53
fixed llm costs being zero and added streaming func to OpenAI/Anthropic
Saaketh0 65a69b5
made functions named better
Saaketh0 9b139f3
Small name change
Saaketh0 5cd1d99
Felipes comment fixes
Saaketh0 3c1fba6
Merge main into CAN-356-Fixing-Claude-GPT-Costs
Saaketh0 eb42e64
small explanation added
Saaketh0 5aae150
fix(llm-proxy): surface stream failures, harden proxy readiness, format
claude 07193bc
Simplified the code
Saaketh0 d5f5668
fix(llm-proxy): don't report healthy on proxy failure, tighten SSE ha…
claude b052e51
chore(llm-proxy): trim over-long comments
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
canyonos_core/controller/cloud_provider_logic/shared_utils/llm_proxy_env.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Single source of truth for the env vars that route an agent's LLM SDK calls | ||
| through the in-container LLM proxy (started by LocalController; see | ||
| canyonos_core/llm_proxy/). | ||
|
|
||
| Every LLM SDK/library reads a different env var name for its base URL -- there | ||
| is no universal name to standardize on, so all of them still have to be set. | ||
| What this module collapses is the VALUE: one PROXY_HOST constant, one place | ||
| that lists the var names, used by both the Local and EC2 runtime backends | ||
| instead of two independently hand-maintained copies of the same six lines. | ||
|
|
||
| See company-memory: "LLM proxy can infer the provider from the request; the | ||
| six base-URL variable names still cannot be collapsed" (CAN-343 analysis). | ||
| """ | ||
|
|
||
| # The proxy always runs on localhost inside the agent's own container. | ||
| PROXY_HOST = "http://127.0.0.1:8081" | ||
|
|
||
|
|
||
| def llm_proxy_env_vars(proxy_host: str = PROXY_HOST) -> dict: | ||
| """Return the {env_var_name: value} pairs that route Bedrock/OpenAI/Anthropic | ||
| SDK traffic through the in-container LLM proxy at `proxy_host`. | ||
| """ | ||
| return { | ||
| # boto3 (Bedrock) | ||
| "AWS_ENDPOINT_URL_BEDROCK_RUNTIME": f"{proxy_host}/bedrock", | ||
| # openai SDK | ||
| "OPENAI_BASE_URL": f"{proxy_host}/openai/v1", | ||
| # langchain_openai / llama_index | ||
| "OPENAI_API_BASE": f"{proxy_host}/openai/v1", | ||
| # anthropic SDK | ||
| "ANTHROPIC_BASE_URL": f"{proxy_host}/anthropic", | ||
| # langchain_anthropic | ||
| "ANTHROPIC_API_URL": f"{proxy_host}/anthropic", | ||
| # LiteLLM | ||
| "ANTHROPIC_API_BASE": f"{proxy_host}/anthropic", | ||
| } | ||
|
|
||
|
|
||
| def llm_proxy_docker_env_args(proxy_host: str = PROXY_HOST) -> list: | ||
| """Return `llm_proxy_env_vars` flattened into repeated `-e NAME=VALUE` pairs, | ||
| ready to splice into a `docker run` argument list. | ||
| """ | ||
| args = [] | ||
| for name, value in llm_proxy_env_vars(proxy_host).items(): | ||
| args.append("-e") | ||
| args.append(f"{name}={value}") | ||
| return args | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file renamed
BIN
+20 KB
...ore/controller/utils/aws_pricing_chart.db → ..._core/controller/utils/llm_token_costs.db
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.