Upgrade LLM deps, add Anthropic/Google providers, fix tiktoken crash … - #516
Conversation
|
Thank you for creating the PR. I think some of the test failures are due to |
|
@cybr-wisp, please see if you can resolve the conflicts with the main branch. Let me know if you have any questions. |
436c756 to
63f6b9d
Compare
|
Rebased on main and all conflicts resolved. The Anthropic/Google extras and tiktoken fix layer on top of the dependency work from #509. CI is awaiting approval to run. |
20001LastOrder
left a comment
There was a problem hiding this comment.
Thank you for the PR. Please see the comments below for improvement. The main idea is that we can create a wrapper for any LangChain models rather than creating a wrapper for each provider
| anthropic = ["langchain-anthropic"] | ||
| google = ["langchain-google-genai"] | ||
|
|
There was a problem hiding this comment.
These should probably be in the optional.dependencies below
| @@ -0,0 +1,80 @@ | |||
| """Anthropic chat model integration module for Sherpa AI.""" | |||
There was a problem hiding this comment.
Instead of creating one sherpa_<provider>.py for each provider. I'm thinking of having the following structure to accommodate any LLMs. The basic idea for Sherpa models is to provide user usage tracking. So we can add a new wrapper to any LangChain model, maybe a file called sherpa_llm.py. Then the structure could be something like:
class SherpaLLM(BaseChatModel):
_llm: BaseChatModel
#... Any additional attributes
@property
def _llm_type(self):
return self.llm._llm_type
def _generate(self, prompts, stop, run_manager, **kwargs):
response = self.llm._generate(prompts, stop, run_manager, **kwargs)
# Do any user tracking actions necessary
return response
...This way, we can avoid creating a new file for each potential future provider we want to support.
|
It seems the tests are also failing. Please rerun pyproject.toml changed significantly since poetry.lock was last generated. Run `poetry lock` to fix the lock file. |
3938c18 to
a8a20a8
Compare
|
Addressed all three items:
|
20001LastOrder
left a comment
There was a problem hiding this comment.
The Sherpa LLM looks good now. Only some cleaning up is needed.
| """Visualization tools for Sherpa AI. | ||
|
|
||
| This package provides visualization utilities for inspecting agent behavior, | ||
| state machine execution, and decision trajectories. | ||
| """ | ||
|
|
||
| from sherpa_ai.visualization.state_machine_viewer import StateMachineViewer | ||
|
|
||
| __all__ = ["StateMachineViewer"] No newline at end of file |
There was a problem hiding this comment.
I think this file was committed by accident? Please revert the change
| langchain-anthropic = {version = ">=1.0.0,<2.0", optional = true} | ||
| langchain-google-genai = {version = ">=2.0.0,<3.0", optional = true} | ||
|
|
||
| [tool.poetry.extras] | ||
| anthropic = ["langchain-anthropic"] | ||
| google = ["langchain-google-genai"] |
There was a problem hiding this comment.
These dependencies are still not changed
5df8a11 to
04cb844
Compare
|
Hey, both fixed now. Reverted the init.py (was a stray commit from another branch, my bad) and moved the deps to optional.dependencies properly this time. CI should be ready to run whenever you get a chance to approve it. |
Description:
Closes #511
The LLM dependencies were outdated -> langchain-openai was pinned to <0.3, langchain-anthropic and langchain-google-genai were missing entirely, and tiktoken crashed on non-OpenAI model names at utils.py:221.
What changed:
Bumped langchain-core (0.3.x → 1.4+), langchain-openai (0.2.x → 1.0+), langchain-community (0.3.x → 0.4+), tiktoken (0.6+ → 0.8+), langchain-chroma (0.2.x → 1.0+)
Added langchain-anthropic and langchain-google-genai as optional extras, installable via pip install sherpa-ai[anthropic] or pip install sherpa-ai[google]
Fixed tiktoken.encoding_for_model() crash by adding a try/except KeyError with cl100k_base fallback for non-OpenAI models
Created SherpaChatAnthropic and SherpaChatGoogle model wrappers following the existing SherpaChatOpenAI pattern
Fixed deprecated ChatOpenAI import in test_utils/llms.py (moved from langchain_community to langchain_openai)
Relaxed spacy version constraint for Python 3.13 compatibility
Regenerated poetry.lock
After pulling these changes, run:
poetry lock && poetry install --with test -E anthropic -E google
Note on test results: 242/306 tests pass. The 61 failures fall into three categories, none caused by this PR: Windows file-locking errors (PermissionError on .db teardown), missing optional tokenizers package, and pre-existing get_relevant_documents deprecation in upstream langchain.
Type of change:
New feature (non-breaking change that adds functionality)
Related issues:
Closes #511, related to #510