mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-01 23:00:41 +00:00
Apply patch [skip ci]
This commit is contained in:
@@ -3,59 +3,34 @@
|
||||
|
||||
import re
|
||||
|
||||
def fix_base_py_imports():
|
||||
"""Fix missing imports in base.py"""
|
||||
def fix_base_py_type_annotations():
|
||||
"""Fix type annotations to use modern syntax"""
|
||||
file_path = '/home/daytona/langchain/libs/partners/openai/langchain_openai/chat_models/base.py'
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Add List and Dict to the typing imports
|
||||
old_imports = """from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Callable,
|
||||
Literal,
|
||||
Optional,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
Union,
|
||||
cast,
|
||||
)"""
|
||||
# Remove Dict and List from imports since we'll use lowercase versions
|
||||
content = re.sub(r'(\s+)Dict,\n', '', content)
|
||||
content = re.sub(r'(\s+)List,\n', '', content)
|
||||
|
||||
new_imports = """from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
List,
|
||||
Literal,
|
||||
Optional,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
Union,
|
||||
cast,
|
||||
)"""
|
||||
# Replace type annotations
|
||||
content = re.sub(r'List\[List\[BaseMessage\]\]', 'list[list[BaseMessage]]', content)
|
||||
content = re.sub(r'Dict\[str, str\]', 'dict[str, str]', content)
|
||||
content = re.sub(r'List\[ChatResult\]', 'list[ChatResult]', content)
|
||||
|
||||
if old_imports in content:
|
||||
content = content.replace(old_imports, new_imports)
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(content)
|
||||
print("Fixed imports in base.py")
|
||||
return True
|
||||
else:
|
||||
print("Could not find import section to fix in base.py")
|
||||
return False
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(content)
|
||||
print("Fixed type annotations in base.py")
|
||||
|
||||
def fix_integration_test_lines():
|
||||
"""Fix line length issues in integration tests"""
|
||||
def fix_integration_test_issues():
|
||||
"""Fix all issues in integration tests"""
|
||||
file_path = '/home/daytona/langchain/libs/partners/openai/tests/integration_tests/chat_models/test_batch_integration.py'
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Fix long lines
|
||||
# Fix long lines by breaking them
|
||||
content = content.replace(
|
||||
'content="What is the capital of France? Answer with just the city name."',
|
||||
'content="What is the capital of France? Answer with just the city name."'
|
||||
@@ -66,25 +41,38 @@ def fix_integration_test_lines():
|
||||
'content="What is the smallest planet? Answer with just the planet name."'
|
||||
)
|
||||
|
||||
# Remove print statements
|
||||
content = re.sub(r'\s*print\(f?"[^"]*"\)\s*\n', '', content)
|
||||
# Fix unused variables by using underscore
|
||||
content = re.sub(r'sequential_time = time\.time\(\) - start_sequential',
|
||||
'_ = time.time() - start_sequential', content)
|
||||
content = re.sub(r'batch_time = time\.time\(\) - start_batch',
|
||||
'_ = time.time() - start_batch', content)
|
||||
|
||||
# Fix long comment line
|
||||
content = content.replace(
|
||||
' # Log timing comparison # Note: Batch API will typically be slower for small batches due to polling,',
|
||||
' # Note: Batch API will typically be slower for small batches due to polling,'
|
||||
)
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(content)
|
||||
print("Fixed integration test issues")
|
||||
|
||||
def fix_unit_test_issues():
|
||||
"""Fix unused variable in unit tests"""
|
||||
"""Fix all issues in unit tests"""
|
||||
file_path = '/home/daytona/langchain/libs/partners/openai/tests/unit_tests/chat_models/test_batch.py'
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Fix unused variable by using it or removing assignment
|
||||
content = content.replace(
|
||||
'results = self.llm.batch(inputs, use_batch_api=True)',
|
||||
'_ = self.llm.batch(inputs, use_batch_api=True)'
|
||||
)
|
||||
# Fix the test that has undefined results variable
|
||||
# Find the test method and fix it properly
|
||||
pattern = r'(\s+)_ = self\.llm\.batch\(inputs, use_batch_api=True\)\s*\n\s*# Verify conversion happened\s*\n\s*assert len\(results\) == num_requests'
|
||||
replacement = r'\1results = self.llm.batch(inputs, use_batch_api=True)\n\1# Verify conversion happened\n\1assert len(results) == num_requests'
|
||||
content = re.sub(pattern, replacement, content)
|
||||
|
||||
# Fix other undefined results references
|
||||
content = re.sub(r'(\s+)_ = self\.llm\.batch\(inputs, use_batch_api=True\)\s*\n(\s+)assert len\(results\) == 2',
|
||||
r'\1results = self.llm.batch(inputs, use_batch_api=True)\n\2assert len(results) == 2', content)
|
||||
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(content)
|
||||
@@ -92,7 +80,8 @@ def fix_unit_test_issues():
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Fixing linting issues...")
|
||||
fix_base_py_imports()
|
||||
fix_integration_test_lines()
|
||||
fix_base_py_type_annotations()
|
||||
fix_integration_test_issues()
|
||||
fix_unit_test_issues()
|
||||
print("All linting issues fixed!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user