method_name stringlengths 1 78 | method_body stringlengths 3 9.66k | full_code stringlengths 31 10.7k | docstring stringlengths 4 4.74k ⌀ |
|---|---|---|---|
draw | """
CPAL chain can draw its resulting DAG.
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> cpal_chain.draw(path="graph.svg")
>>> SVG('graph.svg')
"""
self._story._networkx_wrapper.draw_graphviz(**kwargs) | def draw(self, **kwargs: Any) ->None:
"""
CPAL chain can draw its resulting DAG.
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> cpal_chain.draw(path="graph.svg")
>>> SVG('graph.svg')
"""
self._story._networkx_wrapper.draw_graphv... | CPAL chain can draw its resulting DAG.
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> cpal_chain.draw(path="graph.svg")
>>> SVG('graph.svg') |
similarity_search | """Return docs most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 4.
filter: (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
fetch_k: (Optional[int]) Number of Documents to fet... | def similarity_search(self, query: str, k: int=4, filter: Optional[Dict[str,
Any]]=None, fetch_k: int=20, **kwargs: Any) ->List[Document]:
"""Return docs most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 4.
... | Return docs most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 4.
filter: (Optional[Dict[str, str]]): Filter by metadata. Defaults to None.
fetch_k: (Optional[int]) Number of Documents to fetch before filtering.
Defaults... |
on_llm_start | """Run when LLM starts running.""" | def on_llm_start(self, serialized: Dict[str, Any], prompts: List[str], **
kwargs: Any) ->None:
"""Run when LLM starts running.""" | Run when LLM starts running. |
cosine_similarity_top_k | """Row-wise cosine similarity with optional top-k and score threshold filtering.
Args:
X: Matrix.
Y: Matrix, same width as X.
top_k: Max number of results to return.
score_threshold: Minimum cosine similarity of results.
Returns:
Tuple of two lists. First contains two-t... | def cosine_similarity_top_k(X: Matrix, Y: Matrix, top_k: Optional[int]=5,
score_threshold: Optional[float]=None) ->Tuple[List[Tuple[int, int]],
List[float]]:
"""Row-wise cosine similarity with optional top-k and score threshold filtering.
Args:
X: Matrix.
Y: Matrix, same width as X.
... | Row-wise cosine similarity with optional top-k and score threshold filtering.
Args:
X: Matrix.
Y: Matrix, same width as X.
top_k: Max number of results to return.
score_threshold: Minimum cosine similarity of results.
Returns:
Tuple of two lists. First contains two-tuples of indices (X_idx, Y_idx)... |
_import_zapier_tool_ZapierNLAListActions | from langchain_community.tools.zapier.tool import ZapierNLAListActions
return ZapierNLAListActions | def _import_zapier_tool_ZapierNLAListActions() ->Any:
from langchain_community.tools.zapier.tool import ZapierNLAListActions
return ZapierNLAListActions | null |
test_model_response | msg = AIMessage(content='Model response.')
result = _parse_ai_message(msg)
assert isinstance(result, AgentFinish)
assert result.return_values == {'output': 'Model response.'}
assert result.log == 'Model response.' | def test_model_response(self) ->None:
msg = AIMessage(content='Model response.')
result = _parse_ai_message(msg)
assert isinstance(result, AgentFinish)
assert result.return_values == {'output': 'Model response.'}
assert result.log == 'Model response.' | null |
__init__ | super().__init__(**kwargs)
self.function_callback = function | def __init__(self, function: Callable[[str], None], **kwargs: Any) ->None:
super().__init__(**kwargs)
self.function_callback = function | null |
_import_requests_tool_RequestsPatchTool | from langchain_community.tools.requests.tool import RequestsPatchTool
return RequestsPatchTool | def _import_requests_tool_RequestsPatchTool() ->Any:
from langchain_community.tools.requests.tool import RequestsPatchTool
return RequestsPatchTool | null |
__repr__ | map_for_repr = ',\n '.join(
f"{k}: {indent_lines_after_first(repr(v), ' ' + k + ': ')}" for k, v in
self.steps.items())
return '{\n ' + map_for_repr + '\n}' | def __repr__(self) ->str:
map_for_repr = ',\n '.join(
f"{k}: {indent_lines_after_first(repr(v), ' ' + k + ': ')}" for k,
v in self.steps.items())
return '{\n ' + map_for_repr + '\n}' | null |
__init__ | self.json_data = json_data
self.status_code = status_code | def __init__(self, json_data: Dict, status_code: int):
self.json_data = json_data
self.status_code = status_code | null |
call | """call."""
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' +
self.endpoint_api_key}
if self.deployment_name != '':
headers['azureml-model-deployment'] = self.deployment_name
req = urllib.request.Request(self.endpoint_url, body, headers)
response = urllib.request.urlopen(req, timeout=k... | def call(self, body: bytes, **kwargs: Any) ->bytes:
"""call."""
headers = {'Content-Type': 'application/json', 'Authorization':
'Bearer ' + self.endpoint_api_key}
if self.deployment_name != '':
headers['azureml-model-deployment'] = self.deployment_name
req = urllib.request.Request(self.... | call. |
test_scann_vector_sim_with_score_threshold | """Test vector similarity."""
texts = ['foo', 'bar', 'baz']
docsearch = ScaNN.from_texts(texts, FakeEmbeddings())
index_to_id = docsearch.index_to_docstore_id
expected_docstore = InMemoryDocstore({index_to_id[0]: Document(page_content
='foo'), index_to_id[1]: Document(page_content='bar'), index_to_id[2]:
Docume... | def test_scann_vector_sim_with_score_threshold() ->None:
"""Test vector similarity."""
texts = ['foo', 'bar', 'baz']
docsearch = ScaNN.from_texts(texts, FakeEmbeddings())
index_to_id = docsearch.index_to_docstore_id
expected_docstore = InMemoryDocstore({index_to_id[0]: Document(
page_content... | Test vector similarity. |
test_qdrant_similarity_search_with_relevance_score_no_threshold | """Test end to end construction and search."""
texts = ['foo', 'bar', 'baz']
metadatas = [{'page': i, 'metadata': {'page': i + 1, 'pages': [i + 2, -1]}} for
i in range(len(texts))]
docsearch = Qdrant.from_texts(texts, ConsistentFakeEmbeddings(), metadatas=
metadatas, location=':memory:', vector_name=vector_name... | @pytest.mark.parametrize('vector_name', [None, 'my-vector'])
def test_qdrant_similarity_search_with_relevance_score_no_threshold(vector_name
: Optional[str]) ->None:
"""Test end to end construction and search."""
texts = ['foo', 'bar', 'baz']
metadatas = [{'page': i, 'metadata': {'page': i + 1, 'pages':... | Test end to end construction and search. |
full_table_id | return self._full_table_id | @property
def full_table_id(self) ->str:
return self._full_table_id | null |
test_results_with_custom_params | """Test that call gives correct answer with custom params."""
search = SearchApiAPIWrapper()
output = search.results('cafeteria', hl='es', gl='es', google_domain=
'google.es', location='Madrid, Spain')
assert 'Madrid' in output['search_information']['detected_location'] | def test_results_with_custom_params() ->None:
"""Test that call gives correct answer with custom params."""
search = SearchApiAPIWrapper()
output = search.results('cafeteria', hl='es', gl='es', google_domain=
'google.es', location='Madrid, Spain')
assert 'Madrid' in output['search_information'][... | Test that call gives correct answer with custom params. |
test_pgvector_max_marginal_relevance_search_with_score | """Test max marginal relevance search with relevance scores."""
texts = ['foo', 'bar', 'baz']
docsearch = PGVector.from_texts(texts=texts, collection_name=
'test_collection', embedding=FakeEmbeddingsWithAdaDimension(),
connection_string=CONNECTION_STRING, pre_delete_collection=True)
output = docsearch.max_margi... | def test_pgvector_max_marginal_relevance_search_with_score() ->None:
"""Test max marginal relevance search with relevance scores."""
texts = ['foo', 'bar', 'baz']
docsearch = PGVector.from_texts(texts=texts, collection_name=
'test_collection', embedding=FakeEmbeddingsWithAdaDimension(),
conn... | Test max marginal relevance search with relevance scores. |
search_results | from zep_python import MemorySearchResult, Message
search_result = [{'message': {'uuid':
'66830914-19f5-490b-8677-1ba06bcd556b', 'created_at':
'2023-05-18T20:40:42.743773Z', 'role': 'user', 'content':
"I'm looking to plan a trip to Iceland. Can you help me?",
'token_count': 17}, 'summary': None, 'dist':... | @pytest.fixture
def search_results() ->List[MemorySearchResult]:
from zep_python import MemorySearchResult, Message
search_result = [{'message': {'uuid':
'66830914-19f5-490b-8677-1ba06bcd556b', 'created_at':
'2023-05-18T20:40:42.743773Z', 'role': 'user', 'content':
"I'm looking to plan a... | null |
_get_dataforseo_api_search_json | return DataForSeoAPISearchResults(api_wrapper=DataForSeoAPIWrapper(**kwargs)) | def _get_dataforseo_api_search_json(**kwargs: Any) ->BaseTool:
return DataForSeoAPISearchResults(api_wrapper=DataForSeoAPIWrapper(**
kwargs)) | null |
test_placeholder | """Used for compiling integration tests without running any real tests."""
pass | @pytest.mark.compile
def test_placeholder() ->None:
"""Used for compiling integration tests without running any real tests."""
pass | Used for compiling integration tests without running any real tests. |
__init__ | """Initialize with access token, ids, and key.
Args:
access_token: The access token for the Figma REST API.
ids: The ids of the Figma file.
key: The key for the Figma file
"""
self.access_token = access_token
self.ids = ids
self.key = key | def __init__(self, access_token: str, ids: str, key: str):
"""Initialize with access token, ids, and key.
Args:
access_token: The access token for the Figma REST API.
ids: The ids of the Figma file.
key: The key for the Figma file
"""
self.access_token = acce... | Initialize with access token, ids, and key.
Args:
access_token: The access token for the Figma REST API.
ids: The ids of the Figma file.
key: The key for the Figma file |
_identifying_params | """Get the identifying parameters."""
return {**{'model_path': self.model_path}, **self._default_params} | @property
def _identifying_params(self) ->Dict[str, Any]:
"""Get the identifying parameters."""
return {**{'model_path': self.model_path}, **self._default_params} | Get the identifying parameters. |
__init__ | """Initialize the parser.
Args:
text_kwargs: Keyword arguments to pass to ``pdfplumber.Page.extract_text()``
dedupe: Avoiding the error of duplicate characters if `dedupe=True`.
"""
self.text_kwargs = text_kwargs or {}
self.dedupe = dedupe
self.extract_images = extract_images | def __init__(self, text_kwargs: Optional[Mapping[str, Any]]=None, dedupe:
bool=False, extract_images: bool=False) ->None:
"""Initialize the parser.
Args:
text_kwargs: Keyword arguments to pass to ``pdfplumber.Page.extract_text()``
dedupe: Avoiding the error of duplicate characte... | Initialize the parser.
Args:
text_kwargs: Keyword arguments to pass to ``pdfplumber.Page.extract_text()``
dedupe: Avoiding the error of duplicate characters if `dedupe=True`. |
test_mget | store = UpstashRedisByteStore(client=redis_client, ttl=None)
keys = ['key1', 'key2']
redis_client.mset({'key1': 'value1', 'key2': 'value2'})
result = store.mget(keys)
assert result == [b'value1', b'value2'] | def test_mget(redis_client: Redis) ->None:
store = UpstashRedisByteStore(client=redis_client, ttl=None)
keys = ['key1', 'key2']
redis_client.mset({'key1': 'value1', 'key2': 'value2'})
result = store.mget(keys)
assert result == [b'value1', b'value2'] | null |
_identifying_params | """Gets the identifying parameters."""
return {**{'model_name': self.model_name}, **self._default_params} | @property
def _identifying_params(self) ->Dict[str, Any]:
"""Gets the identifying parameters."""
return {**{'model_name': self.model_name}, **self._default_params} | Gets the identifying parameters. |
_identifying_params | """Get the identifying parameters."""
return {**{'model_name': self.model_name}, **self._default_params} | @property
def _identifying_params(self) ->Dict[str, Any]:
"""Get the identifying parameters."""
return {**{'model_name': self.model_name}, **self._default_params} | Get the identifying parameters. |
__getitem__ | return getattr(self, item) | def __getitem__(self, item: str) ->Any:
return getattr(self, item) | null |
_import_supabase | from langchain_community.vectorstores.supabase import SupabaseVectorStore
return SupabaseVectorStore | def _import_supabase() ->Any:
from langchain_community.vectorstores.supabase import SupabaseVectorStore
return SupabaseVectorStore | null |
assert_docs | for doc in docs:
assert doc.metadata
assert set(doc.metadata) == {'Copyright Information', 'uid', 'Title',
'Published'} | def assert_docs(docs: List[Document]) ->None:
for doc in docs:
assert doc.metadata
assert set(doc.metadata) == {'Copyright Information', 'uid',
'Title', 'Published'} | null |
__init__ | """Initialize with bagel client"""
try:
import bagel
import bagel.config
except ImportError:
raise ImportError('Please install bagel `pip install betabageldb`.')
if client is not None:
self._client_settings = client_settings
self._client = client
else:
if client_settings:
_client_setting... | def __init__(self, cluster_name: str=_LANGCHAIN_DEFAULT_CLUSTER_NAME,
client_settings: Optional[bagel.config.Settings]=None,
embedding_function: Optional[Embeddings]=None, cluster_metadata:
Optional[Dict]=None, client: Optional[bagel.Client]=None,
relevance_score_fn: Optional[Callable[[float], float]]=N... | Initialize with bagel client |
__from | if metric not in INDEX_METRICS:
raise ValueError(
f'Unsupported distance metric: {metric}. Expected one of {list(INDEX_METRICS)}'
)
tiledb_vs, tiledb = dependable_tiledb_import()
input_vectors = np.array(embeddings).astype(np.float32)
cls.create(index_uri=index_uri, index_type=index_type, dimensions... | @classmethod
def __from(cls, texts: List[str], embeddings: List[List[float]], embedding:
Embeddings, index_uri: str, *, metadatas: Optional[List[dict]]=None,
ids: Optional[List[str]]=None, metric: str=DEFAULT_METRIC, index_type:
str='FLAT', config: Optional[Mapping[str, Any]]=None, index_timestamp:
int=... | null |
visit_comparison | if isinstance(comparison.value, list):
return self.visit_operation(Operation(operator=Operator.AND, arguments=
(Comparison(comparator=comparison.comparator, attribute=comparison.
attribute, value=value) for value in comparison.value)))
return '.'.join([
f'{self.metadata_column}{self._get_json_op... | def visit_comparison(self, comparison: Comparison) ->str:
if isinstance(comparison.value, list):
return self.visit_operation(Operation(operator=Operator.AND,
arguments=(Comparison(comparator=comparison.comparator,
attribute=comparison.attribute, value=value) for value in
... | null |
get_named_result | """
Get a named result from a query.
Args:
connection: The connection to the database
query: The query to execute
Returns:
List[dict[str, Any]]: The result of the query
"""
cursor = connection.cursor()
cursor.execute(query)
columns = cursor.description
result = []
for value in c... | def get_named_result(connection: Any, query: str) ->List[dict[str, Any]]:
"""
Get a named result from a query.
Args:
connection: The connection to the database
query: The query to execute
Returns:
List[dict[str, Any]]: The result of the query
"""
cursor = connection.curs... | Get a named result from a query.
Args:
connection: The connection to the database
query: The query to execute
Returns:
List[dict[str, Any]]: The result of the query |
input_keys | extra_keys = [k for k in self.llm_chain.input_keys if k != self.
document_variable_name]
return super().input_keys + extra_keys | @property
def input_keys(self) ->List[str]:
extra_keys = [k for k in self.llm_chain.input_keys if k != self.
document_variable_name]
return super().input_keys + extra_keys | null |
_import_promptlayer_chat | from langchain_community.llms.promptlayer_openai import PromptLayerOpenAIChat
return PromptLayerOpenAIChat | def _import_promptlayer_chat() ->Any:
from langchain_community.llms.promptlayer_openai import PromptLayerOpenAIChat
return PromptLayerOpenAIChat | null |
elasticsearch_connection | from elasticsearch import Elasticsearch
es_url = os.environ.get('ES_URL', 'http://localhost:9200')
cloud_id = os.environ.get('ES_CLOUD_ID')
es_username = os.environ.get('ES_USERNAME', 'elastic')
es_password = os.environ.get('ES_PASSWORD', 'changeme')
if cloud_id:
es = Elasticsearch(cloud_id=cloud_id, basic_auth=(es... | @pytest.fixture(scope='class', autouse=True)
def elasticsearch_connection(self) ->Union[dict, Generator[dict, None, None]]:
from elasticsearch import Elasticsearch
es_url = os.environ.get('ES_URL', 'http://localhost:9200')
cloud_id = os.environ.get('ES_CLOUD_ID')
es_username = os.environ.get('ES_USERNAM... | null |
on_llm_start | """Run when LLM starts."""
self.step += 1
self.llm_starts += 1
self.starts += 1
metadata = self._init_resp()
metadata.update({'action': 'on_llm_start'})
metadata.update(flatten_dict(serialized))
metadata.update(self.get_custom_callback_meta())
for prompt in prompts:
prompt_resp = deepcopy(metadata)
prompt_resp[... | def on_llm_start(self, serialized: Dict[str, Any], prompts: List[str], **
kwargs: Any) ->None:
"""Run when LLM starts."""
self.step += 1
self.llm_starts += 1
self.starts += 1
metadata = self._init_resp()
metadata.update({'action': 'on_llm_start'})
metadata.update(flatten_dict(serialized)... | Run when LLM starts. |
test_pickbest_textembedder_more_namespaces_w_full_label_w_partial_emakeep | feature_embedder = pick_best_chain.PickBestFeatureEmbedder(auto_embed=False,
model=MockEncoder())
str1 = '0'
str2 = '1'
str3 = '2'
encoded_str1 = rl_chain.stringify_embedding(list(encoded_keyword + str1))
encoded_str3 = rl_chain.stringify_embedding(list(encoded_keyword + str3))
ctx_str_1 = 'context1'
ctx_str_2 = 'c... | @pytest.mark.requires('vowpal_wabbit_next')
def test_pickbest_textembedder_more_namespaces_w_full_label_w_partial_emakeep(
) ->None:
feature_embedder = pick_best_chain.PickBestFeatureEmbedder(auto_embed=
False, model=MockEncoder())
str1 = '0'
str2 = '1'
str3 = '2'
encoded_str1 = rl_chain... | null |
test_get_nfts_valid_contract | max_alchemy_tokens = 100
contract_address = '0x1a92f7381b9f03921564a437210bb9396471050c'
result = BlockchainDocumentLoader(contract_address).load()
print('Tokens returned for valid contract: ', len(result))
assert len(result
) == max_alchemy_tokens, f'Wrong number of NFTs returned. Expected {max_alchemy_tokens}, g... | @pytest.mark.skipif(not alchemyKeySet, reason='Alchemy API key not provided.')
def test_get_nfts_valid_contract() ->None:
max_alchemy_tokens = 100
contract_address = '0x1a92f7381b9f03921564a437210bb9396471050c'
result = BlockchainDocumentLoader(contract_address).load()
print('Tokens returned for valid c... | null |
_format_func | self._validate_func(func)
comp_operator_map = {Comparator.EQ: 'term', Comparator.LT: 'lt', Comparator
.LTE: 'lte', Comparator.GT: 'gt', Comparator.GTE: 'gte', Comparator.
CONTAIN: 'match', Comparator.LIKE: 'fuzzy', Operator.AND: 'must',
Operator.OR: 'should', Operator.NOT: 'must_not'}
return comp_operator_m... | def _format_func(self, func: Union[Operator, Comparator]) ->str:
self._validate_func(func)
comp_operator_map = {Comparator.EQ: 'term', Comparator.LT: 'lt',
Comparator.LTE: 'lte', Comparator.GT: 'gt', Comparator.GTE: 'gte',
Comparator.CONTAIN: 'match', Comparator.LIKE: 'fuzzy', Operator.AND:
... | null |
on_chain_error | if parent_run_id is None:
self.increment() | def on_chain_error(self, error: BaseException, *, run_id: UUID,
parent_run_id: Optional[UUID]=None, **kwargs: Any) ->Any:
if parent_run_id is None:
self.increment() | null |
endpoint_path | return self.client.endpoint_path(project=self.project, location=self.
location, endpoint=self.endpoint_id) | @property
def endpoint_path(self) ->str:
return self.client.endpoint_path(project=self.project, location=self.
location, endpoint=self.endpoint_id) | null |
wait_for_futures | """Wait for all futures to complete."""
wait(self.futures) | def wait_for_futures(self) ->None:
"""Wait for all futures to complete."""
wait(self.futures) | Wait for all futures to complete. |
test__convert_message_to_dict_system | message = SystemMessage(content='foo')
with pytest.raises(TypeError) as e:
_convert_message_to_dict(message)
assert 'Got unknown type' in str(e) | def test__convert_message_to_dict_system() ->None:
message = SystemMessage(content='foo')
with pytest.raises(TypeError) as e:
_convert_message_to_dict(message)
assert 'Got unknown type' in str(e) | null |
import_mlflow | """Import the mlflow python package and raise an error if it is not installed."""
try:
import mlflow
except ImportError:
raise ImportError(
'To use the mlflow callback manager you need to have the `mlflow` python package installed. Please install it with `pip install mlflow>=2.3.0`'
)
return mlf... | def import_mlflow() ->Any:
"""Import the mlflow python package and raise an error if it is not installed."""
try:
import mlflow
except ImportError:
raise ImportError(
'To use the mlflow callback manager you need to have the `mlflow` python package installed. Please install it wit... | Import the mlflow python package and raise an error if it is not installed. |
combine_documents | """
Combine a list of documents into a single string that might be passed further down
to a language model.
:param documents: list of documents to combine
:return:
"""
formatter = Formatter()
return '\n\n'.join(formatter.format(document_template, page_content=
document.page_content, metadata=doc... | def combine_documents(documents: List[Document]) ->str:
"""
Combine a list of documents into a single string that might be passed further down
to a language model.
:param documents: list of documents to combine
:return:
"""
formatter = Formatter()
return '\n\n'.join(formatter.format(docu... | Combine a list of documents into a single string that might be passed further down
to a language model.
:param documents: list of documents to combine
:return: |
on_chain_error | """Run when chain errors."""
self.step += 1
self.errors += 1 | def on_chain_error(self, error: BaseException, **kwargs: Any) ->None:
"""Run when chain errors."""
self.step += 1
self.errors += 1 | Run when chain errors. |
step | """Take step."""
response = self.chain.run(**inputs, callbacks=callbacks)
return StepResponse(response=response) | def step(self, inputs: dict, callbacks: Callbacks=None, **kwargs: Any
) ->StepResponse:
"""Take step."""
response = self.chain.run(**inputs, callbacks=callbacks)
return StepResponse(response=response) | Take step. |
from_texts | """
Create and initialize a Bagel instance from list of texts.
Args:
texts (List[str]): List of text content to be added.
cluster_name (str): The name of the BagelDB cluster.
client_settings (Optional[bagel.config.Settings]): Client settings.
cluster_meta... | @classmethod
def from_texts(cls: Type[Bagel], texts: List[str], embedding: Optional[
Embeddings]=None, metadatas: Optional[List[dict]]=None, ids: Optional[
List[str]]=None, cluster_name: str=_LANGCHAIN_DEFAULT_CLUSTER_NAME,
client_settings: Optional[bagel.config.Settings]=None, cluster_metadata:
Optiona... | Create and initialize a Bagel instance from list of texts.
Args:
texts (List[str]): List of text content to be added.
cluster_name (str): The name of the BagelDB cluster.
client_settings (Optional[bagel.config.Settings]): Client settings.
cluster_metadata (Optional[Dict]): Metadata of the cluster.
... |
test_extract_paragraphs | html2text_transformer = Html2TextTransformer()
paragraphs_html = (
'<html><h1>Header</h1><p>First paragraph.</p><p>Second paragraph.</p><h1>Ignore at end</h1></html>'
)
documents = [Document(page_content=paragraphs_html)]
docs_transformed = html2text_transformer.transform_documents(documents)
assert docs_transf... | @pytest.mark.requires('html2text')
def test_extract_paragraphs() ->None:
html2text_transformer = Html2TextTransformer()
paragraphs_html = (
'<html><h1>Header</h1><p>First paragraph.</p><p>Second paragraph.</p><h1>Ignore at end</h1></html>'
)
documents = [Document(page_content=paragraphs_html... | null |
test_all_imports | assert set(__all__) == set(EXPECTED_ALL) | def test_all_imports() ->None:
assert set(__all__) == set(EXPECTED_ALL) | null |
from_llm | """Initialize from llm using default template.
Args:
retriever: retriever to query documents from
llm: llm for query generation using DEFAULT_QUERY_PROMPT
include_original: Whether to include the original query in the list of
generated queries.
Retur... | @classmethod
def from_llm(cls, retriever: BaseRetriever, llm: BaseLLM, prompt:
PromptTemplate=DEFAULT_QUERY_PROMPT, parser_key: str='lines',
include_original: bool=False) ->'MultiQueryRetriever':
"""Initialize from llm using default template.
Args:
retriever: retriever to query document... | Initialize from llm using default template.
Args:
retriever: retriever to query documents from
llm: llm for query generation using DEFAULT_QUERY_PROMPT
include_original: Whether to include the original query in the list of
generated queries.
Returns:
MultiQueryRetriever |
load_schemas | """
Args:
str_schemas: string of schemas
"""
values = str_schemas.replace('(', '').replace(')', '').split(',')
schemas = []
for i in range(len(values) // 3):
schemas.append(Schema(values[i * 3].strip(), values[i * 3 + 1].strip(),
values[i * 3 + 2].strip()))
return schemas | def load_schemas(str_schemas: str) ->List[Schema]:
"""
Args:
str_schemas: string of schemas
"""
values = str_schemas.replace('(', '').replace(')', '').split(',')
schemas = []
for i in range(len(values) // 3):
schemas.append(Schema(values[i * 3].strip(), values[i * 3 + 1].
... | Args:
str_schemas: string of schemas |
validate_environment_override | """Validate that api key and python package exists in environment."""
values['openai_api_key'] = get_from_dict_or_env(values, 'anyscale_api_key',
'ANYSCALE_API_KEY')
values['anyscale_api_key'] = convert_to_secret_str(get_from_dict_or_env(
values, 'anyscale_api_key', 'ANYSCALE_API_KEY'))
values['openai_api_base'... | @root_validator(pre=True)
def validate_environment_override(cls, values: dict) ->dict:
"""Validate that api key and python package exists in environment."""
values['openai_api_key'] = get_from_dict_or_env(values,
'anyscale_api_key', 'ANYSCALE_API_KEY')
values['anyscale_api_key'] = convert_to_secret_... | Validate that api key and python package exists in environment. |
on_chain_error | self.on_chain_error_common() | def on_chain_error(self, *args: Any, **kwargs: Any) ->Any:
self.on_chain_error_common() | null |
on_tool_start_common | self.tool_starts += 1
self.starts += 1 | def on_tool_start_common(self) ->None:
self.tool_starts += 1
self.starts += 1 | null |
_stop | """
Stop the iterator and raise a StopIteration exception with the stopped response.
"""
logger.warning('Stopping agent prematurely due to triggering stop condition')
output = self.agent_executor.agent.return_stopped_response(self.
agent_executor.early_stopping_method, self.intermediate_steps, **sel... | def _stop(self, run_manager: CallbackManagerForChainRun) ->AddableDict:
"""
Stop the iterator and raise a StopIteration exception with the stopped response.
"""
logger.warning(
'Stopping agent prematurely due to triggering stop condition')
output = self.agent_executor.agent.return_st... | Stop the iterator and raise a StopIteration exception with the stopped response. |
test_json_validity_evaluator_evaluate_invalid_json | prediction = '{"name": "John", "age": 30, "city": "New York",}'
result = json_validity_evaluator.evaluate_strings(prediction=prediction)
assert result['score'] == 0
assert result['reasoning'].startswith(
'Expecting property name enclosed in double quotes') | def test_json_validity_evaluator_evaluate_invalid_json(json_validity_evaluator:
JsonValidityEvaluator) ->None:
prediction = '{"name": "John", "age": 30, "city": "New York",}'
result = json_validity_evaluator.evaluate_strings(prediction=prediction)
assert result['score'] == 0
assert result['reasoning... | null |
_llm_type | return 'koboldai' | @property
def _llm_type(self) ->str:
return 'koboldai' | null |
is_lc_serializable | """Return whether this model can be serialized by Langchain."""
return False | @classmethod
def is_lc_serializable(cls) ->bool:
"""Return whether this model can be serialized by Langchain."""
return False | Return whether this model can be serialized by Langchain. |
run | """Convenience method for executing chain.
The main difference between this method and `Chain.__call__` is that this
method expects inputs to be passed directly in as positional arguments or
keyword arguments, whereas `Chain.__call__` expects a single input dictionary
with all the input... | def run(self, *args: Any, callbacks: Callbacks=None, tags: Optional[List[
str]]=None, metadata: Optional[Dict[str, Any]]=None, **kwargs: Any) ->Any:
"""Convenience method for executing chain.
The main difference between this method and `Chain.__call__` is that this
method expects inputs to be p... | Convenience method for executing chain.
The main difference between this method and `Chain.__call__` is that this
method expects inputs to be passed directly in as positional arguments or
keyword arguments, whereas `Chain.__call__` expects a single input dictionary
with all the inputs
Args:
*args: If the chain ex... |
from_llm | llm_chain = LLMChain(llm=llm, prompt=prompt)
return cls(llm_chain=llm_chain, **kwargs) | @classmethod
def from_llm(cls, llm: BaseLanguageModel, prompt: BasePromptTemplate=PROMPT,
**kwargs: Any) ->LLMMathChain:
llm_chain = LLMChain(llm=llm, prompt=prompt)
return cls(llm_chain=llm_chain, **kwargs) | null |
similarity_search | """Same as `similarity_search_with_relevance_scores` but
doesn't return the scores.
"""
return self.similarity_search_by_vector(self._embeddings.embed_query(query),
k, distance_func, where_str, **kwargs) | def similarity_search(self, query: str, k: int=4, distance_func:
DistanceFunction=DistanceFunction.COSINE_SIM, where_str: Optional[str]=
None, **kwargs: Any) ->List[Document]:
"""Same as `similarity_search_with_relevance_scores` but
doesn't return the scores.
"""
return self.similarity_s... | Same as `similarity_search_with_relevance_scores` but
doesn't return the scores. |
test_chat_google_palm_generate | """Test Google PaLM Chat API wrapper with generate."""
chat = ChatGooglePalm(n=2, temperature=1.0)
message = HumanMessage(content='Hello')
response = chat.generate([[message], [message]])
assert isinstance(response, LLMResult)
assert len(response.generations) == 2
for generations in response.generations:
assert len... | def test_chat_google_palm_generate() ->None:
"""Test Google PaLM Chat API wrapper with generate."""
chat = ChatGooglePalm(n=2, temperature=1.0)
message = HumanMessage(content='Hello')
response = chat.generate([[message], [message]])
assert isinstance(response, LLMResult)
assert len(response.gene... | Test Google PaLM Chat API wrapper with generate. |
test_basic_functionality | """Test basic functionality of methods exposed by class"""
combined_memory = CombinedMemory(memories=[example_memory[0],
example_memory[1]])
assert combined_memory.memory_variables == ['foo', 'bar']
assert combined_memory.load_memory_variables({}) == {'foo': '', 'bar': ''}
combined_memory.save_context({'input': 'He... | def test_basic_functionality(example_memory: List[ConversationBufferMemory]
) ->None:
"""Test basic functionality of methods exposed by class"""
combined_memory = CombinedMemory(memories=[example_memory[0],
example_memory[1]])
assert combined_memory.memory_variables == ['foo', 'bar']
assert ... | Test basic functionality of methods exposed by class |
draw_graphviz | """
Provides better drawing
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> self.draw_graphviz_svg(layout="dot", filename="web.svg")
>>> SVG('web.svg')
"""
from networkx.drawing.nx_agraph import to_agraph
try:
import pygraphviz
excep... | def draw_graphviz(self, **kwargs: Any) ->None:
"""
Provides better drawing
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> self.draw_graphviz_svg(layout="dot", filename="web.svg")
>>> SVG('web.svg')
"""
from networkx.drawing.nx_a... | Provides better drawing
Usage in a jupyter notebook:
>>> from IPython.display import SVG
>>> self.draw_graphviz_svg(layout="dot", filename="web.svg")
>>> SVG('web.svg') |
test_sqlitevss_with_score | """Test end to end construction and search with scores and IDs."""
texts = ['foo', 'bar', 'baz']
metadatas = [{'page': i} for i in range(len(texts))]
docsearch = _sqlite_vss_from_texts(metadatas=metadatas)
output = docsearch.similarity_search_with_score('foo', k=3)
docs = [o[0] for o in output]
distances = [o[1] for o ... | @pytest.mark.requires('sqlite-vss')
def test_sqlitevss_with_score() ->None:
"""Test end to end construction and search with scores and IDs."""
texts = ['foo', 'bar', 'baz']
metadatas = [{'page': i} for i in range(len(texts))]
docsearch = _sqlite_vss_from_texts(metadatas=metadatas)
output = docsearch... | Test end to end construction and search with scores and IDs. |
test_tool_with_kwargs | """Test functionality when only return direct is provided."""
@tool(return_direct=True)
def search_api(arg_0: str, arg_1: float=4.3, ping: str='hi') ->str:
"""Search the API for the query."""
return f'arg_0={arg_0}, arg_1={arg_1}, ping={ping}'
assert isinstance(search_api, BaseTool)
result = search_api.run(tool... | def test_tool_with_kwargs() ->None:
"""Test functionality when only return direct is provided."""
@tool(return_direct=True)
def search_api(arg_0: str, arg_1: float=4.3, ping: str='hi') ->str:
"""Search the API for the query."""
return f'arg_0={arg_0}, arg_1={arg_1}, ping={ping}'
assert ... | Test functionality when only return direct is provided. |
get_lc_namespace | """Get the namespace of the langchain object."""
return ['langchain', 'prompts', 'chat'] | @classmethod
def get_lc_namespace(cls) ->List[str]:
"""Get the namespace of the langchain object."""
return ['langchain', 'prompts', 'chat'] | Get the namespace of the langchain object. |
_on_chain_start | """Process the Chain Run upon start.""" | def _on_chain_start(self, run: Run) ->None:
"""Process the Chain Run upon start.""" | Process the Chain Run upon start. |
_get_relevant_documents | try:
if self.is_arxiv_identifier(query):
results = self.arxiv_search(id_list=query.split(), max_results=self
.top_k_results).results()
else:
results = self.arxiv_search(query[:self.ARXIV_MAX_QUERY_LENGTH],
max_results=self.top_k_results).results()
except self.arxiv_except... | def _get_relevant_documents(self, query: str, *, run_manager:
CallbackManagerForRetrieverRun) ->List[Document]:
try:
if self.is_arxiv_identifier(query):
results = self.arxiv_search(id_list=query.split(), max_results=
self.top_k_results).results()
else:
res... | null |
__init__ | """Initialize by creating all tables."""
self.engine = engine
self.cache_schema = cache_schema
self.cache_schema.metadata.create_all(self.engine) | def __init__(self, engine: Engine, cache_schema: Type[FullMd5LLMCache]=
FullMd5LLMCache):
"""Initialize by creating all tables."""
self.engine = engine
self.cache_schema = cache_schema
self.cache_schema.metadata.create_all(self.engine) | Initialize by creating all tables. |
test_redis_semantic_cache_chat | set_llm_cache(RedisSemanticCache(embedding=FakeEmbeddings(), redis_url=
REDIS_TEST_URL, score_threshold=0.1))
llm = FakeChatModel()
params = llm.dict()
params['stop'] = None
llm_string = str(sorted([(k, v) for k, v in params.items()]))
prompt: List[BaseMessage] = [HumanMessage(content='foo')]
get_llm_cache().update... | def test_redis_semantic_cache_chat() ->None:
set_llm_cache(RedisSemanticCache(embedding=FakeEmbeddings(), redis_url=
REDIS_TEST_URL, score_threshold=0.1))
llm = FakeChatModel()
params = llm.dict()
params['stop'] = None
llm_string = str(sorted([(k, v) for k, v in params.items()]))
prompt:... | null |
test_chroma_search_filter_with_scores | """Test end to end construction and scored search with metadata filtering."""
texts = ['far', 'bar', 'baz']
metadatas = [{'first_letter': '{}'.format(text[0])} for text in texts]
docsearch = Chroma.from_texts(collection_name='test_collection', texts=
texts, embedding=FakeEmbeddings(), metadatas=metadatas)
output = ... | def test_chroma_search_filter_with_scores() ->None:
"""Test end to end construction and scored search with metadata filtering."""
texts = ['far', 'bar', 'baz']
metadatas = [{'first_letter': '{}'.format(text[0])} for text in texts]
docsearch = Chroma.from_texts(collection_name='test_collection', texts=
... | Test end to end construction and scored search with metadata filtering. |
__call__ | """Correct the query to make it valid. If
Args:
query: cypher query
"""
return self.correct_query(query) | def __call__(self, query: str) ->str:
"""Correct the query to make it valid. If
Args:
query: cypher query
"""
return self.correct_query(query) | Correct the query to make it valid. If
Args:
query: cypher query |
requires_reference | """Whether this evaluator requires a reference label."""
return False | @property
def requires_reference(self) ->bool:
"""Whether this evaluator requires a reference label."""
return False | Whether this evaluator requires a reference label. |
on_agent_action | """Do nothing."""
pass | def on_agent_action(self, action: AgentAction, **kwargs: Any) ->Any:
"""Do nothing."""
pass | Do nothing. |
__init__ | """
Initialize a new LangSmithRunChatLoader instance.
:param runs: List of LLM run IDs or run objects.
:param client: An instance of LangSmith client, if not provided,
a new client instance will be created.
"""
from langsmith.client import Client
self.runs = runs
self.client... | def __init__(self, runs: Iterable[Union[str, Run]], client: Optional[
'Client']=None):
"""
Initialize a new LangSmithRunChatLoader instance.
:param runs: List of LLM run IDs or run objects.
:param client: An instance of LangSmith client, if not provided,
a new client instanc... | Initialize a new LangSmithRunChatLoader instance.
:param runs: List of LLM run IDs or run objects.
:param client: An instance of LangSmith client, if not provided,
a new client instance will be created. |
test_dashscope_embedding_documents | """Test dashscope embeddings."""
documents = ['foo bar']
embedding = DashScopeEmbeddings(model='text-embedding-v1')
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 1536 | def test_dashscope_embedding_documents() ->None:
"""Test dashscope embeddings."""
documents = ['foo bar']
embedding = DashScopeEmbeddings(model='text-embedding-v1')
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 1536 | Test dashscope embeddings. |
__init__ | """Create an Astra DB chat message history."""
try:
from astrapy.db import AstraDB as LibAstraDB
except (ImportError, ModuleNotFoundError):
raise ImportError(
'Could not import a recent astrapy python package. Please install it with `pip install --upgrade astrapy`.'
)
if astra_db_client is not N... | def __init__(self, *, session_id: str, collection_name: str=
DEFAULT_COLLECTION_NAME, token: Optional[str]=None, api_endpoint:
Optional[str]=None, astra_db_client: Optional[LibAstraDB]=None,
namespace: Optional[str]=None) ->None:
"""Create an Astra DB chat message history."""
try:
from astra... | Create an Astra DB chat message history. |
test_jinachat_extra_kwargs | """Test extra kwargs to chat openai."""
llm = JinaChat(foo=3, max_tokens=10)
assert llm.max_tokens == 10
assert llm.model_kwargs == {'foo': 3}
llm = JinaChat(foo=3, model_kwargs={'bar': 2})
assert llm.model_kwargs == {'foo': 3, 'bar': 2}
with pytest.raises(ValueError):
JinaChat(foo=3, model_kwargs={'foo': 2})
with ... | def test_jinachat_extra_kwargs() ->None:
"""Test extra kwargs to chat openai."""
llm = JinaChat(foo=3, max_tokens=10)
assert llm.max_tokens == 10
assert llm.model_kwargs == {'foo': 3}
llm = JinaChat(foo=3, model_kwargs={'bar': 2})
assert llm.model_kwargs == {'foo': 3, 'bar': 2}
with pytest.r... | Test extra kwargs to chat openai. |
test_cosine_similarity_score_threshold | expected_idxs = [(0, 0), (2, 2)]
expected_scores = [1.0, 0.93419873]
actual_idxs, actual_scores = cosine_similarity_top_k(X, Y, top_k=None,
score_threshold=0.9)
assert actual_idxs == expected_idxs
assert np.allclose(expected_scores, actual_scores) | def test_cosine_similarity_score_threshold(X: List[List[float]], Y: List[
List[float]]) ->None:
expected_idxs = [(0, 0), (2, 2)]
expected_scores = [1.0, 0.93419873]
actual_idxs, actual_scores = cosine_similarity_top_k(X, Y, top_k=None,
score_threshold=0.9)
assert actual_idxs == expected_idxs... | null |
get_lc_namespace | """Get the namespace of the langchain object."""
return ['langchain', 'schema', 'messages'] | @classmethod
def get_lc_namespace(cls) ->List[str]:
"""Get the namespace of the langchain object."""
return ['langchain', 'schema', 'messages'] | Get the namespace of the langchain object. |
_import_azure_cognitive_services_AzureCogsTextAnalyticsHealthTool | from langchain_community.tools.azure_cognitive_services import AzureCogsTextAnalyticsHealthTool
return AzureCogsTextAnalyticsHealthTool | def _import_azure_cognitive_services_AzureCogsTextAnalyticsHealthTool() ->Any:
from langchain_community.tools.azure_cognitive_services import AzureCogsTextAnalyticsHealthTool
return AzureCogsTextAnalyticsHealthTool | null |
_generate | should_stream = stream if stream is not None else self.streaming
if should_stream:
stream_iter = self._stream(messages, stop=stop, run_manager=run_manager,
**kwargs)
return generate_from_stream(stream_iter)
message_dicts, params = self._create_message_dicts(messages, stop)
params = {**params, **kwargs}
... | def _generate(self, messages: List[BaseMessage], stop: Optional[List[str]]=
None, run_manager: Optional[CallbackManagerForLLMRun]=None, stream:
Optional[bool]=None, **kwargs: Any) ->ChatResult:
should_stream = stream if stream is not None else self.streaming
if should_stream:
stream_iter = self.... | null |
_parse_search_response | documents = []
for doc in response.matching_documents:
metadata = {'title': doc.document.title, 'source': doc.document.
raw_document_path}
documents.append(Document(page_content=doc.search_text_snippet,
metadata=metadata))
return documents | def _parse_search_response(self, response: 'SearchDocumentsPager') ->List[
Document]:
documents = []
for doc in response.matching_documents:
metadata = {'title': doc.document.title, 'source': doc.document.
raw_document_path}
documents.append(Document(page_content=doc.search_text_... | null |
get_prompt | """Get default prompt for a language model.""" | @abstractmethod
def get_prompt(self, llm: BaseLanguageModel) ->BasePromptTemplate:
"""Get default prompt for a language model.""" | Get default prompt for a language model. |
list | """
List all or search for available templates.
"""
from langchain_cli.utils.github import list_packages
packages = list_packages(contains=contains)
for package in packages:
typer.echo(package) | @package_cli.command()
def list(contains: Annotated[Optional[str], typer.Argument()]=None) ->None:
"""
List all or search for available templates.
"""
from langchain_cli.utils.github import list_packages
packages = list_packages(contains=contains)
for package in packages:
typer.echo(pack... | List all or search for available templates. |
get_llm_kwargs | """Returns the kwargs for the LLMChain constructor.
Args:
function: The function to use.
Returns:
The kwargs for the LLMChain constructor.
"""
return {'functions': [function], 'function_call': {'name': function['name']}} | def get_llm_kwargs(function: dict) ->dict:
"""Returns the kwargs for the LLMChain constructor.
Args:
function: The function to use.
Returns:
The kwargs for the LLMChain constructor.
"""
return {'functions': [function], 'function_call': {'name': function[
'name']}} | Returns the kwargs for the LLMChain constructor.
Args:
function: The function to use.
Returns:
The kwargs for the LLMChain constructor. |
__init__ | super().__init__(criteria=criteria, normalize_by=normalize_by, **kwargs) | def __init__(self, criteria: Optional[CRITERIA_TYPE]=None, normalize_by:
Optional[float]=None, **kwargs: Any) ->None:
super().__init__(criteria=criteria, normalize_by=normalize_by, **kwargs) | null |
from_llm | """Load chain from LLM."""
combine_docs_chain_kwargs = combine_docs_chain_kwargs or {}
doc_chain = load_qa_chain(llm, chain_type=chain_type, callbacks=callbacks,
**combine_docs_chain_kwargs)
condense_question_chain = LLMChain(llm=llm, prompt=condense_question_prompt,
callbacks=callbacks)
return cls(vectorstore=... | @classmethod
def from_llm(cls, llm: BaseLanguageModel, vectorstore: VectorStore,
condense_question_prompt: BasePromptTemplate=CONDENSE_QUESTION_PROMPT,
chain_type: str='stuff', combine_docs_chain_kwargs: Optional[Dict]=None,
callbacks: Callbacks=None, **kwargs: Any
) ->BaseConversationalRetrievalChain:
... | Load chain from LLM. |
test_get_relevant_documents | retriever.add_texts(['Hai there!', 'Hello world!', 'Foo bar baz!'])
expected = [Document(page_content='Hai there!')]
retriever.k = 1
results = retriever.get_relevant_documents('Hai there!')
assert len(results) == retriever.k
assert results == expected
assert retriever.get_relevant_documents('Hai there!') == expected | def test_get_relevant_documents(retriever: QdrantSparseVectorRetriever) ->None:
retriever.add_texts(['Hai there!', 'Hello world!', 'Foo bar baz!'])
expected = [Document(page_content='Hai there!')]
retriever.k = 1
results = retriever.get_relevant_documents('Hai there!')
assert len(results) == retriev... | null |
test_intervention_chain | """
Test intervention chain correctly transforms
the LLM's text completion into a setting-like object.
"""
intervention_chain = InterventionChain.from_univariate_prompt(llm=self.fake_llm
)
output = intervention_chain('if cindy has ten pets')
expected_output = {'chain_answer': None, 'chain_da... | def test_intervention_chain(self) ->None:
"""
Test intervention chain correctly transforms
the LLM's text completion into a setting-like object.
"""
intervention_chain = InterventionChain.from_univariate_prompt(llm=self.
fake_llm)
output = intervention_chain('if cindy has ten... | Test intervention chain correctly transforms
the LLM's text completion into a setting-like object. |
_import_google_search_tool_GoogleSearchResults | from langchain_community.tools.google_search.tool import GoogleSearchResults
return GoogleSearchResults | def _import_google_search_tool_GoogleSearchResults() ->Any:
from langchain_community.tools.google_search.tool import GoogleSearchResults
return GoogleSearchResults | null |
_call | """Split document into chunks and pass to CombineDocumentsChain."""
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
document = inputs[self.input_key]
docs = self.text_splitter.create_documents([document])
other_keys: Dict = {k: v for k, v in inputs.items() if k != self.input_key}
other_keys[... | def _call(self, inputs: Dict[str, str], run_manager: Optional[
CallbackManagerForChainRun]=None) ->Dict[str, str]:
"""Split document into chunks and pass to CombineDocumentsChain."""
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
document = inputs[self.input_key]
docs = ... | Split document into chunks and pass to CombineDocumentsChain. |
test_move_file_errs_outside_root_dir | """Test the FileMove tool when a root dir is specified."""
with TemporaryDirectory() as temp_dir:
tool = MoveFileTool(root_dir=temp_dir)
result = tool.run({'source_path': '../source.txt', 'destination_path':
'../destination.txt'})
assert result == INVALID_PATH_TEMPLATE.format(arg_name='source_path',... | def test_move_file_errs_outside_root_dir() ->None:
"""Test the FileMove tool when a root dir is specified."""
with TemporaryDirectory() as temp_dir:
tool = MoveFileTool(root_dir=temp_dir)
result = tool.run({'source_path': '../source.txt',
'destination_path': '../destination.txt'})
... | Test the FileMove tool when a root dir is specified. |
get_chat_model_table | feat_table = {}
for cm in chat_models.__all__:
feat_table[cm] = {}
cls = getattr(chat_models, cm)
if issubclass(cls, SimpleChatModel):
comparison_cls = SimpleChatModel
else:
comparison_cls = BaseChatModel
for feat in ('_stream', '_astream', '_agenerate'):
feat_table[cm][feat]... | def get_chat_model_table():
feat_table = {}
for cm in chat_models.__all__:
feat_table[cm] = {}
cls = getattr(chat_models, cm)
if issubclass(cls, SimpleChatModel):
comparison_cls = SimpleChatModel
else:
comparison_cls = BaseChatModel
for feat in ('_... | null |
get_format_instructions | """Instructions on how the LLM output should be formatted."""
initial = f'For your first output: {self.parsers[0].get_format_instructions()}'
subsequent = '\n'.join(
f'Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}'
for p in self.pars... | def get_format_instructions(self) ->str:
"""Instructions on how the LLM output should be formatted."""
initial = (
f'For your first output: {self.parsers[0].get_format_instructions()}')
subsequent = '\n'.join(
f'Complete that output fully. Then produce another output, separated by two newlin... | Instructions on how the LLM output should be formatted. |
on_llm_end | self.saved_things['generation'] = args[0] | def on_llm_end(self, *args: Any, **kwargs: Any) ->Any:
self.saved_things['generation'] = args[0] | null |
_call | """Call the internal llm chain."""
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
return self.llm_chain(inputs, callbacks=_run_manager.get_child()) | def _call(self, inputs: Dict[str, Any], run_manager: Optional[
CallbackManagerForChainRun]=None) ->Dict[str, str]:
"""Call the internal llm chain."""
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
return self.llm_chain(inputs, callbacks=_run_manager.get_child()) | Call the internal llm chain. |
test_run_kwargs_error | """Test run method with kwargs errors as expected."""
chain = FakeChain(the_input_keys=['foo', 'bar'])
with pytest.raises(ValueError):
chain.run(foo='bar', baz='foo') | def test_run_kwargs_error() ->None:
"""Test run method with kwargs errors as expected."""
chain = FakeChain(the_input_keys=['foo', 'bar'])
with pytest.raises(ValueError):
chain.run(foo='bar', baz='foo') | Test run method with kwargs errors as expected. |
End of preview. Expand in Data Studio
- Downloads last month
- 63