method_name
stringlengths
1
78
method_body
stringlengths
3
9.66k
full_code
stringlengths
31
10.7k
docstring
stringlengths
4
4.74k
__init__
"""Initialize with webpage path and optional filter URLs. Args: web_path: url of the sitemap. can also be a local path filter_urls: a list of regexes. If specified, only URLS that match one of the filter URLs will be loaded. *WARNING* The filter URLs are ...
def __init__(self, web_path: str, filter_urls: Optional[List[str]]=None, parsing_function: Optional[Callable]=None, blocksize: Optional[int]= None, blocknum: int=0, meta_function: Optional[Callable]=None, is_local: bool=False, continue_on_failure: bool=False, restrict_to_same_domain: bool=True, **kwargs...
Initialize with webpage path and optional filter URLs. Args: web_path: url of the sitemap. can also be a local path filter_urls: a list of regexes. If specified, only URLS that match one of the filter URLs will be loaded. *WARNING* The filter URLs are interpreted as regular expressions. ...
sample_gdf
import geopandas path_to_data = geopandas.datasets.get_path('nybb') gdf = geopandas.read_file(path_to_data) gdf['area'] = gdf.area gdf['crs'] = gdf.crs.to_string() return gdf.head(2)
@pytest.mark.requires('geopandas') def sample_gdf() ->GeoDataFrame: import geopandas path_to_data = geopandas.datasets.get_path('nybb') gdf = geopandas.read_file(path_to_data) gdf['area'] = gdf.area gdf['crs'] = gdf.crs.to_string() return gdf.head(2)
null
output_keys
"""Input keys this chain returns.""" return self.output_variables
@property def output_keys(self) ->List[str]: """Input keys this chain returns.""" return self.output_variables
Input keys this chain returns.
validate_top_k
if value < 0: raise ValueError(f'top_k ({value}) cannot be negative.') return value
@validator('top_k') def validate_top_k(cls, value: int) ->int: if value < 0: raise ValueError(f'top_k ({value}) cannot be negative.') return value
null
delete
"""Delete by vector IDs. Args: ids: List of ids to delete. """ if ids is None: raise ValueError('No ids provided to delete.') for id in ids: self._client.data_object.delete(uuid=id)
def delete(self, ids: Optional[List[str]]=None, **kwargs: Any) ->None: """Delete by vector IDs. Args: ids: List of ids to delete. """ if ids is None: raise ValueError('No ids provided to delete.') for id in ids: self._client.data_object.delete(uuid=id)
Delete by vector IDs. Args: ids: List of ids to delete.
_run
return f'{arg1} {arg2} {arg3}'
def _run(self, arg1: int, arg2: bool, arg3: Optional[dict]=None) ->str: return f'{arg1} {arg2} {arg3}'
null
comment_on_issue
""" Adds a comment to a github issue Parameters: comment_query(str): a string which contains the issue number, two newlines, and the comment. for example: "1 Working on it now" adds the comment "working on it now" to issue 1 Returns: s...
def comment_on_issue(self, comment_query: str) ->str: """ Adds a comment to a github issue Parameters: comment_query(str): a string which contains the issue number, two newlines, and the comment. for example: "1 Working on it now" adds the comment "wo...
Adds a comment to a github issue Parameters: comment_query(str): a string which contains the issue number, two newlines, and the comment. for example: "1 Working on it now" adds the comment "working on it now" to issue 1 Returns: str: ...
from_agent_and_tools
"""Create from agent and tools.""" return cls(agent=agent, tools=tools, callbacks=callbacks, **kwargs)
@classmethod def from_agent_and_tools(cls, agent: Union[BaseSingleActionAgent, BaseMultiActionAgent], tools: Sequence[BaseTool], callbacks: Callbacks= None, **kwargs: Any) ->AgentExecutor: """Create from agent and tools.""" return cls(agent=agent, tools=tools, callbacks=callbacks, **kwargs)
Create from agent and tools.
_load_pubmed_from_universal_entry
from langchain.agents.load_tools import load_tools tools = load_tools(['pubmed'], **kwargs) assert len(tools) == 1, 'loaded more than 1 tool' return tools[0]
def _load_pubmed_from_universal_entry(**kwargs: Any) ->BaseTool: from langchain.agents.load_tools import load_tools tools = load_tools(['pubmed'], **kwargs) assert len(tools) == 1, 'loaded more than 1 tool' return tools[0]
null
get_full_inputs
"""Create the full inputs for the LLMChain from intermediate steps.""" thoughts = self._construct_scratchpad(intermediate_steps) new_inputs = {'agent_scratchpad': thoughts, 'stop': self._stop} full_inputs = {**kwargs, **new_inputs} return full_inputs
def get_full_inputs(self, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any) ->Dict[str, Any]: """Create the full inputs for the LLMChain from intermediate steps.""" thoughts = self._construct_scratchpad(intermediate_steps) new_inputs = {'agent_scratchpad': thoughts, 'stop': self._stop} ...
Create the full inputs for the LLMChain from intermediate steps.
validate_environment
"""Validate that api key and python package exists in environment.""" deepinfra_api_token = get_from_dict_or_env(values, 'deepinfra_api_token', 'DEEPINFRA_API_TOKEN') values['deepinfra_api_token'] = deepinfra_api_token return values
@root_validator() def validate_environment(cls, values: Dict) ->Dict: """Validate that api key and python package exists in environment.""" deepinfra_api_token = get_from_dict_or_env(values, 'deepinfra_api_token', 'DEEPINFRA_API_TOKEN') values['deepinfra_api_token'] = deepinfra_api_token return ...
Validate that api key and python package exists in environment.
_get_resource
endpoint = STRIPE_ENDPOINTS.get(self.resource) if endpoint is None: return [] return self._make_request(endpoint)
def _get_resource(self) ->List[Document]: endpoint = STRIPE_ENDPOINTS.get(self.resource) if endpoint is None: return [] return self._make_request(endpoint)
null
_search
""" Perform a search using the query embedding and return top_k documents. Args: query_emb: Query represented as an embedding top_k: Number of documents to return Returns: A list of top_k documents matching the query """ from docarray.index import El...
def _search(self, query_emb: np.ndarray, top_k: int) ->List[Union[Dict[str, Any], Any]]: """ Perform a search using the query embedding and return top_k documents. Args: query_emb: Query represented as an embedding top_k: Number of documents to return Returns: ...
Perform a search using the query embedding and return top_k documents. Args: query_emb: Query represented as an embedding top_k: Number of documents to return Returns: A list of top_k documents matching the query
add_texts
batch_size = kwargs.get('batch_size', DEFAULT_INSERT_BATCH_SIZE) _metadatas: Union[List, Generator] = metadatas or ({} for _ in texts) texts_batch = [] metadatas_batch = [] result_ids = [] for i, (text, metadata) in enumerate(zip(texts, _metadatas)): texts_batch.append(text) metadatas_batch.append(metadata) ...
def add_texts(self, texts: Iterable[str], metadatas: Optional[List[Dict[str, Any]]]=None, **kwargs: Any) ->List: batch_size = kwargs.get('batch_size', DEFAULT_INSERT_BATCH_SIZE) _metadatas: Union[List, Generator] = metadatas or ({} for _ in texts) texts_batch = [] metadatas_batch = [] result_ids...
null
test__init__
"""Test initialization from init.""" loader = GenericLoader(FileSystemBlobLoader(toy_dir, suffixes=['.txt']), AsIsParser()) docs = loader.load() assert len(docs) == 3 assert docs[0].page_content == 'This is a test.txt file.'
def test__init__(toy_dir: str) ->None: """Test initialization from init.""" loader = GenericLoader(FileSystemBlobLoader(toy_dir, suffixes=['.txt']), AsIsParser()) docs = loader.load() assert len(docs) == 3 assert docs[0].page_content == 'This is a test.txt file.'
Test initialization from init.
process_pdf
try: import pytesseract from pdf2image import convert_from_bytes except ImportError: raise ImportError( '`pytesseract` or `pdf2image` package not found, please run `pip install pytesseract pdf2image`' ) response = self.confluence.request(path=link, absolute=True) text = '' if response.status...
def process_pdf(self, link: str, ocr_languages: Optional[str]=None) ->str: try: import pytesseract from pdf2image import convert_from_bytes except ImportError: raise ImportError( '`pytesseract` or `pdf2image` package not found, please run `pip install pytesseract pdf2image`' ...
null
test_append
zep_chat.add_message(AIMessage(content='test message')) zep_chat.zep_client.memory.add_memory.assert_called_once()
@pytest.mark.requires('zep_python') def test_append(mocker: MockerFixture, zep_chat: ZepChatMessageHistory) ->None: zep_chat.add_message(AIMessage(content='test message')) zep_chat.zep_client.memory.add_memory.assert_called_once()
null
create_spark_dataframe_agent
"""Construct a Spark agent from an LLM and dataframe.""" if not _validate_spark_df(df) and not _validate_spark_connect_df(df): raise ImportError('Spark is not installed. run `pip install pyspark`.') if input_variables is None: input_variables = ['df', 'input', 'agent_scratchpad'] tools = [PythonAstREPLTool(loca...
def create_spark_dataframe_agent(llm: BaseLLM, df: Any, callback_manager: Optional[BaseCallbackManager]=None, prefix: str=PREFIX, suffix: str= SUFFIX, input_variables: Optional[List[str]]=None, verbose: bool=False, return_intermediate_steps: bool=False, max_iterations: Optional[int]=15, max_execution_ti...
Construct a Spark agent from an LLM and dataframe.
__copy__
"""Copy the tracer.""" return self
def __copy__(self) ->BaseTracer: """Copy the tracer.""" return self
Copy the tracer.
_create_retry_decorator
min_seconds = 1 max_seconds = 4 return retry(reraise=True, stop=stop_after_attempt(llm.max_retries), wait= wait_exponential(multiplier=1, min=min_seconds, max=max_seconds), retry =retry_if_exception_type(HTTPError), before_sleep=before_sleep_log( logger, logging.WARNING))
def _create_retry_decorator(llm: Tongyi) ->Callable[[Any], Any]: min_seconds = 1 max_seconds = 4 return retry(reraise=True, stop=stop_after_attempt(llm.max_retries), wait=wait_exponential(multiplier=1, min=min_seconds, max= max_seconds), retry=retry_if_exception_type(HTTPError), befo...
null
_get_llm_math
return Tool(name='Calculator', description= 'Useful for when you need to answer questions about math.', func= LLMMathChain.from_llm(llm=llm).run, coroutine=LLMMathChain.from_llm(llm =llm).arun)
def _get_llm_math(llm: BaseLanguageModel) ->BaseTool: return Tool(name='Calculator', description= 'Useful for when you need to answer questions about math.', func= LLMMathChain.from_llm(llm=llm).run, coroutine=LLMMathChain.from_llm (llm=llm).arun)
null
_submit
"""Submit a function to the executor.""" if self.executor is None: function(run) else: self._futures.add(self.executor.submit(function, run))
def _submit(self, function: Callable[[Run], None], run: Run) ->None: """Submit a function to the executor.""" if self.executor is None: function(run) else: self._futures.add(self.executor.submit(function, run))
Submit a function to the executor.
search_api
"""Search the API for the query.""" assert isinstance(query, str) return f'API result - {query}'
@tool('search') def search_api(query: str) ->str: """Search the API for the query.""" assert isinstance(query, str) return f'API result - {query}'
Search the API for the query.
validate_prompt_input_variables
"""Validate that prompt input variables are consistent.""" prompt_variables = values['prompt'].input_variables expected_keys = {'summary', 'new_lines'} if expected_keys != set(prompt_variables): raise ValueError( f'Got unexpected prompt input variables. The prompt expects {prompt_variables}, but it should h...
@root_validator() def validate_prompt_input_variables(cls, values: Dict) ->Dict: """Validate that prompt input variables are consistent.""" prompt_variables = values['prompt'].input_variables expected_keys = {'summary', 'new_lines'} if expected_keys != set(prompt_variables): raise ValueError( ...
Validate that prompt input variables are consistent.
format_prompt
for k, prompt in self.pipeline_prompts: _inputs = _get_inputs(kwargs, prompt.input_variables) if isinstance(prompt, BaseChatPromptTemplate): kwargs[k] = prompt.format_messages(**_inputs) else: kwargs[k] = prompt.format(**_inputs) _inputs = _get_inputs(kwargs, self.final_prompt.input_variable...
def format_prompt(self, **kwargs: Any) ->PromptValue: for k, prompt in self.pipeline_prompts: _inputs = _get_inputs(kwargs, prompt.input_variables) if isinstance(prompt, BaseChatPromptTemplate): kwargs[k] = prompt.format_messages(**_inputs) else: kwargs[k] = prompt.fo...
null
_fstring_JoinedStr
for value in t.values: meth = getattr(self, '_fstring_' + type(value).__name__) meth(value, write)
def _fstring_JoinedStr(self, t, write): for value in t.values: meth = getattr(self, '_fstring_' + type(value).__name__) meth(value, write)
null
test_similarity_search_with_metadata
"""Test end to end construction and search with metadata.""" texts = ['foo', 'bar', 'baz'] metadatas = [{'page': i} for i in range(len(texts))] docsearch = ElasticsearchStore.from_texts(texts, ConsistentFakeEmbeddings(), metadatas=metadatas, **elasticsearch_connection, index_name=index_name) output = docsearch.simi...
def test_similarity_search_with_metadata(self, elasticsearch_connection: dict, index_name: str) ->None: """Test end to end construction and search with metadata.""" texts = ['foo', 'bar', 'baz'] metadatas = [{'page': i} for i in range(len(texts))] docsearch = ElasticsearchStore.from_texts(texts, ...
Test end to end construction and search with metadata.
on_chain_end
"""Run when chain ends running.""" self.metrics['step'] += 1 self.metrics['chain_ends'] += 1 self.metrics['ends'] += 1 chain_ends = self.metrics['chain_ends'] resp: Dict[str, Any] = {} chain_output = ','.join([f'{k}={v}' for k, v in outputs.items()]) resp.update({'action': 'on_chain_end', 'outputs': chain_output}) resp...
def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) ->None: """Run when chain ends running.""" self.metrics['step'] += 1 self.metrics['chain_ends'] += 1 self.metrics['ends'] += 1 chain_ends = self.metrics['chain_ends'] resp: Dict[str, Any] = {} chain_output = ','.join([f'{k}={v}' ...
Run when chain ends running.
_import_vectorstore_tool_VectorStoreQAWithSourcesTool
from langchain_community.tools.vectorstore.tool import VectorStoreQAWithSourcesTool return VectorStoreQAWithSourcesTool
def _import_vectorstore_tool_VectorStoreQAWithSourcesTool() ->Any: from langchain_community.tools.vectorstore.tool import VectorStoreQAWithSourcesTool return VectorStoreQAWithSourcesTool
null
test_integration_question
"""Test question about integration that needs sympy""" question = 'What is the integral of e^-x from 0 to infinity?' output = fake_llm_symbolic_math_chain.run(question) assert output == 'Answer: 1'
def test_integration_question(fake_llm_symbolic_math_chain: LLMSymbolicMathChain) ->None: """Test question about integration that needs sympy""" question = 'What is the integral of e^-x from 0 to infinity?' output = fake_llm_symbolic_math_chain.run(question) assert output == 'Answer: 1'
Test question about integration that needs sympy
reset_deanonymizer_mapping
"""Abstract method to reset deanonymizer mapping"""
@abstractmethod def reset_deanonymizer_mapping(self) ->None: """Abstract method to reset deanonymizer mapping"""
Abstract method to reset deanonymizer mapping
lazy_load
"""Lazy load Documents from URLs.""" for url in self.urls: if self.text_content: response = requests.post('https://chrome.browserless.io/scrape', params={'token': self.api_token}, json={'url': url, 'elements': [{'selector': 'body'}]}) yield Document(page_content=response.json...
def lazy_load(self) ->Iterator[Document]: """Lazy load Documents from URLs.""" for url in self.urls: if self.text_content: response = requests.post('https://chrome.browserless.io/scrape', params={'token': self.api_token}, json={'url': url, 'elements': [{'selec...
Lazy load Documents from URLs.
test_astradb_vectorstore_metadata
"""Metadata filtering.""" store_someemb.add_documents([Document(page_content='q', metadata={'ord': ord('q'), 'group': 'consonant'}), Document(page_content='w', metadata={ 'ord': ord('w'), 'group': 'consonant'}), Document(page_content='r', metadata={'ord': ord('r'), 'group': 'consonant'}), Document( page...
def test_astradb_vectorstore_metadata(self, store_someemb: AstraDB) ->None: """Metadata filtering.""" store_someemb.add_documents([Document(page_content='q', metadata={'ord': ord('q'), 'group': 'consonant'}), Document(page_content='w', metadata={'ord': ord('w'), 'group': 'consonant'}), Document(...
Metadata filtering.
validate_environment
"""Validate that api key and python package exists in environment.""" openai_api_key = get_from_dict_or_env(values, 'openai_api_key', 'OPENAI_API_KEY') openai_organization = get_from_dict_or_env(values, 'openai_organization', 'OPENAI_ORGANIZATION', default='') try: import openai openai.api_key = openai_...
@root_validator() def validate_environment(cls, values: Dict) ->Dict: """Validate that api key and python package exists in environment.""" openai_api_key = get_from_dict_or_env(values, 'openai_api_key', 'OPENAI_API_KEY') openai_organization = get_from_dict_or_env(values, 'openai_organizatio...
Validate that api key and python package exists in environment.
to_doc
"""Converts this item to a Document.""" page_content = page_content_formatter(self) metadata = self.get_additional_metadata() metadata.update({'result_id': self.Id, 'document_id': self.DocumentId, 'source': self.DocumentURI, 'title': self.get_title(), 'excerpt': self. get_excerpt(), 'document_attributes': self....
def to_doc(self, page_content_formatter: Callable[['ResultItem'], str]= combined_text) ->Document: """Converts this item to a Document.""" page_content = page_content_formatter(self) metadata = self.get_additional_metadata() metadata.update({'result_id': self.Id, 'document_id': self.DocumentId, ...
Converts this item to a Document.
on_tool_start
"""Run when tool starts running.""" self.step += 1 self.tool_starts += 1 self.starts += 1 resp = self._init_resp() resp.update({'action': 'on_tool_start', 'input_str': input_str}) resp.update(flatten_dict(serialized)) resp.update(self.get_custom_callback_meta()) self.on_tool_start_records.append(resp) self.action_recor...
def on_tool_start(self, serialized: Dict[str, Any], input_str: str, ** kwargs: Any) ->None: """Run when tool starts running.""" self.step += 1 self.tool_starts += 1 self.starts += 1 resp = self._init_resp() resp.update({'action': 'on_tool_start', 'input_str': input_str}) resp.update(flat...
Run when tool starts running.
test_vertex_generate
llm = VertexAI(temperature=0.3, n=2, model_name='text-bison@001') output = llm.generate(['Say foo:']) assert isinstance(output, LLMResult) assert len(output.generations) == 1 assert len(output.generations[0]) == 2
@pytest.mark.scheduled def test_vertex_generate() ->None: llm = VertexAI(temperature=0.3, n=2, model_name='text-bison@001') output = llm.generate(['Say foo:']) assert isinstance(output, LLMResult) assert len(output.generations) == 1 assert len(output.generations[0]) == 2
null
lazy_load
"""Lazy load given path as pages.""" if self.web_path: blob = Blob.from_data(open(self.file_path, 'rb').read(), path=self.web_path ) else: blob = Blob.from_path(self.file_path) yield from self.parser.parse_folder(blob)
def lazy_load(self) ->Iterator[Document]: """Lazy load given path as pages.""" if self.web_path: blob = Blob.from_data(open(self.file_path, 'rb').read(), path=self. web_path) else: blob = Blob.from_path(self.file_path) yield from self.parser.parse_folder(blob)
Lazy load given path as pages.
_lambda
if x == 1: raise ValueError('x is 1') elif x == 2: raise RuntimeError('x is 2') else: return x
def _lambda(x: int) ->Union[int, Runnable]: if x == 1: raise ValueError('x is 1') elif x == 2: raise RuntimeError('x is 2') else: return x
null
login
"""Authenticate using the Slack API.""" try: from slack_sdk import WebClient except ImportError as e: raise ImportError( 'Cannot import slack_sdk. Please install the package with `pip install slack_sdk`.' ) from e if 'SLACK_BOT_TOKEN' in os.environ: token = os.environ['SLACK_BOT_...
def login() ->WebClient: """Authenticate using the Slack API.""" try: from slack_sdk import WebClient except ImportError as e: raise ImportError( 'Cannot import slack_sdk. Please install the package with `pip install slack_sdk`.' ) from e if 'SLACK_BOT...
Authenticate using the Slack API.
_extract_scheme_and_domain
"""Extract the scheme + domain from a given URL. Args: url (str): The input URL. Returns: return a 2-tuple of scheme and domain """ parsed_uri = urlparse(url) return parsed_uri.scheme, parsed_uri.netloc
def _extract_scheme_and_domain(url: str) ->Tuple[str, str]: """Extract the scheme + domain from a given URL. Args: url (str): The input URL. Returns: return a 2-tuple of scheme and domain """ parsed_uri = urlparse(url) return parsed_uri.scheme, parsed_uri.netloc
Extract the scheme + domain from a given URL. Args: url (str): The input URL. Returns: return a 2-tuple of scheme and domain
_get_notes
has_more = True page = 1 while has_more: req_note = urllib.request.Request(self._get_note_url.format(page=page)) with urllib.request.urlopen(req_note) as response: json_data = json.loads(response.read().decode()) for note in json_data['items']: metadata = {'source': LINK_NOTE_TEMPLAT...
def _get_notes(self) ->Iterator[Document]: has_more = True page = 1 while has_more: req_note = urllib.request.Request(self._get_note_url.format(page=page)) with urllib.request.urlopen(req_note) as response: json_data = json.loads(response.read().decode()) for note in ...
null
test_dir
return Path(os.path.join(PROJECT_DIR, 'tests', 'integration_tests'))
@pytest.fixture(scope='module') def test_dir() ->Path: return Path(os.path.join(PROJECT_DIR, 'tests', 'integration_tests'))
null
save_context
"""Save context from this conversation to buffer.""" input_str, output_str = self._get_input_output(inputs, outputs) self.chat_memory.add_user_message(input_str) self.chat_memory.add_ai_message(output_str)
def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) ->None: """Save context from this conversation to buffer.""" input_str, output_str = self._get_input_output(inputs, outputs) self.chat_memory.add_user_message(input_str) self.chat_memory.add_ai_message(output_str)
Save context from this conversation to buffer.
similarity_search
"""Run similarity search Args: query (str): The query text for which to find similar documents. k (int): The number of documents to return. Default is 4. filter (RedisFilterExpression, optional): Optional metadata filter. Defaults to None. return_...
def similarity_search(self, query: str, k: int=4, filter: Optional[ RedisFilterExpression]=None, return_metadata: bool=True, distance_threshold: Optional[float]=None, **kwargs: Any) ->List[Document]: """Run similarity search Args: query (str): The query text for which to find similar do...
Run similarity search Args: query (str): The query text for which to find similar documents. k (int): The number of documents to return. Default is 4. filter (RedisFilterExpression, optional): Optional metadata filter. Defaults to None. return_metadata (bool, optional): Whether to return metada...
test_chat_openai_streaming
"""Test that streaming correctly invokes on_llm_new_token callback.""" callback_handler = FakeCallbackHandler() callback_manager = CallbackManager([callback_handler]) chat = ChatOpenAI(max_tokens=10, streaming=True, temperature=0, callback_manager=callback_manager, verbose=True) message = HumanMessage(content='Hell...
@pytest.mark.scheduled def test_chat_openai_streaming() ->None: """Test that streaming correctly invokes on_llm_new_token callback.""" callback_handler = FakeCallbackHandler() callback_manager = CallbackManager([callback_handler]) chat = ChatOpenAI(max_tokens=10, streaming=True, temperature=0, c...
Test that streaming correctly invokes on_llm_new_token callback.
test_titan_takeoff_call
"""Test valid call to Titan Takeoff.""" url = 'http://localhost:8000/generate' responses.add(responses.POST, url, json={'message': '2 + 2 is 4'}, status=200) llm = TitanTakeoff() output = llm('What is 2 + 2?') assert isinstance(output, str)
@responses.activate def test_titan_takeoff_call() ->None: """Test valid call to Titan Takeoff.""" url = 'http://localhost:8000/generate' responses.add(responses.POST, url, json={'message': '2 + 2 is 4'}, status=200) llm = TitanTakeoff() output = llm('What is 2 + 2?') assert isinstance(ou...
Test valid call to Titan Takeoff.
dumps
"""Return a json string representation of an object.""" if 'default' in kwargs: raise ValueError('`default` should not be passed to dumps') try: if pretty: indent = kwargs.pop('indent', 2) return json.dumps(obj, default=default, indent=indent, **kwargs) else: return json.dumps(obj, d...
def dumps(obj: Any, *, pretty: bool=False, **kwargs: Any) ->str: """Return a json string representation of an object.""" if 'default' in kwargs: raise ValueError('`default` should not be passed to dumps') try: if pretty: indent = kwargs.pop('indent', 2) return json.du...
Return a json string representation of an object.
test_load_success_all_meta
api_client.load_all_available_meta = True docs = api_client.load('HUNTER X HUNTER') assert len(docs) > 1 assert len(docs) <= 3 assert_docs(docs, all_meta=True)
def test_load_success_all_meta(api_client: WikipediaAPIWrapper) ->None: api_client.load_all_available_meta = True docs = api_client.load('HUNTER X HUNTER') assert len(docs) > 1 assert len(docs) <= 3 assert_docs(docs, all_meta=True)
null
batched
iterator = iter(iterable) while (batch := list(islice(iterator, batch_size))): yield batch
def batched(iterable: Iterable[Any], batch_size: int) ->Iterable[Any]: iterator = iter(iterable) while (batch := list(islice(iterator, batch_size))): yield batch
null
test_visit_comparison_ne
comp = Comparison(comparator=Comparator.NE, attribute='name', value='foo') expected = {'name': {'$ne': 'foo'}} actual = DEFAULT_TRANSLATOR.visit_comparison(comp) assert expected == actual
def test_visit_comparison_ne() ->None: comp = Comparison(comparator=Comparator.NE, attribute='name', value='foo') expected = {'name': {'$ne': 'foo'}} actual = DEFAULT_TRANSLATOR.visit_comparison(comp) assert expected == actual
null
test_mosaicml_embedding_documents_multiple
"""Test MosaicML embeddings with multiple documents.""" documents = ['foo bar', 'bar foo', 'foo'] embedding = MosaicMLInstructorEmbeddings() output = embedding.embed_documents(documents) assert len(output) == 3 assert len(output[0]) == 768 assert len(output[1]) == 768 assert len(output[2]) == 768
def test_mosaicml_embedding_documents_multiple() ->None: """Test MosaicML embeddings with multiple documents.""" documents = ['foo bar', 'bar foo', 'foo'] embedding = MosaicMLInstructorEmbeddings() output = embedding.embed_documents(documents) assert len(output) == 3 assert len(output[0]) == 768...
Test MosaicML embeddings with multiple documents.
_get_memory
"""Retrieve memory from Zep""" from zep_python import NotFoundError try: zep_memory: Memory = self.zep_client.memory.get_memory(self.session_id) except NotFoundError: logger.warning( f'Session {self.session_id} not found in Zep. Returning None') return None return zep_memory
def _get_memory(self) ->Optional[Memory]: """Retrieve memory from Zep""" from zep_python import NotFoundError try: zep_memory: Memory = self.zep_client.memory.get_memory(self.session_id) except NotFoundError: logger.warning( f'Session {self.session_id} not found in Zep. Retur...
Retrieve memory from Zep
on_llm_error
"""Run when LLM errors. Args: error (Exception or KeyboardInterrupt): The error. kwargs (Any): Additional keyword arguments. - response (LLMResult): The response which was generated before the error occurred. """ handle_event(self.handlers, 'o...
def on_llm_error(self, error: BaseException, **kwargs: Any) ->None: """Run when LLM errors. Args: error (Exception or KeyboardInterrupt): The error. kwargs (Any): Additional keyword arguments. - response (LLMResult): The response which was generated before ...
Run when LLM errors. Args: error (Exception or KeyboardInterrupt): The error. kwargs (Any): Additional keyword arguments. - response (LLMResult): The response which was generated before the error occurred.
_prepare_output
""" Prepare the output dictionary. Args: result (Dict[str, Any]): The evaluation results. Returns: Dict[str, Any]: The prepared output dictionary. """ result = {'score': result['score']} if RUN_KEY in result: result[RUN_KEY] = result[RUN_KEY].dict() return r...
def _prepare_output(self, result: Dict[str, Any]) ->Dict[str, Any]: """ Prepare the output dictionary. Args: result (Dict[str, Any]): The evaluation results. Returns: Dict[str, Any]: The prepared output dictionary. """ result = {'score': result['score']}...
Prepare the output dictionary. Args: result (Dict[str, Any]): The evaluation results. Returns: Dict[str, Any]: The prepared output dictionary.
client_search
version_num = client.info()['version']['number'][0] version_num = int(version_num) if version_num >= 8: response = client.search(index=index_name, query=script_query, size=size) else: response = client.search(index=index_name, body={'query': script_query, 'size': size}) return response
def client_search(self, client: Any, index_name: str, script_query: Dict, size: int) ->Any: version_num = client.info()['version']['number'][0] version_num = int(version_num) if version_num >= 8: response = client.search(index=index_name, query=script_query, size =size) else: ...
null
on_agent_action
self.on_agent_action_common()
def on_agent_action(self, *args: Any, **kwargs: Any) ->Any: self.on_agent_action_common()
null
test_couchbase_loader
"""Test Couchbase loader.""" loader = CouchbaseLoader(connection_string=self.conn_string, db_username= self.database_user, db_password=self.database_password, query=self. valid_query, page_content_fields=self.valid_page_content_fields, metadata_fields=self.valid_metadata_fields) docs = loader.load() print(d...
def test_couchbase_loader(self) ->None: """Test Couchbase loader.""" loader = CouchbaseLoader(connection_string=self.conn_string, db_username=self.database_user, db_password=self.database_password, query=self.valid_query, page_content_fields=self. valid_page_content_fields, metadata_fiel...
Test Couchbase loader.
_get_sample_rows
command = select(table).limit(self._sample_rows_in_table_info) columns_str = '\t'.join([col.name for col in table.columns]) try: with self._engine.connect() as connection: sample_rows_result = connection.execute(command) sample_rows = list(map(lambda ls: [str(i)[:100] for i in ls], sampl...
def _get_sample_rows(self, table: Table) ->str: command = select(table).limit(self._sample_rows_in_table_info) columns_str = '\t'.join([col.name for col in table.columns]) try: with self._engine.connect() as connection: sample_rows_result = connection.execute(command) sample_...
null
_load_from_bytes
"""Return a document from a bytes representation.""" return loads(serialized.decode('utf-8'))
def _load_from_bytes(serialized: bytes) ->Serializable: """Return a document from a bytes representation.""" return loads(serialized.decode('utf-8'))
Return a document from a bytes representation.
validate_tools_single_input
"""Validate tools for single input.""" for tool in tools: if not tool.is_single_input: raise ValueError( f'{class_name} does not support multi-input tool {tool.name}.')
def validate_tools_single_input(class_name: str, tools: Sequence[BaseTool] ) ->None: """Validate tools for single input.""" for tool in tools: if not tool.is_single_input: raise ValueError( f'{class_name} does not support multi-input tool {tool.name}.')
Validate tools for single input.
test_get_code
"""Test the parser.""" code_lines = output_parser.parse_folder(_SAMPLE_CODE) code = [c for c in code_lines if c.strip()] assert code == code_lines assert code == ['echo hello'] code_lines = output_parser.parse_folder(_SAMPLE_CODE + _SAMPLE_CODE_2_LINES) assert code_lines == ['echo hello', 'echo hello', 'echo world']
def test_get_code(output_parser: BashOutputParser) ->None: """Test the parser.""" code_lines = output_parser.parse_folder(_SAMPLE_CODE) code = [c for c in code_lines if c.strip()] assert code == code_lines assert code == ['echo hello'] code_lines = output_parser.parse_folder(_SAMPLE_CODE + _SAMP...
Test the parser.
__init__
self.folder = Path(folder) self.model_path = self.folder / 'latest.vw' self.with_history = with_history if reset and self.has_history(): logger.warning( 'There is non empty history which is recommended to be cleaned up') if self.model_path.exists(): os.remove(self.model_path) self.folder.mkdir(p...
def __init__(self, folder: Union[str, os.PathLike], with_history: bool=True, reset: bool=False): self.folder = Path(folder) self.model_path = self.folder / 'latest.vw' self.with_history = with_history if reset and self.has_history(): logger.warning( 'There is non empty history wh...
null
test_init_delta_sync_with_self_managed_embeddings
index = mock_index(DELTA_SYNC_INDEX_SELF_MANAGED_EMBEDDINGS) vectorsearch = DatabricksVectorSearch(index, embedding= DEFAULT_EMBEDDING_MODEL, text_column=DEFAULT_TEXT_COLUMN) assert vectorsearch.index == index
@pytest.mark.requires('databricks', 'databricks.vector_search') def test_init_delta_sync_with_self_managed_embeddings() ->None: index = mock_index(DELTA_SYNC_INDEX_SELF_MANAGED_EMBEDDINGS) vectorsearch = DatabricksVectorSearch(index, embedding= DEFAULT_EMBEDDING_MODEL, text_column=DEFAULT_TEXT_COLUMN) ...
null
test_all_imports
assert sorted(EXPECTED_ALL) == sorted(__all__)
def test_all_imports() ->None: assert sorted(EXPECTED_ALL) == sorted(__all__)
null
test_pass_confluence_kwargs
loader = ConfluenceLoader(url='https://templates.atlassian.net/wiki/', confluence_kwargs={'verify_ssl': False}) assert loader.confluence.verify_ssl is False
@pytest.mark.skipif(not confluence_installed, reason= 'Atlassian package not installed') def test_pass_confluence_kwargs() ->None: loader = ConfluenceLoader(url='https://templates.atlassian.net/wiki/', confluence_kwargs={'verify_ssl': False}) assert loader.confluence.verify_ssl is False
null
test_api_key_masked_when_passed_via_constructor
llm = CerebriumAI(cerebriumai_api_key='secret-api-key') print(llm.cerebriumai_api_key, end='') captured = capsys.readouterr() assert captured.out == '**********' assert repr(llm.cerebriumai_api_key) == "SecretStr('**********')"
def test_api_key_masked_when_passed_via_constructor(capsys: CaptureFixture ) ->None: llm = CerebriumAI(cerebriumai_api_key='secret-api-key') print(llm.cerebriumai_api_key, end='') captured = capsys.readouterr() assert captured.out == '**********' assert repr(llm.cerebriumai_api_key) == "SecretSt...
null
test_similarity_search_approx_with_custom_query_fn
"""test that custom query function is called with the query string and query body""" def my_custom_query(query_body: dict, query: str) ->dict: assert query == 'foo' assert query_body == {'knn': {'field': 'vector', 'filter': [], 'k': 1, 'num_candidates': 50, 'query_vector': [1.0, 1.0, 1.0, 1.0, 1...
def test_similarity_search_approx_with_custom_query_fn(self, elasticsearch_connection: dict, index_name: str) ->None: """test that custom query function is called with the query string and query body""" def my_custom_query(query_body: dict, query: str) ->dict: assert query == 'foo' ...
test that custom query function is called with the query string and query body
format_messages
"""Format the chat template into a list of finalized messages. Args: **kwargs: keyword arguments to use for filling in template variables in all the template messages in this chat template. Returns: list of formatted messages """ kwargs = self._mer...
def format_messages(self, **kwargs: Any) ->List[BaseMessage]: """Format the chat template into a list of finalized messages. Args: **kwargs: keyword arguments to use for filling in template variables in all the template messages in this chat template. Returns: ...
Format the chat template into a list of finalized messages. Args: **kwargs: keyword arguments to use for filling in template variables in all the template messages in this chat template. Returns: list of formatted messages
__init__
self._pod = pod self._store = store self._vector_index = vector_index self._vector_type = vector_type self._vector_dimension = vector_dimension self._embedding = embedding try: from jaguardb_http_client.JaguarHttpClient import JaguarHttpClient except ImportError: raise ValueError( 'Could not import jagu...
def __init__(self, pod: str, store: str, vector_index: str, vector_type: str, vector_dimension: int, url: str, embedding: Embeddings): self._pod = pod self._store = store self._vector_index = vector_index self._vector_type = vector_type self._vector_dimension = vector_dimension self._embeddi...
null
test_embed_query_normalized
output = OpenAIEmbeddings().embed_query('foo walked to the market') assert np.isclose(np.linalg.norm(output), 1.0)
@pytest.mark.scheduled def test_embed_query_normalized() ->None: output = OpenAIEmbeddings().embed_query('foo walked to the market') assert np.isclose(np.linalg.norm(output), 1.0)
null
test_token_text_splitter
"""Test no overlap.""" splitter = TokenTextSplitter(chunk_size=5, chunk_overlap=0) output = splitter.split_text('abcdef' * 5) expected_output = ['abcdefabcdefabc', 'defabcdefabcdef'] assert output == expected_output
def test_token_text_splitter() ->None: """Test no overlap.""" splitter = TokenTextSplitter(chunk_size=5, chunk_overlap=0) output = splitter.split_text('abcdef' * 5) expected_output = ['abcdefabcdefabc', 'defabcdefabcdef'] assert output == expected_output
Test no overlap.
embed_query
return self._get_embedding(seed=self._get_seed(text))
def embed_query(self, text: str) ->List[float]: return self._get_embedding(seed=self._get_seed(text))
null
test_tracer_multiple_llm_runs
"""Test the tracer with multiple runs.""" uuid = uuid4() compare_run = Run(id=uuid, name='llm', start_time=datetime.now(timezone.utc ), end_time=datetime.now(timezone.utc), events=[{'name': 'start', 'time': datetime.now(timezone.utc)}, {'name': 'end', 'time': datetime. now(timezone.utc)}], extra={}, executi...
@freeze_time('2023-01-01') def test_tracer_multiple_llm_runs() ->None: """Test the tracer with multiple runs.""" uuid = uuid4() compare_run = Run(id=uuid, name='llm', start_time=datetime.now(timezone .utc), end_time=datetime.now(timezone.utc), events=[{'name': 'start', 'time': datetime.now(t...
Test the tracer with multiple runs.
test_language_loader_for_python
"""Test Python loader with parser enabled.""" file_path = Path(__file__).parent.parent.parent / 'examples' loader = GenericLoader.from_filesystem(file_path, glob='hello_world.py', parser=LanguageParser(parser_threshold=5)) docs = loader.load() assert len(docs) == 2 metadata = docs[0].metadata assert metadata['sourc...
def test_language_loader_for_python() ->None: """Test Python loader with parser enabled.""" file_path = Path(__file__).parent.parent.parent / 'examples' loader = GenericLoader.from_filesystem(file_path, glob='hello_world.py', parser=LanguageParser(parser_threshold=5)) docs = loader.load() as...
Test Python loader with parser enabled.
load
"""Load documents.""" return list(self.lazy_load())
def load(self) ->List[Document]: """Load documents.""" return list(self.lazy_load())
Load documents.
_encoding_file_extension_map
texttospeech = _import_google_cloud_texttospeech() ENCODING_FILE_EXTENSION_MAP = {texttospeech.AudioEncoding.LINEAR16: '.wav', texttospeech.AudioEncoding.MP3: '.mp3', texttospeech.AudioEncoding. OGG_OPUS: '.ogg', texttospeech.AudioEncoding.MULAW: '.wav', texttospeech.AudioEncoding.ALAW: '.wav'} return ENCOD...
def _encoding_file_extension_map(encoding: texttospeech.AudioEncoding ) ->Optional[str]: texttospeech = _import_google_cloud_texttospeech() ENCODING_FILE_EXTENSION_MAP = {texttospeech.AudioEncoding.LINEAR16: '.wav', texttospeech.AudioEncoding.MP3: '.mp3', texttospeech. AudioEncoding.OGG_OPUS...
null
test_openai_multiple_prompts
"""Test completion with multiple prompts.""" llm = OpenAI(max_tokens=10) output = llm.generate(["I'm Pickle Rick", "I'm Pickle Rick"]) assert isinstance(output, LLMResult) assert isinstance(output.generations, list) assert len(output.generations) == 2
@pytest.mark.scheduled def test_openai_multiple_prompts() ->None: """Test completion with multiple prompts.""" llm = OpenAI(max_tokens=10) output = llm.generate(["I'm Pickle Rick", "I'm Pickle Rick"]) assert isinstance(output, LLMResult) assert isinstance(output.generations, list) assert len(out...
Test completion with multiple prompts.
__init__
self.client = client self.moderation_beacon = {'moderation_chain_id': chain_id, 'moderation_type': 'PromptSafety', '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': 'PromptSafety', 'moderation_status': 'LABELS_NOT_FOUND'} s...
null
test_stream
"""Test streaming tokens from ChatMistralAI.""" llm = ChatMistralAI() for token in llm.stream("I'm Pickle Rick"): assert isinstance(token.content, str)
def test_stream() ->None: """Test streaming tokens from ChatMistralAI.""" llm = ChatMistralAI() for token in llm.stream("I'm Pickle Rick"): assert isinstance(token.content, str)
Test streaming tokens from ChatMistralAI.
test_load_fail_wrong_dataset_name
"""Test that fails to load""" with pytest.raises(ValidationError) as exc_info: TensorflowDatasetLoader(dataset_name='wrong_dataset_name', split_name= 'test', load_max_docs=MAX_DOCS, sample_to_document_function= mlqaen_example_to_document) assert 'the dataset name is spelled correctly' in str(exc_inf...
def test_load_fail_wrong_dataset_name() ->None: """Test that fails to load""" with pytest.raises(ValidationError) as exc_info: TensorflowDatasetLoader(dataset_name='wrong_dataset_name', split_name='test', load_max_docs=MAX_DOCS, sample_to_document_function=mlqaen_example_to_docum...
Test that fails to load
run
user_input = ( 'Determine which next command to use, and respond using the format specified above:' ) loop_count = 0 while True: loop_count += 1 assistant_reply = self.chain.run(goals=goals, messages=self. chat_history_memory.messages, memory=self.memory, user_input=user_input ) prin...
def run(self, goals: List[str]) ->str: user_input = ( 'Determine which next command to use, and respond using the format specified above:' ) loop_count = 0 while True: loop_count += 1 assistant_reply = self.chain.run(goals=goals, messages=self. chat_history_memory...
null
test_incorrect_command_return_err_output
"""Test optional returning of shell output on incorrect command.""" session = BashProcess(return_err_output=True) output = session.run(['invalid_command']) assert re.match( '^/bin/sh:.*invalid_command.*(?:not found|Permission denied).*$', output)
@pytest.mark.skipif(sys.platform.startswith('win'), reason= 'Test not supported on Windows') def test_incorrect_command_return_err_output() ->None: """Test optional returning of shell output on incorrect command.""" session = BashProcess(return_err_output=True) output = session.run(['invalid_command']) ...
Test optional returning of shell output on incorrect command.
summarize_related_memories
"""Summarize memories that are most relevant to an observation.""" prompt = PromptTemplate.from_template( """ {q1}? Context from memory: {relevant_memories} Relevant context: """) entity_name = self._get_entity_from_observation(observation) entity_action = self._get_entity_action(observation, entity_name) q1 = f'W...
def summarize_related_memories(self, observation: str) ->str: """Summarize memories that are most relevant to an observation.""" prompt = PromptTemplate.from_template( """ {q1}? Context from memory: {relevant_memories} Relevant context: """ ) entity_name = self._get_entity_from_observation(...
Summarize memories that are most relevant to an observation.
test_self_hosted_huggingface_instructor_embedding_query
"""Test self-hosted huggingface instruct embeddings.""" query = 'foo bar' gpu = get_remote_instance() embedding = SelfHostedHuggingFaceInstructEmbeddings(hardware=gpu) output = embedding.embed_query(query) assert len(output) == 768
def test_self_hosted_huggingface_instructor_embedding_query() ->None: """Test self-hosted huggingface instruct embeddings.""" query = 'foo bar' gpu = get_remote_instance() embedding = SelfHostedHuggingFaceInstructEmbeddings(hardware=gpu) output = embedding.embed_query(query) assert len(output) =...
Test self-hosted huggingface instruct embeddings.
_select_relevance_score_fn
""" Select and return the appropriate relevance score function based on the distance metric used in the BagelDB cluster. """ if self.override_relevance_score_fn: return self.override_relevance_score_fn distance = 'l2' distance_key = 'hnsw:space' metadata = self._cluster.metadata if metadata ...
def _select_relevance_score_fn(self) ->Callable[[float], float]: """ Select and return the appropriate relevance score function based on the distance metric used in the BagelDB cluster. """ if self.override_relevance_score_fn: return self.override_relevance_score_fn distance ...
Select and return the appropriate relevance score function based on the distance metric used in the BagelDB cluster.
exists
"""Check if entity exists in store.""" pass
@abstractmethod def exists(self, key: str) ->bool: """Check if entity exists in store.""" pass
Check if entity exists in store.
match_args
ret: Dict[str, Any] = dict(query_embedding=query) if filter: ret['filter'] = filter return ret
def match_args(self, query: List[float], filter: Optional[Dict[str, Any]] ) ->Dict[str, Any]: ret: Dict[str, Any] = dict(query_embedding=query) if filter: ret['filter'] = filter return ret
null
_str
return ' '.join([f'{i}:{e}' for i, e in enumerate(embedding)])
@staticmethod def _str(embedding: List[float]) ->str: return ' '.join([f'{i}:{e}' for i, e in enumerate(embedding)])
null
_import_sql_database_tool_ListSQLDatabaseTool
from langchain_community.tools.sql_database.tool import ListSQLDatabaseTool return ListSQLDatabaseTool
def _import_sql_database_tool_ListSQLDatabaseTool() ->Any: from langchain_community.tools.sql_database.tool import ListSQLDatabaseTool return ListSQLDatabaseTool
null
test_chat_google_genai_invoke
"""Test invoke tokens from ChatGoogleGenerativeAI.""" llm = ChatGoogleGenerativeAI(model=_MODEL) result = llm.invoke("This is a test. Say 'foo'", config=dict(tags=['foo']), generation_config=dict(top_k=2, top_p=1, temperature=0.7)) assert isinstance(result.content, str) assert not result.content.startswith(' ')
def test_chat_google_genai_invoke() ->None: """Test invoke tokens from ChatGoogleGenerativeAI.""" llm = ChatGoogleGenerativeAI(model=_MODEL) result = llm.invoke("This is a test. Say 'foo'", config=dict(tags=[ 'foo']), generation_config=dict(top_k=2, top_p=1, temperature=0.7)) assert isinstance(r...
Test invoke tokens from ChatGoogleGenerativeAI.
_run
"""Use the tool.""" return self.api_wrapper.run(query)
def _run(self, query: str, run_manager: Optional[CallbackManagerForToolRun] =None) ->str: """Use the tool.""" return self.api_wrapper.run(query)
Use the tool.
_create_retry_decorator
"""Returns a tenacity retry decorator, preconfigured to handle PaLM exceptions""" import litellm errors = [litellm.Timeout, litellm.APIError, litellm.APIConnectionError, litellm.RateLimitError] return create_base_retry_decorator(error_types=errors, max_retries=llm. max_retries, run_manager=run_manager)
def _create_retry_decorator(llm: ChatLiteLLM, run_manager: Optional[Union[ AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun]]=None) ->Callable[ [Any], Any]: """Returns a tenacity retry decorator, preconfigured to handle PaLM exceptions""" import litellm errors = [litellm.Timeout, litellm.APIE...
Returns a tenacity retry decorator, preconfigured to handle PaLM exceptions
_call
docs = self.text_splitter.create_documents([inputs[self.input_key]]) results = self.llm_chain.generate([{'text': d.page_content} for d in docs], run_manager=run_manager) qa = [json.loads(res[0].text) for res in results.generations] return {self.output_key: qa}
def _call(self, inputs: Dict[str, Any], run_manager: Optional[ CallbackManagerForChainRun]=None) ->Dict[str, List]: docs = self.text_splitter.create_documents([inputs[self.input_key]]) results = self.llm_chain.generate([{'text': d.page_content} for d in docs], run_manager=run_manager) qa = [json...
null
_llm_type
"""Return type of model.""" return 'replicate'
@property def _llm_type(self) ->str: """Return type of model.""" return 'replicate'
Return type of model.
test_all_imports
assert sorted(EXPECTED_ALL) == sorted(__all__)
def test_all_imports() ->None: assert sorted(EXPECTED_ALL) == sorted(__all__)
null
_stream
invocation_params = self._invocation_params(stop, **kwargs) headers = {'User-Agent': 'Test Client', 'Authorization': f'{self.eas_service_token}'} if self.version == '1.0': pload = {'input_ids': prompt, **invocation_params} response = requests.post(self.eas_service_url, headers=headers, json= pload, ...
def _stream(self, prompt: str, stop: Optional[List[str]]=None, run_manager: Optional[CallbackManagerForLLMRun]=None, **kwargs: Any) ->Iterator[ GenerationChunk]: invocation_params = self._invocation_params(stop, **kwargs) headers = {'User-Agent': 'Test Client', 'Authorization': f'{self.eas_servi...
null
from_llm
"""Get the response parser.""" system_template = ( '#1 Task Planning Stage: The AI assistant can parse user input to several tasks: [{{"task": task, "id": task_id, "dep": dependency_task_id, "args": {{"input name": text may contain <resource-dep_id>}}}}]. The special tag "dep_id" refer to the one generated text/ima...
@classmethod def from_llm(cls, llm: BaseLanguageModel, demos: List[Dict]=DEMONSTRATIONS, verbose: bool=True) ->LLMChain: """Get the response parser.""" system_template = ( '#1 Task Planning Stage: The AI assistant can parse user input to several tasks: [{{"task": task, "id": task_id, "dep": dependen...
Get the response parser.
__init__
self.nua = nuclia_tool self.id = str(uuid.uuid4()) self.nua.run({'action': 'push', 'id': self.id, 'path': path, 'text': None})
def __init__(self, path: str, nuclia_tool: NucliaUnderstandingAPI): self.nua = nuclia_tool self.id = str(uuid.uuid4()) self.nua.run({'action': 'push', 'id': self.id, 'path': path, 'text': None})
null
ignore_chain
"""Whether to ignore chain callbacks.""" return self.ignore_chain_
@property def ignore_chain(self) ->bool: """Whether to ignore chain callbacks.""" return self.ignore_chain_
Whether to ignore chain callbacks.