method_name stringlengths 1 78 | method_body stringlengths 3 9.66k | full_code stringlengths 31 10.7k | docstring stringlengths 4 4.74k ⌀ |
|---|---|---|---|
generate_prompt | prompt_messages = [p.to_messages() for p in prompts]
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs) | def generate_prompt(self, prompts: List[PromptValue], stop: Optional[List[
str]]=None, callbacks: Callbacks=None, **kwargs: Any) ->LLMResult:
prompt_messages = [p.to_messages() for p in prompts]
return self.generate(prompt_messages, stop=stop, callbacks=callbacks,
**kwargs) | null |
__from | if ids is None:
ids = [str(uuid.uuid1()) for _ in texts]
if not metadatas:
metadatas = [{} for _ in texts]
store = cls(embedding=embedding, search_type=search_type, **kwargs)
embedding_dimension = store.retrieve_existing_index()
if not embedding_dimension:
store.create_new_index()
elif not store.embedding_d... | @classmethod
def __from(cls, texts: List[str], embeddings: List[List[float]], embedding:
Embeddings, metadatas: Optional[List[dict]]=None, ids: Optional[List[
str]]=None, create_id_index: bool=True, search_type: SearchType=
SearchType.VECTOR, **kwargs: Any) ->Neo4jVector:
if ids is None:
ids = [... | null |
validate_environment | """Validate that FastEmbed has been installed."""
try:
from fastembed.embedding import FlagEmbedding
model_name = values.get('model_name')
max_length = values.get('max_length')
cache_dir = values.get('cache_dir')
threads = values.get('threads')
values['_model'] = FlagEmbedding(model_name=model_n... | @root_validator()
def validate_environment(cls, values: Dict) ->Dict:
"""Validate that FastEmbed has been installed."""
try:
from fastembed.embedding import FlagEmbedding
model_name = values.get('model_name')
max_length = values.get('max_length')
cache_dir = values.get('cache_dir... | Validate that FastEmbed has been installed. |
test_invalid_request_format | """Test invalid request format."""
class CustomContentFormatter(ContentFormatterBase):
content_type = 'application/json'
accepts = 'application/json'
def format_request_payload(self, prompt: str, model_kwargs: Dict) ->bytes:
input_str = json.dumps({'incorrect_input': {'input_string': [prompt
... | def test_invalid_request_format() ->None:
"""Test invalid request format."""
class CustomContentFormatter(ContentFormatterBase):
content_type = 'application/json'
accepts = 'application/json'
def format_request_payload(self, prompt: str, model_kwargs: Dict
) ->bytes:
... | Test invalid request format. |
_create_weaviate_client | try:
import weaviate
except ImportError:
raise ImportError(
'Could not import weaviate python package. Please install it with `pip install weaviate-client`'
)
url = url or os.environ.get('WEAVIATE_URL')
api_key = api_key or os.environ.get('WEAVIATE_API_KEY')
auth = weaviate.auth.AuthApiKey(api_... | def _create_weaviate_client(url: Optional[str]=None, api_key: Optional[str]
=None, **kwargs: Any) ->weaviate.Client:
try:
import weaviate
except ImportError:
raise ImportError(
'Could not import weaviate python package. Please install it with `pip install weaviate-client`'
... | null |
convert_pydantic_to_ernie_tool | """Converts a Pydantic model to a function description for the Ernie API."""
function = convert_pydantic_to_ernie_function(model, name=name, description
=description)
return {'type': 'function', 'function': function} | def convert_pydantic_to_ernie_tool(model: Type[BaseModel], *, name:
Optional[str]=None, description: Optional[str]=None) ->ToolDescription:
"""Converts a Pydantic model to a function description for the Ernie API."""
function = convert_pydantic_to_ernie_function(model, name=name,
description=descrip... | Converts a Pydantic model to a function description for the Ernie API. |
test_openai_streaming_multiple_prompts_error | """Test validation for streaming fails if multiple prompts are given."""
with pytest.raises(ValueError):
_get_llm(streaming=True).generate(["I'm Pickle Rick", "I'm Pickle Rick"]) | def test_openai_streaming_multiple_prompts_error() ->None:
"""Test validation for streaming fails if multiple prompts are given."""
with pytest.raises(ValueError):
_get_llm(streaming=True).generate(["I'm Pickle Rick",
"I'm Pickle Rick"]) | Test validation for streaming fails if multiple prompts are given. |
callback | log_method(text, extra=extra) | def callback(text: str) ->None:
log_method(text, extra=extra) | null |
__next__ | while True:
self.buffer.seek(self.read_pos)
line = self.buffer.readline()
if line and line[-1] == ord('\n'):
self.read_pos += len(line)
return line[:-1]
try:
chunk = next(self.byte_iterator)
except StopIteration:
if self.read_pos < self.buffer.getbuffer().nbytes:
... | def __next__(self) ->Any:
while True:
self.buffer.seek(self.read_pos)
line = self.buffer.readline()
if line and line[-1] == ord('\n'):
self.read_pos += len(line)
return line[:-1]
try:
chunk = next(self.byte_iterator)
except StopIteration:
... | null |
mocked_responses | """Fixture mocking requests.get."""
with responses.RequestsMock() as rsps:
yield rsps | @pytest.fixture(autouse=True)
def mocked_responses() ->Iterable[responses.RequestsMock]:
"""Fixture mocking requests.get."""
with responses.RequestsMock() as rsps:
yield rsps | Fixture mocking requests.get. |
test_run_multiple_args_error | """Test run method with multiple args errors as expected."""
chain = FakeChain()
with pytest.raises(ValueError):
chain.run('bar', 'foo') | def test_run_multiple_args_error() ->None:
"""Test run method with multiple args errors as expected."""
chain = FakeChain()
with pytest.raises(ValueError):
chain.run('bar', 'foo') | Test run method with multiple args errors as expected. |
test_parse_with_language | llm_output = """I can use the `foo` tool to achieve the goal.
Action:
```json
{
"action": "foo",
"action_input": "bar"
}
```
"""
action, action_input = get_action_and_input(llm_output)
assert action == 'foo'
assert action_input == 'bar' | def test_parse_with_language() ->None:
llm_output = """I can use the `foo` tool to achieve the goal.
Action:
```json
{
"action": "foo",
"action_input": "bar"
}
```
"""
action, action_input = get_action_and_input(llm_output)
assert action == 'foo'
assert action_input ... | null |
create_table_if_not_exists | Table(self.collection_name, Base.metadata, Column('id', TEXT, primary_key=
True, default=uuid.uuid4), Column('embedding', ARRAY(REAL)), Column(
'document', String, nullable=True), Column('metadata', JSON, nullable=
True), extend_existing=True)
with self.engine.connect() as conn:
with conn.begin():
... | def create_table_if_not_exists(self) ->None:
Table(self.collection_name, Base.metadata, Column('id', TEXT,
primary_key=True, default=uuid.uuid4), Column('embedding', ARRAY(
REAL)), Column('document', String, nullable=True), Column(
'metadata', JSON, nullable=True), extend_existing=True)
... | null |
__init__ | """Initialize with necessary components.
Args:
table_name (str, optional): Specifies the name of the table in use.
Defaults to "message_store".
id_field (str, optional): Specifies the name of the id field in the table.
Defaults to "id".
sess... | def __init__(self, session_id: str, *, table_name: str='message_store',
id_field: str='id', session_id_field: str='session_id', message_field:
str='message', pool_size: int=5, max_overflow: int=10, timeout: float=
30, **kwargs: Any):
"""Initialize with necessary components.
Args:
... | Initialize with necessary components.
Args:
table_name (str, optional): Specifies the name of the table in use.
Defaults to "message_store".
id_field (str, optional): Specifies the name of the id field in the table.
Defaults to "id".
session_id_field (str, optional): Specifies the name of... |
try_load_from_hub | """Load configuration from hub. Returns None if path is not a hub path."""
if not isinstance(path, str) or not (match := HUB_PATH_RE.match(path)):
return None
ref, remote_path_str = match.groups()
ref = ref[1:] if ref else DEFAULT_REF
remote_path = Path(remote_path_str)
if remote_path.parts[0] != valid_prefix:
... | def try_load_from_hub(path: Union[str, Path], loader: Callable[[str], T],
valid_prefix: str, valid_suffixes: Set[str], **kwargs: Any) ->Optional[T]:
"""Load configuration from hub. Returns None if path is not a hub path."""
if not isinstance(path, str) or not (match := HUB_PATH_RE.match(path)):
ret... | Load configuration from hub. Returns None if path is not a hub path. |
test_visit_structured_query_complex | query = 'What is the capital of France?'
op = Operation(operator=Operator.AND, arguments=[Comparison(comparator=
Comparator.EQ, attribute='foo', value=2), Operation(operator=Operator.
OR, arguments=[Comparison(comparator=Comparator.LT, attribute='bar',
value=1), Comparison(comparator=Comparator.LIKE, attrib... | def test_visit_structured_query_complex() ->None:
query = 'What is the capital of France?'
op = Operation(operator=Operator.AND, arguments=[Comparison(comparator=
Comparator.EQ, attribute='foo', value=2), Operation(operator=
Operator.OR, arguments=[Comparison(comparator=Comparator.LT,
at... | null |
_get_stacktrace | """Get the stacktrace of the parent error."""
msg = repr(error)
try:
if sys.version_info < (3, 10):
tb = traceback.format_exception(error.__class__, error, error.
__traceback__)
else:
tb = traceback.format_exception(error)
return (msg + '\n\n'.join(tb)).strip()
except:
return... | @staticmethod
def _get_stacktrace(error: BaseException) ->str:
"""Get the stacktrace of the parent error."""
msg = repr(error)
try:
if sys.version_info < (3, 10):
tb = traceback.format_exception(error.__class__, error, error.
__traceback__)
else:
tb = ... | Get the stacktrace of the parent error. |
_import_titan_takeoff | from langchain_community.llms.titan_takeoff import TitanTakeoff
return TitanTakeoff | def _import_titan_takeoff() ->Any:
from langchain_community.llms.titan_takeoff import TitanTakeoff
return TitanTakeoff | null |
get_child | """Get a child callback manager.
Args:
tag (str, optional): The tag for the child callback manager.
Defaults to None.
Returns:
CallbackManager: The child callback manager.
"""
manager = CallbackManager(handlers=[], parent_run_id=self.run_id)
manager.set_... | def get_child(self, tag: Optional[str]=None) ->CallbackManager:
"""Get a child callback manager.
Args:
tag (str, optional): The tag for the child callback manager.
Defaults to None.
Returns:
CallbackManager: The child callback manager.
"""
manage... | Get a child callback manager.
Args:
tag (str, optional): The tag for the child callback manager.
Defaults to None.
Returns:
CallbackManager: The child callback manager. |
_document_exists | return len(self._query(
f"""
SELECT 1
FROM {self.location}
WHERE _id=:session_id
LIMIT 1
"""
, session_id=self.session_id)) != 0 | def _document_exists(self) ->bool:
return len(self._query(
f"""
SELECT 1
FROM {self.location}
WHERE _id=:session_id
LIMIT 1
"""
, session_id=self.session_id)) != 0 | null |
test_retry_logic | """Tests that two queries (which would usually exceed the rate limit) works"""
llm = MosaicML(inject_instruction_format=True, model_kwargs={
'max_new_tokens': 10})
instruction = 'Repeat the word foo'
prompt = llm._transform_prompt(instruction)
expected_prompt = PROMPT_FOR_GENERATION_FORMAT.format(instruction=instru... | def test_retry_logic() ->None:
"""Tests that two queries (which would usually exceed the rate limit) works"""
llm = MosaicML(inject_instruction_format=True, model_kwargs={
'max_new_tokens': 10})
instruction = 'Repeat the word foo'
prompt = llm._transform_prompt(instruction)
expected_prompt =... | Tests that two queries (which would usually exceed the rate limit) works |
add_texts | """Run more texts through the embeddings and add to the vectorstore.
Args:
texts: List of strings to add to the vectorstore.
metadatas: Optional list of metadata associated with the texts.
Returns:
List of ids from adding the texts into the vectorstore.
"""
... | def add_texts(self, texts: List[str], metadatas: Optional[List[dict]]=None,
**kwargs: Any) ->List[str]:
"""Run more texts through the embeddings and add to the vectorstore.
Args:
texts: List of strings to add to the vectorstore.
metadatas: Optional list of metadata associated wi... | Run more texts through the embeddings and add to the vectorstore.
Args:
texts: List of strings to add to the vectorstore.
metadatas: Optional list of metadata associated with the texts.
Returns:
List of ids from adding the texts into the vectorstore. |
_validate_inputs | super()._validate_inputs(inputs)
if self.selected_input_key in inputs.keys(
) or self.selected_based_on_input_key in inputs.keys():
raise ValueError(
f"The rl chain does not accept '{self.selected_input_key}' or '{self.selected_based_on_input_key}' as input keys, they are reserved for internal use durin... | def _validate_inputs(self, inputs: Dict[str, Any]) ->None:
super()._validate_inputs(inputs)
if self.selected_input_key in inputs.keys(
) or self.selected_based_on_input_key in inputs.keys():
raise ValueError(
f"The rl chain does not accept '{self.selected_input_key}' or '{self.select... | null |
test_input_dict_with_history_key | runnable = RunnableLambda(lambda input: 'you said: ' + '\n'.join([str(m.
content) for m in input['history'] if isinstance(m, HumanMessage)] + [
input['input']]))
get_session_history = _get_get_session_history()
with_history = RunnableWithMessageHistory(runnable, get_session_history,
input_messages_key='inpu... | def test_input_dict_with_history_key() ->None:
runnable = RunnableLambda(lambda input: 'you said: ' + '\n'.join([str(m
.content) for m in input['history'] if isinstance(m, HumanMessage)] +
[input['input']]))
get_session_history = _get_get_session_history()
with_history = RunnableWithMessageH... | null |
prepare_output_stream | stream = response.get('body')
if not stream:
return
if provider not in cls.provider_to_output_key_map:
raise ValueError(
f'Unknown streaming response output key for provider: {provider}')
for event in stream:
chunk = event.get('chunk')
if chunk:
chunk_obj = json.loads(chunk.get('bytes').... | @classmethod
def prepare_output_stream(cls, provider: str, response: Any, stop: Optional
[List[str]]=None) ->Iterator[GenerationChunk]:
stream = response.get('body')
if not stream:
return
if provider not in cls.provider_to_output_key_map:
raise ValueError(
f'Unknown streaming... | null |
_combine_message_texts | """
Combine the message texts for each parent message ID based on the list of message threads.
Args:
message_threads (dict): A dictionary where the key is the parent message ID and the value is a list of message IDs in ascending order.
data (pd.DataFr... | def _combine_message_texts(self, message_threads: Dict[int, List[int]],
data: pd.DataFrame) ->str:
"""
Combine the message texts for each parent message ID based on the list of message threads.
Args:
message_threads (dict): A dictionary where the key is the parent messag... | Combine the message texts for each parent message ID based on the list of message threads.
Args:
message_threads (dict): A dictionary where the key is the parent message ID and the value is a list of message IDs in ascending order.
data (pd.DataFrame): A DataFrame containing the con... |
_import_llm_rails | from langchain_community.vectorstores.llm_rails import LLMRails
return LLMRails | def _import_llm_rails() ->Any:
from langchain_community.vectorstores.llm_rails import LLMRails
return LLMRails | null |
test_default_w_embeddings_off | llm, PROMPT = setup()
feature_embedder = pick_best_chain.PickBestFeatureEmbedder(auto_embed=False,
model=MockEncoder())
chain = pick_best_chain.PickBest.from_llm(llm=llm, prompt=PROMPT,
feature_embedder=feature_embedder, auto_embed=False)
str1 = '0'
str2 = '1'
str3 = '2'
ctx_str_1 = 'context1'
expected = f"""sh... | @pytest.mark.requires('vowpal_wabbit_next', 'sentence_transformers')
def test_default_w_embeddings_off() ->None:
llm, PROMPT = setup()
feature_embedder = pick_best_chain.PickBestFeatureEmbedder(auto_embed=
False, model=MockEncoder())
chain = pick_best_chain.PickBest.from_llm(llm=llm, prompt=PROMPT,
... | null |
_transform | xml_start_re = re.compile('<[a-zA-Z:_]')
parser = ET.XMLPullParser(['start', 'end'])
xml_started = False
current_path: List[str] = []
current_path_has_children = False
buffer = ''
for chunk in input:
if isinstance(chunk, BaseMessage):
chunk_content = chunk.content
if not isinstance(chunk_content, st... | def _transform(self, input: Iterator[Union[str, BaseMessage]]) ->Iterator[
AddableDict]:
xml_start_re = re.compile('<[a-zA-Z:_]')
parser = ET.XMLPullParser(['start', 'end'])
xml_started = False
current_path: List[str] = []
current_path_has_children = False
buffer = ''
for chunk in input:... | null |
sanitize_input | """Sanitize input to the python REPL.
Remove whitespace, backtick & python (if llm mistakes python console as terminal)
Args:
query: The query to sanitize
Returns:
str: The sanitized query
"""
query = re.sub('^(\\s|`)*(?i:python)?\\s*', '', query)
query = re.sub('(\\s|`)*$', '', query)... | def sanitize_input(query: str) ->str:
"""Sanitize input to the python REPL.
Remove whitespace, backtick & python (if llm mistakes python console as terminal)
Args:
query: The query to sanitize
Returns:
str: The sanitized query
"""
query = re.sub('^(\\s|`)*(?i:python)?\\s*', '',... | Sanitize input to the python REPL.
Remove whitespace, backtick & python (if llm mistakes python console as terminal)
Args:
query: The query to sanitize
Returns:
str: The sanitized query |
on_agent_finish | """Run on agent end."""
print_text(finish.log, color=color or self.color, end='\n', file=self.file) | def on_agent_finish(self, finish: AgentFinish, color: Optional[str]=None,
**kwargs: Any) ->None:
"""Run on agent end."""
print_text(finish.log, color=color or self.color, end='\n', file=self.file) | Run on agent end. |
get_lc_namespace | """Get the namespace of the langchain object."""
return ['langchain', 'schema', 'prompt_template'] | @classmethod
def get_lc_namespace(cls) ->List[str]:
"""Get the namespace of the langchain object."""
return ['langchain', 'schema', 'prompt_template'] | Get the namespace of the langchain object. |
test_usearch_from_texts | """Test end to end construction and search."""
texts = ['foo', 'bar', 'baz']
docsearch = USearch.from_texts(texts, FakeEmbeddings())
output = docsearch.similarity_search('foo', k=1)
assert output == [Document(page_content='foo')] | def test_usearch_from_texts() ->None:
"""Test end to end construction and search."""
texts = ['foo', 'bar', 'baz']
docsearch = USearch.from_texts(texts, FakeEmbeddings())
output = docsearch.similarity_search('foo', k=1)
assert output == [Document(page_content='foo')] | Test end to end construction and search. |
last_node | """Find the single node that is not a source of any edge.
If there is no such node, or there are multiple, return None.
When drawing the graph this node would be the destination.
"""
sources = {edge.source for edge in self.edges}
found: List[Node] = []
for node in self.nodes.values():
if nod... | def last_node(self) ->Optional[Node]:
"""Find the single node that is not a source of any edge.
If there is no such node, or there are multiple, return None.
When drawing the graph this node would be the destination.
"""
sources = {edge.source for edge in self.edges}
found: List[Node... | Find the single node that is not a source of any edge.
If there is no such node, or there are multiple, return None.
When drawing the graph this node would be the destination. |
_get_default_output_parser | return ChatOutputParser() | @classmethod
def _get_default_output_parser(cls, **kwargs: Any) ->AgentOutputParser:
return ChatOutputParser() | null |
api_client | return ArxivAPIWrapper() | @pytest.fixture
def api_client() ->ArxivAPIWrapper:
return ArxivAPIWrapper() | null |
test_raise_error_if_path_not_exist | loader = DirectoryLoader('./not_exist_directory')
with pytest.raises(FileNotFoundError) as e:
loader.load()
assert str(e.value) == "Directory not found: './not_exist_directory'" | def test_raise_error_if_path_not_exist() ->None:
loader = DirectoryLoader('./not_exist_directory')
with pytest.raises(FileNotFoundError) as e:
loader.load()
assert str(e.value) == "Directory not found: './not_exist_directory'" | null |
__init__ | """Load a list of URLs using Playwright."""
try:
import playwright
except ImportError:
raise ImportError(
'playwright package not found, please install it with `pip install playwright`'
)
self.urls = urls
self.continue_on_failure = continue_on_failure
self.headless = headless
if remove_selectors... | def __init__(self, urls: List[str], continue_on_failure: bool=True,
headless: bool=True, remove_selectors: Optional[List[str]]=None,
evaluator: Optional[PlaywrightEvaluator]=None):
"""Load a list of URLs using Playwright."""
try:
import playwright
except ImportError:
raise ImportErro... | Load a list of URLs using Playwright. |
create_connection | import sqlite3
import sqlite_vss
connection = sqlite3.connect(db_file)
connection.row_factory = sqlite3.Row
connection.enable_load_extension(True)
sqlite_vss.load(connection)
connection.enable_load_extension(False)
return connection | @staticmethod
def create_connection(db_file: str) ->sqlite3.Connection:
import sqlite3
import sqlite_vss
connection = sqlite3.connect(db_file)
connection.row_factory = sqlite3.Row
connection.enable_load_extension(True)
sqlite_vss.load(connection)
connection.enable_load_extension(False)
r... | null |
_run_llm | """
Run the language model on the example.
Args:
llm: The language model to run.
inputs: The input dictionary.
callbacks: The callbacks to use during the run.
tags: Optional tags to add to the run.
input_mapper: function to map to the inputs dictionary from an Example
... | def _run_llm(llm: BaseLanguageModel, inputs: Dict[str, Any], callbacks:
Callbacks, *, tags: Optional[List[str]]=None, input_mapper: Optional[
Callable[[Dict], Any]]=None) ->Union[str, BaseMessage]:
"""
Run the language model on the example.
Args:
llm: The language model to run.
inpu... | Run the language model on the example.
Args:
llm: The language model to run.
inputs: The input dictionary.
callbacks: The callbacks to use during the run.
tags: Optional tags to add to the run.
input_mapper: function to map to the inputs dictionary from an Example
Returns:
The LLMResult or Chat... |
similarity_search | """Return typesense documents most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 10.
Minimum 10 results would be returned.
filter: typesense filter_by expression to filter documents on
... | def similarity_search(self, query: str, k: int=10, filter: Optional[str]='',
**kwargs: Any) ->List[Document]:
"""Return typesense documents most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 10.
... | Return typesense documents most similar to query.
Args:
query: Text to look up documents similar to.
k: Number of Documents to return. Defaults to 10.
Minimum 10 results would be returned.
filter: typesense filter_by expression to filter documents on
Returns:
List of Documents most similar to ... |
get_docstore | """Get the metadata store used for this example."""
return LocalFileStore(str(Path(__file__).parent.parent /
'multi_vector_retriever_metadata')) | def get_docstore():
"""Get the metadata store used for this example."""
return LocalFileStore(str(Path(__file__).parent.parent /
'multi_vector_retriever_metadata')) | Get the metadata store used for this example. |
from_embeddings | texts = [t[0] for t in text_embeddings]
embeddings = [t[1] for t in text_embeddings]
return cls._initialize_from_embeddings(texts, embeddings, embedding,
metadatas=metadatas, ids=ids, collection_name=collection_name,
pre_delete_collection=pre_delete_collection, **kwargs) | @classmethod
def from_embeddings(cls, text_embeddings: List[Tuple[str, List[float]]],
embedding: Embeddings, metadatas: Optional[List[dict]]=None,
collection_name: str=_LANGCHAIN_DEFAULT_COLLECTION_NAME, ids: Optional[
List[str]]=None, pre_delete_collection: bool=False, **kwargs: Any
) ->PGEmbedding:
... | null |
test_api_key_masked_when_passed_via_constructor | mock_response = mock_get.return_value
mock_response.status_code = 200
mock_response.json.return_value = {'model_id': '', 'status':
'training_complete'}
arcee_without_env_var = Arcee(model='DALM-PubMed', arcee_api_key=
'secret_api_key', arcee_api_url='https://localhost', arcee_api_version=
'version')
print(a... | @patch('langchain_community.utilities.arcee.requests.get')
def test_api_key_masked_when_passed_via_constructor(mock_get: MagicMock,
capsys: CaptureFixture) ->None:
mock_response = mock_get.return_value
mock_response.status_code = 200
mock_response.json.return_value = {'model_id': '', 'status':
'... | null |
from_texts | """Create an Astra DB vectorstore from raw texts.
Args:
texts (List[str]): the texts to insert.
embedding (Embeddings): the embedding function to use in the store.
metadatas (Optional[List[dict]]): metadata dicts for the texts.
ids (Optional[List[str]]): ids to a... | @classmethod
def from_texts(cls: Type[ADBVST], texts: List[str], embedding: Embeddings,
metadatas: Optional[List[dict]]=None, ids: Optional[List[str]]=None, **
kwargs: Any) ->ADBVST:
"""Create an Astra DB vectorstore from raw texts.
Args:
texts (List[str]): the texts to insert.
... | Create an Astra DB vectorstore from raw texts.
Args:
texts (List[str]): the texts to insert.
embedding (Embeddings): the embedding function to use in the store.
metadatas (Optional[List[dict]]): metadata dicts for the texts.
ids (Optional[List[str]]): ids to associate to the texts.
*Additional argu... |
_llm_type | """Return type of llm."""
return 'google_palm' | @property
def _llm_type(self) ->str:
"""Return type of llm."""
return 'google_palm' | Return type of llm. |
test_similarity_search_without_metadata | """Test end to end construction and search without metadata."""
texts = ['foo', 'bar', 'baz']
docsearch = ElasticVectorSearch.from_texts(texts, FakeEmbeddings(),
elasticsearch_url=elasticsearch_url)
output = docsearch.similarity_search('foo', k=1)
assert output == [Document(page_content='foo')] | def test_similarity_search_without_metadata(self, elasticsearch_url: str
) ->None:
"""Test end to end construction and search without metadata."""
texts = ['foo', 'bar', 'baz']
docsearch = ElasticVectorSearch.from_texts(texts, FakeEmbeddings(),
elasticsearch_url=elasticsearch_url)
output = d... | Test end to end construction and search without metadata. |
generate_queries | """Generate queries based upon user input.
Args:
question: user query
Returns:
List of LLM generated queries that are similar to the user input
"""
response = self.llm_chain({'question': question}, callbacks=run_manager.
get_child())
lines = getattr(response['text']... | def generate_queries(self, question: str, run_manager:
CallbackManagerForRetrieverRun) ->List[str]:
"""Generate queries based upon user input.
Args:
question: user query
Returns:
List of LLM generated queries that are similar to the user input
"""
response =... | Generate queries based upon user input.
Args:
question: user query
Returns:
List of LLM generated queries that are similar to the user input |
from_credentials | """Convenience constructor that builds TrelloClient init param for you.
Args:
board_name: The name of the Trello board.
api_key: Trello API key. Can also be specified as environment variable
TRELLO_API_KEY.
token: Trello token. Can also be specified as enviro... | @classmethod
def from_credentials(cls, board_name: str, *, api_key: Optional[str]=None,
token: Optional[str]=None, **kwargs: Any) ->TrelloLoader:
"""Convenience constructor that builds TrelloClient init param for you.
Args:
board_name: The name of the Trello board.
api_key: Trel... | Convenience constructor that builds TrelloClient init param for you.
Args:
board_name: The name of the Trello board.
api_key: Trello API key. Can also be specified as environment variable
TRELLO_API_KEY.
token: Trello token. Can also be specified as environment variable
TRELLO_TOKEN.
in... |
_import_marqo | from langchain_community.vectorstores.marqo import Marqo
return Marqo | def _import_marqo() ->Any:
from langchain_community.vectorstores.marqo import Marqo
return Marqo | null |
test_load_single_page | loader = GitbookLoader(web_page)
result = loader.load()
assert len(result) == expected_number_results | @pytest.mark.parametrize('web_page, expected_number_results', [(
'https://platform-docs.opentargets.org/getting-started', 1)])
def test_load_single_page(self, web_page: str, expected_number_results: int
) ->None:
loader = GitbookLoader(web_page)
result = loader.load()
assert len(result) == expected_... | null |
test_openai_streaming | """Test streaming tokens from OpenAI."""
for token in llm.stream("I'm Pickle Rick"):
assert isinstance(token.content, str) | @pytest.mark.scheduled
def test_openai_streaming(llm: AzureChatOpenAI) ->None:
"""Test streaming tokens from OpenAI."""
for token in llm.stream("I'm Pickle Rick"):
assert isinstance(token.content, str) | Test streaming tokens from OpenAI. |
__get_headers | is_managed = self.url == MANAGED_URL
headers = {'Content-Type': 'application/json'}
if is_managed and not (self.api_key and self.client_id):
raise ValueError(
"""
You must provide an API key or a client ID to use the managed
version of Motorhead. Visit https://getmetal.io for... | def __get_headers(self) ->Dict[str, str]:
is_managed = self.url == MANAGED_URL
headers = {'Content-Type': 'application/json'}
if is_managed and not (self.api_key and self.client_id):
raise ValueError(
"""
You must provide an API key or a client ID to use the managed
... | null |
test_call | """Test valid call to qianfan."""
llm = QianfanLLMEndpoint()
output = llm('write a joke')
assert isinstance(output, str) | def test_call() ->None:
"""Test valid call to qianfan."""
llm = QianfanLLMEndpoint()
output = llm('write a joke')
assert isinstance(output, str) | Test valid call to qianfan. |
router | if input['key'] == 'math':
return itemgetter('input') | math_chain
elif input['key'] == 'english':
return itemgetter('input') | english_chain
else:
raise ValueError(f"Unknown key: {input['key']}") | def router(input: Dict[str, Any]) ->Runnable:
if input['key'] == 'math':
return itemgetter('input') | math_chain
elif input['key'] == 'english':
return itemgetter('input') | english_chain
else:
raise ValueError(f"Unknown key: {input['key']}") | null |
full_key_prefix | return f'{self.key_prefix}:{self.session_id}' | @property
def full_key_prefix(self) ->str:
return f'{self.key_prefix}:{self.session_id}' | null |
test_api_key_masked_when_passed_via_constructor | llm = ChatTongyi(dashscope_api_key='secret-api-key')
print(llm.dashscope_api_key, end='')
captured = capsys.readouterr()
assert captured.out == '**********' | def test_api_key_masked_when_passed_via_constructor(capsys: CaptureFixture
) ->None:
llm = ChatTongyi(dashscope_api_key='secret-api-key')
print(llm.dashscope_api_key, end='')
captured = capsys.readouterr()
assert captured.out == '**********' | null |
parse | """Parse the output of an LLM call."""
match = re.search(self.regex, text)
if match:
return {key: match.group(i + 1) for i, key in enumerate(self.output_keys)}
elif self.default_output_key is None:
raise ValueError(f'Could not parse output: {text}')
else:
return {key: (text if key == self.default_output_key... | def parse(self, text: str) ->Dict[str, str]:
"""Parse the output of an LLM call."""
match = re.search(self.regex, text)
if match:
return {key: match.group(i + 1) for i, key in enumerate(self.
output_keys)}
elif self.default_output_key is None:
raise ValueError(f'Could not par... | Parse the output of an LLM call. |
test_parse_invalid_grammar | with pytest.raises((ValueError, lark.exceptions.UnexpectedToken)):
DEFAULT_PARSER.parse_folder(x) | @pytest.mark.parametrize('x', ('', 'foo', 'foo("bar", "baz")'))
def test_parse_invalid_grammar(x: str) ->None:
with pytest.raises((ValueError, lark.exceptions.UnexpectedToken)):
DEFAULT_PARSER.parse_folder(x) | null |
_on_llm_end | """Process the LLM Run."""
self._process_end_trace(run) | def _on_llm_end(self, run: 'Run') ->None:
"""Process the LLM Run."""
self._process_end_trace(run) | Process the LLM Run. |
__init__ | self.client = client
self.moderation_beacon = {'moderation_chain_id': chain_id,
'moderation_type': 'Toxicity', 'moderation_status': 'LABELS_NOT_FOUND'}
self.callback = callback
self.unique_id = unique_id | def __init__(self, client: Any, callback: Optional[Any]=None, unique_id:
Optional[str]=None, chain_id: Optional[str]=None) ->None:
self.client = client
self.moderation_beacon = {'moderation_chain_id': chain_id,
'moderation_type': 'Toxicity', 'moderation_status': 'LABELS_NOT_FOUND'}
self.callback... | null |
__init__ | super().__init__(criteria=criteria, **kwargs) | def __init__(self, criteria: Optional[CRITERIA_TYPE]=None, **kwargs: Any
) ->None:
super().__init__(criteria=criteria, **kwargs) | null |
test_graph_cypher_qa_chain_prompt_selection_3 | memory = ConversationBufferMemory(memory_key='chat_history')
readonlymemory = ReadOnlySharedMemory(memory=memory)
chain = GraphCypherQAChain.from_llm(llm=FakeLLM(), graph=FakeGraphStore(),
verbose=True, return_intermediate_steps=False, cypher_llm_kwargs={
'memory': readonlymemory}, qa_llm_kwargs={'memory': read... | def test_graph_cypher_qa_chain_prompt_selection_3() ->None:
memory = ConversationBufferMemory(memory_key='chat_history')
readonlymemory = ReadOnlySharedMemory(memory=memory)
chain = GraphCypherQAChain.from_llm(llm=FakeLLM(), graph=FakeGraphStore
(), verbose=True, return_intermediate_steps=False,
... | null |
batch | """Default implementation runs invoke in parallel using a thread pool executor.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch ... | def batch(self, inputs: List[Input], config: Optional[Union[RunnableConfig,
List[RunnableConfig]]]=None, *, return_exceptions: bool=False, **kwargs:
Optional[Any]) ->List[Output]:
"""Default implementation runs invoke in parallel using a thread pool executor.
The default implementation of batch wor... | Default implementation runs invoke in parallel using a thread pool executor.
The default implementation of batch works well for IO bound runnables.
Subclasses should override this method if they can batch more efficiently;
e.g., if the underlying runnable uses an API which supports a batch mode. |
_import_json_tool_JsonListKeysTool | from langchain_community.tools.json.tool import JsonListKeysTool
return JsonListKeysTool | def _import_json_tool_JsonListKeysTool() ->Any:
from langchain_community.tools.json.tool import JsonListKeysTool
return JsonListKeysTool | null |
test_openai_opeanapi | chain = get_openapi_chain(
'https://www.klarna.com/us/shopping/public/openai/v0/api-docs/')
output = chain.run(
"What are some options for a men's large blue button down shirt")
assert isinstance(output, dict) | def test_openai_opeanapi() ->None:
chain = get_openapi_chain(
'https://www.klarna.com/us/shopping/public/openai/v0/api-docs/')
output = chain.run(
"What are some options for a men's large blue button down shirt")
assert isinstance(output, dict) | null |
test_document_found | dummy_dict = {'foo': Document(page_content='bar')}
docstore = DocstoreFn(lambda x: dummy_dict[x])
output = docstore.search('foo')
assert isinstance(output, Document)
assert output.page_content == 'bar' | def test_document_found() ->None:
dummy_dict = {'foo': Document(page_content='bar')}
docstore = DocstoreFn(lambda x: dummy_dict[x])
output = docstore.search('foo')
assert isinstance(output, Document)
assert output.page_content == 'bar' | null |
parse_dependencies | num_deps = max(len(dependencies) if dependencies is not None else 0, len(
repo), len(branch))
if dependencies and len(dependencies) != num_deps or api_path and len(api_path
) != num_deps or repo and len(repo) not in [1, num_deps] or branch and len(
branch) not in [1, num_deps]:
raise ValueError(
... | def parse_dependencies(dependencies: Optional[List[str]], repo: List[str],
branch: List[str], api_path: List[str]) ->List[DependencySource]:
num_deps = max(len(dependencies) if dependencies is not None else 0,
len(repo), len(branch))
if dependencies and len(dependencies) != num_deps or api_path and ... | null |
test_openai_callback_batch_llm | llm = OpenAI(temperature=0)
with get_openai_callback() as cb:
llm.generate(['What is the square root of 4?',
'What is the square root of 4?'])
assert cb.total_tokens > 0
total_tokens = cb.total_tokens
with get_openai_callback() as cb:
llm('What is the square root of 4?')
llm('What is the square root... | def test_openai_callback_batch_llm() ->None:
llm = OpenAI(temperature=0)
with get_openai_callback() as cb:
llm.generate(['What is the square root of 4?',
'What is the square root of 4?'])
assert cb.total_tokens > 0
total_tokens = cb.total_tokens
with get_openai_callback() as cb:
... | null |
_import_office365_events_search | from langchain_community.tools.office365.events_search import O365SearchEvents
return O365SearchEvents | def _import_office365_events_search() ->Any:
from langchain_community.tools.office365.events_search import O365SearchEvents
return O365SearchEvents | null |
_create_cls_from_kwargs | index_name = kwargs.get('index_name')
if index_name is None:
raise ValueError('Please provide an index_name.')
es_connection = kwargs.get('es_connection')
es_cloud_id = kwargs.get('es_cloud_id')
es_url = kwargs.get('es_url')
es_user = kwargs.get('es_user')
es_password = kwargs.get('es_password')
es_api_key = kwargs... | @staticmethod
def _create_cls_from_kwargs(embedding: Optional[Embeddings]=None, **kwargs: Any
) ->'ElasticsearchStore':
index_name = kwargs.get('index_name')
if index_name is None:
raise ValueError('Please provide an index_name.')
es_connection = kwargs.get('es_connection')
es_cloud_id = kwa... | null |
run | """Run body through Twilio and respond with message sid.
Args:
body: The text of the message you want to send. Can be up to 1,600
characters in length.
to: The destination phone number in
[E.164](https://www.twilio.com/docs/glossary/what-e164) format for
... | def run(self, body: str, to: str) ->str:
"""Run body through Twilio and respond with message sid.
Args:
body: The text of the message you want to send. Can be up to 1,600
characters in length.
to: The destination phone number in
[E.164](https://www.tw... | Run body through Twilio and respond with message sid.
Args:
body: The text of the message you want to send. Can be up to 1,600
characters in length.
to: The destination phone number in
[E.164](https://www.twilio.com/docs/glossary/what-e164) format for
SMS/MMS or
[Channel user ad... |
_chunk | for i in range(0, len(texts), size):
yield texts[i:i + size] | def _chunk(texts: List[str], size: int) ->Iterator[List[str]]:
for i in range(0, len(texts), size):
yield texts[i:i + size] | null |
_call | _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
_run_manager.on_text(inputs[self.input_key])
llm_output = self.llm_chain.predict(question=inputs[self.input_key], stop=[
'```output'], callbacks=_run_manager.get_child())
return self._process_llm_result(llm_output, _run_manager) | def _call(self, inputs: Dict[str, str], run_manager: Optional[
CallbackManagerForChainRun]=None) ->Dict[str, str]:
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
_run_manager.on_text(inputs[self.input_key])
llm_output = self.llm_chain.predict(question=inputs[self.input_key],... | null |
similarity_search_with_score | """Perform a search on a query string and return results with score.
For more information about the search parameters, take a look at the pymilvus
documentation found here:
https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md
Args:
query (str): The text be... | def similarity_search_with_score(self, query: str, k: int=4, param:
Optional[dict]=None, expr: Optional[str]=None, timeout: Optional[int]=
None, **kwargs: Any) ->List[Tuple[Document, float]]:
"""Perform a search on a query string and return results with score.
For more information about the search ... | Perform a search on a query string and return results with score.
For more information about the search parameters, take a look at the pymilvus
documentation found here:
https://milvus.io/api-reference/pymilvus/v2.2.6/Collection/search().md
Args:
query (str): The text being searched.
k (int, optional): The am... |
transform | return self._transform_stream_with_config(input, self._transform, config,
**kwargs) | def transform(self, input: Iterator[Input], config: Optional[RunnableConfig
]=None, **kwargs: Any) ->Iterator[Output]:
return self._transform_stream_with_config(input, self._transform,
config, **kwargs) | null |
raise_deprecation | warnings.warn(
'`VectorDBQA` is deprecated - please use `from langchain.chains import RetrievalQA`'
)
return values | @root_validator()
def raise_deprecation(cls, values: Dict) ->Dict:
warnings.warn(
'`VectorDBQA` is deprecated - please use `from langchain.chains import RetrievalQA`'
)
return values | null |
_import_sql_database | from langchain_community.utilities.sql_database import SQLDatabase
return SQLDatabase | def _import_sql_database() ->Any:
from langchain_community.utilities.sql_database import SQLDatabase
return SQLDatabase | null |
similarity_search_with_score_by_vector | """Return docs most similar to embedding vector.
Args:
embedding (str): Embedding to look up documents similar to.
k (int): Number of Documents to return. Defaults to 4.
Returns:
List of (Document, score), the most similar to the query vector.
"""
return [(do... | def similarity_search_with_score_by_vector(self, embedding: List[float], k:
int=4, filter: Optional[Dict[str, str]]=None) ->List[Tuple[Document, float]
]:
"""Return docs most similar to embedding vector.
Args:
embedding (str): Embedding to look up documents similar to.
k (in... | Return docs most similar to embedding vector.
Args:
embedding (str): Embedding to look up documents similar to.
k (int): Number of Documents to return. Defaults to 4.
Returns:
List of (Document, score), the most similar to the query vector. |
_get_single_prompt | if suffix is not None:
suffix_to_use = suffix
include_df_head = True
elif include_df_in_prompt:
suffix_to_use = SUFFIX_WITH_DF
include_df_head = True
else:
suffix_to_use = SUFFIX_NO_DF
include_df_head = False
if input_variables is None:
input_variables = ['input', 'agent_scratchpad']
if ... | def _get_single_prompt(df: Any, prefix: Optional[str]=None, suffix:
Optional[str]=None, input_variables: Optional[List[str]]=None,
include_df_in_prompt: Optional[bool]=True, number_of_head_rows: int=5,
extra_tools: Sequence[BaseTool]=()) ->Tuple[BasePromptTemplate, List[
BaseTool]]:
if suffix is not... | null |
test_extra_kwargs | chat = ChatHunyuan(temperature=0.88, top_p=0.7)
assert chat.temperature == 0.88
assert chat.top_p == 0.7 | def test_extra_kwargs() ->None:
chat = ChatHunyuan(temperature=0.88, top_p=0.7)
assert chat.temperature == 0.88
assert chat.top_p == 0.7 | null |
test_valid_arguments | loader = RSpaceLoader(url=TestRSpaceLoader.url, api_key=TestRSpaceLoader.
api_key, global_id=TestRSpaceLoader.global_id)
self.assertEqual(TestRSpaceLoader.url, loader.url)
self.assertEqual(TestRSpaceLoader.api_key, loader.api_key)
self.assertEqual(TestRSpaceLoader.global_id, loader.global_id) | def test_valid_arguments(self) ->None:
loader = RSpaceLoader(url=TestRSpaceLoader.url, api_key=
TestRSpaceLoader.api_key, global_id=TestRSpaceLoader.global_id)
self.assertEqual(TestRSpaceLoader.url, loader.url)
self.assertEqual(TestRSpaceLoader.api_key, loader.api_key)
self.assertEqual(TestRSpac... | null |
multi_modal_rag_chain | """
Multi-modal RAG chain,
:param retriever: A function that retrieves the necessary context for the model.
:return: A chain of functions representing the multi-modal RAG process.
"""
model = ChatOpenAI(temperature=0, model='gpt-4-vision-preview', max_tokens=1024
)
chain = {'context': retriever | R... | def multi_modal_rag_chain(retriever):
"""
Multi-modal RAG chain,
:param retriever: A function that retrieves the necessary context for the model.
:return: A chain of functions representing the multi-modal RAG process.
"""
model = ChatOpenAI(temperature=0, model='gpt-4-vision-preview',
m... | Multi-modal RAG chain,
:param retriever: A function that retrieves the necessary context for the model.
:return: A chain of functions representing the multi-modal RAG process. |
test_php_code_splitter | splitter = RecursiveCharacterTextSplitter.from_language(Language.PHP,
chunk_size=CHUNK_SIZE, chunk_overlap=0)
code = """
<?php
function hello_world() {
echo "Hello, World!";
}
hello_world();
?>
"""
chunks = splitter.split_text(code)
assert chunks == ['<?php', 'function', 'hello_world() {', 'echo', '"Hello,... | def test_php_code_splitter() ->None:
splitter = RecursiveCharacterTextSplitter.from_language(Language.PHP,
chunk_size=CHUNK_SIZE, chunk_overlap=0)
code = """
<?php
function hello_world() {
echo "Hello, World!";
}
hello_world();
?>
"""
chunks = splitter.split_text(code)
assert chunks == ... | null |
__init__ | """Initialize a MarkdownTextSplitter."""
separators = self.get_separators_for_language(Language.MARKDOWN)
super().__init__(separators=separators, **kwargs) | def __init__(self, **kwargs: Any) ->None:
"""Initialize a MarkdownTextSplitter."""
separators = self.get_separators_for_language(Language.MARKDOWN)
super().__init__(separators=separators, **kwargs) | Initialize a MarkdownTextSplitter. |
__init__ | """Initialize MaxCompute document loader.
Args:
client: odps.ODPS MaxCompute client object.
"""
self.client = client | def __init__(self, client: ODPS):
"""Initialize MaxCompute document loader.
Args:
client: odps.ODPS MaxCompute client object.
"""
self.client = client | Initialize MaxCompute document loader.
Args:
client: odps.ODPS MaxCompute client object. |
_import_elasticsearch | from langchain_community.vectorstores.elasticsearch import ElasticsearchStore
return ElasticsearchStore | def _import_elasticsearch() ->Any:
from langchain_community.vectorstores.elasticsearch import ElasticsearchStore
return ElasticsearchStore | null |
test_unstructured_tsv_loader | """Test unstructured loader."""
file_path = os.path.join(EXAMPLE_DIRECTORY, 'stanley-cups.tsv')
loader = UnstructuredTSVLoader(str(file_path))
docs = loader.load()
assert len(docs) == 1 | def test_unstructured_tsv_loader() ->None:
"""Test unstructured loader."""
file_path = os.path.join(EXAMPLE_DIRECTORY, 'stanley-cups.tsv')
loader = UnstructuredTSVLoader(str(file_path))
docs = loader.load()
assert len(docs) == 1 | Test unstructured loader. |
test_pai_eas_v1_streaming | """Test streaming call to PAI-EAS Service."""
llm = PaiEasEndpoint(eas_service_url=os.getenv('EAS_SERVICE_URL'),
eas_service_token=os.getenv('EAS_SERVICE_TOKEN'), version='1.0')
generator = llm.stream("Q: How do you say 'hello' in German? A:'", stop=['.'])
stream_results_string = ''
assert isinstance(generator, Gen... | def test_pai_eas_v1_streaming() ->None:
"""Test streaming call to PAI-EAS Service."""
llm = PaiEasEndpoint(eas_service_url=os.getenv('EAS_SERVICE_URL'),
eas_service_token=os.getenv('EAS_SERVICE_TOKEN'), version='1.0')
generator = llm.stream("Q: How do you say 'hello' in German? A:'", stop
=[... | Test streaming call to PAI-EAS Service. |
test_results_exists | """Test that results gives the correct output format."""
search = api_client.results(query='What is the best programming language?',
sort='relevance', time_filter='all', subreddit='all', limit=10)
assert_results_exists(search) | @pytest.mark.requires('praw')
def test_results_exists(api_client: RedditSearchAPIWrapper) ->None:
"""Test that results gives the correct output format."""
search = api_client.results(query=
'What is the best programming language?', sort='relevance',
time_filter='all', subreddit='all', limit=10)
... | Test that results gives the correct output format. |
add | """Add a sequence of addable objects together."""
final = None
for chunk in addables:
if final is None:
final = chunk
else:
final = final + chunk
return final | def add(addables: Iterable[Addable]) ->Optional[Addable]:
"""Add a sequence of addable objects together."""
final = None
for chunk in addables:
if final is None:
final = chunk
else:
final = final + chunk
return final | Add a sequence of addable objects together. |
_reset | _task_type = task_type if task_type else self.task_type
_workspace = workspace if workspace else self.workspace
_project_name = project_name if project_name else self.project_name
_tags = tags if tags else self.tags
_name = name if name else self.name
_visualizations = visualizations if visualizations else self.visuali... | def _reset(self, task_type: Optional[str]=None, workspace: Optional[str]=
None, project_name: Optional[str]=None, tags: Optional[Sequence]=None,
name: Optional[str]=None, visualizations: Optional[List[str]]=None,
complexity_metrics: bool=False, custom_metrics: Optional[Callable]=None
) ->None:
_task... | null |
similarity_search_by_vector_with_score | """Return docs most similar to the embedding and their cosine distance.
Args:
embedding: Embedding to look up documents similar to.
k: Number of Documents to return. Defaults to 4.
filter: Optional. A list of Namespaces for filtering
the matching results.
... | def similarity_search_by_vector_with_score(self, embedding: List[float], k:
int=4, filter: Optional[List[Namespace]]=None) ->List[Tuple[Document,
float]]:
"""Return docs most similar to the embedding and their cosine distance.
Args:
embedding: Embedding to look up documents similar to.
... | Return docs most similar to the embedding and their cosine distance.
Args:
embedding: Embedding to look up documents similar to.
k: Number of Documents to return. Defaults to 4.
filter: Optional. A list of Namespaces for filtering
the matching results.
For example:
[Namespace("color... |
__init__ | self.segment_sentences = segment_sentences
self.grobid_server = grobid_server
try:
requests.get(grobid_server)
except requests.exceptions.RequestException:
logger.error(
'GROBID server does not appear up and running, please ensure Grobid is installed and the server is running'
)
... | def __init__(self, segment_sentences: bool, grobid_server: str=
'http://localhost:8070/api/processFulltextDocument') ->None:
self.segment_sentences = segment_sentences
self.grobid_server = grobid_server
try:
requests.get(grobid_server)
except requests.exceptions.RequestException:
log... | null |
max_marginal_relevance_search_by_vector | """Perform a search and return results that are reordered by MMR."""
filter = None if expr is None else self.document.Filter(expr)
ef = 10 if param is None else param.get('ef', 10)
res: List[List[Dict]] = self.collection.search(vectors=[embedding], filter=
filter, params=self.document.HNSWSearchParams(ef=ef), retri... | def max_marginal_relevance_search_by_vector(self, embedding: list[float], k:
int=4, fetch_k: int=20, lambda_mult: float=0.5, param: Optional[dict]=
None, expr: Optional[str]=None, timeout: Optional[int]=None, **kwargs: Any
) ->List[Document]:
"""Perform a search and return results that are reordered by ... | Perform a search and return results that are reordered by MMR. |
test_memory_with_message_store | """Test the memory with a message store."""
message_history = SingleStoreDBChatMessageHistory(session_id='test-session',
host=TEST_SINGLESTOREDB_URL)
memory = ConversationBufferMemory(memory_key='baz', chat_memory=
message_history, return_messages=True)
memory.chat_memory.add_ai_message('This is me, the AI')
me... | def test_memory_with_message_store() ->None:
"""Test the memory with a message store."""
message_history = SingleStoreDBChatMessageHistory(session_id=
'test-session', host=TEST_SINGLESTOREDB_URL)
memory = ConversationBufferMemory(memory_key='baz', chat_memory=
message_history, return_message... | Test the memory with a message store. |
from_text | """Get an OpenAPI spec from a text."""
try:
spec_dict = json.loads(text)
except json.JSONDecodeError:
spec_dict = yaml.safe_load(text)
return cls.from_spec_dict(spec_dict) | @classmethod
def from_text(cls, text: str) ->OpenAPISpec:
"""Get an OpenAPI spec from a text."""
try:
spec_dict = json.loads(text)
except json.JSONDecodeError:
spec_dict = yaml.safe_load(text)
return cls.from_spec_dict(spec_dict) | Get an OpenAPI spec from a text. |
from_texts | """Construct Meilisearch wrapper from raw documents.
This is a user-friendly interface that:
1. Embeds documents.
2. Adds the documents to a provided Meilisearch index.
This is intended to be a quick way to get started.
Example:
.. code-block:: python
... | @classmethod
def from_texts(cls: Type[Meilisearch], texts: List[str], embedding:
Embeddings, metadatas: Optional[List[dict]]=None, client: Optional[
Client]=None, url: Optional[str]=None, api_key: Optional[str]=None,
index_name: str='langchain-demo', ids: Optional[List[str]]=None,
text_key: Optional[str... | Construct Meilisearch wrapper from raw documents.
This is a user-friendly interface that:
1. Embeds documents.
2. Adds the documents to a provided Meilisearch index.
This is intended to be a quick way to get started.
Example:
.. code-block:: python
from langchain_community.vectorstores import Me... |
embeddings | return self.embedding | @property
def embeddings(self) ->Embeddings:
return self.embedding | null |
validate_environment | """Validate that api key and python package exists in environment."""
values['gradient_access_token'] = get_from_dict_or_env(values,
'gradient_access_token', 'GRADIENT_ACCESS_TOKEN')
values['gradient_workspace_id'] = get_from_dict_or_env(values,
'gradient_workspace_id', 'GRADIENT_WORKSPACE_ID')
values['gradient... | @root_validator(allow_reuse=True)
def validate_environment(cls, values: Dict) ->Dict:
"""Validate that api key and python package exists in environment."""
values['gradient_access_token'] = get_from_dict_or_env(values,
'gradient_access_token', 'GRADIENT_ACCESS_TOKEN')
values['gradient_workspace_id']... | Validate that api key and python package exists in environment. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.