Compare commits

..

3 Commits

Author SHA1 Message Date
Brandon Hancock (bhancock_ai)
9aad450b4a Merge branch 'main' into brandon/gemini-google-docs 2025-02-10 12:11:16 -05:00
Brandon Hancock (bhancock_ai)
612119f114 Merge branch 'main' into brandon/gemini-google-docs 2025-02-10 12:01:33 -05:00
Brandon Hancock
5b1d200b5b incorporate Small update in memory.mdx, fixing Google AI parameters #2008 2025-02-10 10:13:46 -05:00
3 changed files with 2 additions and 107 deletions

View File

@@ -447,38 +447,6 @@ my_crew = Crew(
)
```
### Using Amazon Bedrock embeddings
```python Code
# Note: Ensure you have installed `boto3` for Bedrock embeddings to work.
import os
import boto3
from crewai import Crew, Agent, Task, Process
boto3_session = boto3.Session(
region_name=os.environ.get("AWS_REGION_NAME"),
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY")
)
my_crew = Crew(
agents=[...],
tasks=[...],
process=Process.sequential,
memory=True,
embedder={
"provider": "bedrock",
"config":{
"session": boto3_session,
"model": "amazon.titan-embed-text-v2:0",
"vector_dimension": 1024
}
}
verbose=True
)
```
### Adding Custom Embedding Function
```python Code

View File

@@ -117,39 +117,6 @@ def suppress_warnings():
class LLM:
"""LLM class for handling model interactions.
Args:
model: The model identifier; should not start with 'models/'.
Examples: 'gemini/gemini-1.5-pro', 'anthropic/claude-3'
timeout: Optional timeout for model calls
temperature: Optional temperature parameter
max_tokens: Optional maximum tokens for completion
max_completion_tokens: Optional maximum completion tokens
logprobs: Optional log probabilities
top_p: Optional nucleus sampling parameter
n: Optional number of completions
stop: Optional stop sequences
presence_penalty: Optional presence penalty
frequency_penalty: Optional frequency penalty
logit_bias: Optional token biasing
user: Optional user identifier
response_format: Optional response format configuration
seed: Optional random seed
tools: Optional list of tools
tool_choice: Optional tool choice configuration
api_base: Optional API base URL
api_key: Optional API key
api_version: Optional API version
base_url: Optional base URL
top_logprobs: Optional top log probabilities
callbacks: Optional list of callbacks
reasoning_effort: Optional reasoning effort level
Raises:
ValueError: If the model name starts with 'models/' or is empty
TypeError: If model is not a string
"""
def __init__(
self,
model: str,
@@ -175,20 +142,6 @@ class LLM:
reasoning_effort: Optional[Literal["none", "low", "medium", "high"]] = None,
**kwargs,
):
# Constants for model name validation
INVALID_MODEL_PREFIX = "models/"
# Validate model name
if not isinstance(model, str):
raise TypeError("Model name must be a string")
if not model:
raise ValueError("Model name cannot be empty")
if model.startswith(INVALID_MODEL_PREFIX):
raise ValueError(
f'Invalid model name "{model}": Model names should not start with "{INVALID_MODEL_PREFIX}". '
'Use the provider prefix instead (e.g., "gemini/model-name").'
)
self.model = model
self.timeout = timeout
self.temperature = temperature

View File

@@ -252,29 +252,6 @@ def test_validate_call_params_no_response_format():
llm._validate_call_params()
class TestModelNameValidation:
"""Tests for model name validation in LLM class."""
def test_models_prefix_rejection(self):
"""Test that model names with 'models/' prefix are rejected."""
with pytest.raises(ValueError, match="should not start with \"models/\""):
LLM(model="models/gemini/gemini-1.5-pro")
def test_valid_model_names(self):
"""Test that valid model names are accepted."""
LLM(model="gemini/gemini-1.5-pro")
LLM(model="anthropic/claude-3-opus-20240229-v1:0")
LLM(model="openai/gpt-4")
LLM(model="openai/gpt-4 turbo") # Space in model name should work
def test_edge_cases(self):
"""Test edge cases for model name validation."""
with pytest.raises(ValueError, match="cannot be empty"):
LLM(model="") # Empty string
with pytest.raises(TypeError, match="must be a string"):
LLM(model=None) # None value
@pytest.mark.vcr(filter_headers=["authorization"])
def test_o3_mini_reasoning_effort_high():
llm = LLM(
@@ -347,16 +324,13 @@ def test_anthropic_model_detection():
("claude-instant", True),
("claude/v1", True),
("gpt-4", False),
("", False),
("anthropomorphic", False), # Should not match partial words
]
for model, expected in models:
llm = LLM(model=model)
assert llm._is_anthropic_model(model) == expected, f"Failed for model: {model}"
# Test empty model name separately since it raises ValueError
with pytest.raises(ValueError, match="cannot be empty"):
LLM(model="")
assert llm.is_anthropic == expected, f"Failed for model: {model}"
def test_anthropic_message_formatting(anthropic_llm, system_message, user_message):
"""Test Anthropic message formatting with fixtures."""