id
stringlengths
14
16
source
stringlengths
49
117
text
stringlengths
16
2.73k
ab4756c25a14-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/base.html
Source code for langchain.prompts.base """BasePrompt schema definition.""" from __future__ import annotations import json from abc import ABC, abstractmethod from pathlib import Path from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Union import yaml from pydantic import BaseModel, Extra, Field, roo...
ab4756c25a14-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/base.html
"Please install it with `pip install jinja2`." ) env = Environment() ast = env.parse(template) variables = meta.find_undeclared_variables(ast) return variables DEFAULT_FORMATTER_MAPPING: Dict[str, Callable] = { "f-string": formatter.format, "jinja2": jinja2_formatter, } DEFAULT_VALIDATOR...
ab4756c25a14-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/base.html
output_parser: Optional[BaseOutputParser] = None """How to parse the output of calling an LLM on this formatted prompt.""" partial_variables: Mapping[str, Union[str, Callable[[], str]]] = Field( default_factory=dict ) class Config: """Configuration for this pydantic object.""" ex...
ab4756c25a14-3
https://python.langchain.com/en/latest/_modules/langchain/prompts/base.html
def _merge_partial_and_user_variables(self, **kwargs: Any) -> Dict[str, Any]: # Get partial params: partial_kwargs = { k: v if isinstance(v, str) else v() for k, v in self.partial_variables.items() } return {**partial_kwargs, **kwargs} [docs] @abstractmethod ...
ab4756c25a14-4
https://python.langchain.com/en/latest/_modules/langchain/prompts/base.html
prompt_dict = self.dict() if save_path.suffix == ".json": with open(file_path, "w") as f: json.dump(prompt_dict, f, indent=4) elif save_path.suffix == ".yaml": with open(file_path, "w") as f: yaml.dump(prompt_dict, f, default_flow_style=False) ...
722e5f20c100-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot.html
Source code for langchain.prompts.few_shot """Prompt template that contains few shot examples.""" from typing import Any, Dict, List, Optional from pydantic import Extra, root_validator from langchain.prompts.base import ( DEFAULT_FORMATTER_MAPPING, StringPromptTemplate, check_valid_template, ) from langcha...
722e5f20c100-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot.html
examples = values.get("examples", None) example_selector = values.get("example_selector", None) if examples and example_selector: raise ValueError( "Only one of 'examples' and 'example_selector' should be provided" ) if examples is None and example_selecto...
722e5f20c100-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot.html
{k: e[k] for k in self.example_prompt.input_variables} for e in examples ] # Format the examples. example_strings = [ self.example_prompt.format(**example) for example in examples ] # Create the overall template. pieces = [self.prefix, *example_strings, self.s...
0f0660a4aaa2-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/prompt.html
Source code for langchain.prompts.prompt """Prompt schema definition.""" from __future__ import annotations from pathlib import Path from string import Formatter from typing import Any, Dict, List, Union from pydantic import Extra, root_validator from langchain.prompts.base import ( DEFAULT_FORMATTER_MAPPING, S...
0f0660a4aaa2-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/prompt.html
return DEFAULT_FORMATTER_MAPPING[self.template_format](self.template, **kwargs) @root_validator() def template_is_valid(cls, values: Dict) -> Dict: """Check that template and input variables are consistent.""" if values["validate_template"]: all_inputs = values["input_variables"] + l...
0f0660a4aaa2-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/prompt.html
"""Load a prompt from a file. Args: template_file: The path to the file containing the prompt template. input_variables: A list of variable names the final prompt template will expect. Returns: The prompt loaded from the file. """ with ...
780379979c6a-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/loading.html
Source code for langchain.prompts.loading """Load prompts from disk.""" import importlib import json import logging from pathlib import Path from typing import Union import yaml from langchain.output_parsers.regex import RegexParser from langchain.prompts.base import BasePromptTemplate from langchain.prompts.few_shot i...
780379979c6a-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/loading.html
template = f.read() else: raise ValueError # Set the template variable to the extracted variable. config[var_name] = template return config def _load_examples(config: dict) -> dict: """Load examples if necessary.""" if isinstance(config["examples"], list): pass ...
780379979c6a-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/loading.html
if "example_prompt" in config: raise ValueError( "Only one of example_prompt and example_prompt_path should " "be specified." ) config["example_prompt"] = load_prompt(config.pop("example_prompt_path")) else: config["example_prompt"] = load_prom...
780379979c6a-3
https://python.langchain.com/en/latest/_modules/langchain/prompts/loading.html
config = yaml.safe_load(f) elif file_path.suffix == ".py": spec = importlib.util.spec_from_loader( "prompt", loader=None, origin=str(file_path) ) if spec is None: raise ValueError("could not load spec") helper = importlib.util.module_from_spec(spec) wi...
f5aae45c33fb-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot_with_templates.html
Source code for langchain.prompts.few_shot_with_templates """Prompt template that contains few shot examples.""" from typing import Any, Dict, List, Optional from pydantic import Extra, root_validator from langchain.prompts.base import DEFAULT_FORMATTER_MAPPING, StringPromptTemplate from langchain.prompts.example_selec...
f5aae45c33fb-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot_with_templates.html
example_selector = values.get("example_selector", None) if examples and example_selector: raise ValueError( "Only one of 'examples' and 'example_selector' should be provided" ) if examples is None and example_selector is None: raise ValueError( ...
f5aae45c33fb-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot_with_templates.html
.. code-block:: python prompt.format(variable1="foo") """ kwargs = self._merge_partial_and_user_variables(**kwargs) # Get the examples to use. examples = self._get_examples(**kwargs) # Format the examples. example_strings = [ self.example_prompt.fo...
f5aae45c33fb-3
https://python.langchain.com/en/latest/_modules/langchain/prompts/few_shot_with_templates.html
Last updated on Jun 04, 2023.
f0feafbe3c8f-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/chat.html
Source code for langchain.prompts.chat """Chat prompt template.""" from __future__ import annotations from abc import ABC, abstractmethod from pathlib import Path from typing import Any, Callable, List, Sequence, Tuple, Type, TypeVar, Union from pydantic import BaseModel, Field from langchain.memory.buffer import get_b...
f0feafbe3c8f-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/chat.html
return [self.variable_name] MessagePromptTemplateT = TypeVar( "MessagePromptTemplateT", bound="BaseStringMessagePromptTemplate" ) class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC): prompt: StringPromptTemplate additional_kwargs: dict = Field(default_factory=dict) @classmethod def...
f0feafbe3c8f-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/chat.html
text = self.prompt.format(**kwargs) return HumanMessage(content=text, additional_kwargs=self.additional_kwargs) class AIMessagePromptTemplate(BaseStringMessagePromptTemplate): def format(self, **kwargs: Any) -> BaseMessage: text = self.prompt.format(**kwargs) return AIMessage(content=text, a...
f0feafbe3c8f-3
https://python.langchain.com/en/latest/_modules/langchain/prompts/chat.html
message = HumanMessagePromptTemplate(prompt=prompt_template) return cls.from_messages([message]) @classmethod def from_role_strings( cls, string_messages: List[Tuple[str, str]] ) -> ChatPromptTemplate: messages = [ ChatMessagePromptTemplate( prompt=PromptT...
f0feafbe3c8f-4
https://python.langchain.com/en/latest/_modules/langchain/prompts/chat.html
} message = message_template.format_messages(**rel_params) result.extend(message) else: raise ValueError(f"Unexpected input: {message_template}") return result [docs] def partial(self, **kwargs: Union[str, Callable[[], str]]) -> BasePromptTemplate: ...
729db40035f0-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/semantic_similarity.html
Source code for langchain.prompts.example_selector.semantic_similarity """Example selector that selects examples based on SemanticSimilarity.""" from __future__ import annotations from typing import Any, Dict, List, Optional, Type from pydantic import BaseModel, Extra from langchain.embeddings.base import Embeddings fr...
729db40035f0-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/semantic_similarity.html
[docs] def select_examples(self, input_variables: Dict[str, str]) -> List[dict]: """Select which examples to use based on semantic similarity.""" # Get the docs with the highest similarity. if self.input_keys: input_variables = {key: input_variables[key] for key in self.input_keys...
729db40035f0-2
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/semantic_similarity.html
Returns: The ExampleSelector instantiated, backed by a vector store. """ if input_keys: string_examples = [ " ".join(sorted_values({k: eg[k] for k in input_keys})) for eg in examples ] else: string_examples = [" ".jo...
729db40035f0-3
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/semantic_similarity.html
examples = [{k: eg[k] for k in self.example_keys} for eg in examples] return examples [docs] @classmethod def from_examples( cls, examples: List[dict], embeddings: Embeddings, vectorstore_cls: Type[VectorStore], k: int = 4, input_keys: Optional[List[str]] =...
729db40035f0-4
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/semantic_similarity.html
© Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
560f47a48808-0
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/length_based.html
Source code for langchain.prompts.example_selector.length_based """Select examples based on length.""" import re from typing import Callable, Dict, List from pydantic import BaseModel, validator from langchain.prompts.example_selector.base import BaseExampleSelector from langchain.prompts.prompt import PromptTemplate d...
560f47a48808-1
https://python.langchain.com/en/latest/_modules/langchain/prompts/example_selector/length_based.html
string_examples = [example_prompt.format(**eg) for eg in values["examples"]] return [get_text_length(eg) for eg in string_examples] [docs] def select_examples(self, input_variables: Dict[str, str]) -> List[dict]: """Select which examples to use based on the input lengths.""" inputs = " ".join...
95987ec0c222-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/airbyte_json.html
Source code for langchain.document_loaders.airbyte_json """Loader that loads local airbyte json files.""" import json from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.utils import stringify_dict [docs]class AirbyteJSONLoader(B...
834a032620ac-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/diffbot.html
Source code for langchain.document_loaders.diffbot """Loader that uses Diffbot to load webpages in text format.""" import logging from typing import Any, List import requests from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader logger = logging.getLogger(__name__) [doc...
834a032620ac-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/diffbot.html
metadata = {"source": url} docs.append(Document(page_content=text, metadata=metadata)) except Exception as e: if self.continue_on_failure: logger.error(f"Error fetching or processing {url}, exception: {e}") else: raise e...
75e3adae98b9-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/modern_treasury.html
Source code for langchain.document_loaders.modern_treasury """Loader that fetches data from Modern Treasury""" import json import urllib.request from base64 import b64encode from typing import List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from lan...
75e3adae98b9-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/modern_treasury.html
api_key: Optional[str] = None, ) -> None: self.resource = resource organization_id = organization_id or get_from_env( "organization_id", "MODERN_TREASURY_ORGANIZATION_ID" ) api_key = api_key or get_from_env("api_key", "MODERN_TREASURY_API_KEY") credentials = f"{or...
770d01a6f08c-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/figma.html
Source code for langchain.document_loaders.figma """Loader that loads Figma files json dump.""" import json import urllib.request from typing import Any, List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.utils import stringify_dict [docs]class Fi...
4af4eb8adfdf-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/bigquery.html
Source code for langchain.document_loaders.bigquery from __future__ import annotations from typing import TYPE_CHECKING, List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader if TYPE_CHECKING: from google.auth.credentials import Credentials [docs]clas...
4af4eb8adfdf-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/bigquery.html
self.metadata_columns = metadata_columns self.credentials = credentials [docs] def load(self) -> List[Document]: try: from google.cloud import bigquery except ImportError as ex: raise ValueError( "Could not import google-cloud-bigquery python package. "...
07b96ac378bd-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/readthedocs.html
Source code for langchain.document_loaders.readthedocs """Loader that loads ReadTheDocs documentation directory dump.""" from pathlib import Path from typing import Any, List, Optional, Tuple, Union from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class ReadT...
07b96ac378bd-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/readthedocs.html
"Could not import python packages. " "Please install it with `pip install beautifulsoup4`. " ) try: _ = BeautifulSoup( "<html><body>Parser builder library test.</body></html>", **kwargs ) except Exception as e: raise ValueEr...
07b96ac378bd-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/readthedocs.html
# trim empty lines return "\n".join([t for t in text.split("\n") if t]) By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
7a9f43065188-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/chatgpt.html
Source code for langchain.document_loaders.chatgpt """Load conversations from ChatGPT data export""" import datetime import json from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader def concatenate_rows(message: dict, title: str) -> str: if ...
7a9f43065188-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/chatgpt.html
return documents By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
e4e08b1374c2-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/powerpoint.html
Source code for langchain.document_loaders.powerpoint """Loader that loads powerpoint files.""" import os from typing import List from langchain.document_loaders.unstructured import UnstructuredFileLoader [docs]class UnstructuredPowerPointLoader(UnstructuredFileLoader): """Loader that uses unstructured to load powe...
e4e08b1374c2-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/powerpoint.html
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
2e60b3df97c7-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/epub.html
Source code for langchain.document_loaders.epub """Loader that loads EPub files.""" from typing import List from langchain.document_loaders.unstructured import ( UnstructuredFileLoader, satisfies_min_unstructured_version, ) [docs]class UnstructuredEPubLoader(UnstructuredFileLoader): """Loader that uses unst...
f09439a78ec0-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/python.html
Source code for langchain.document_loaders.python import tokenize from langchain.document_loaders.text import TextLoader [docs]class PythonLoader(TextLoader): """ Load Python files, respecting any non-default encoding if specified. """ def __init__(self, file_path: str): with open(file_path, "rb...
355bf8265f52-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/azure_blob_storage_file.html
Source code for langchain.document_loaders.azure_blob_storage_file """Loading logic for loading documents from an Azure Blob Storage file.""" import os import tempfile from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.document_...
4c7acbaaffac-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/git.html
Source code for langchain.document_loaders.git import os from typing import Callable, List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class GitLoader(BaseLoader): """Loads files from a Git repository into a list of documents. Repositor...
4c7acbaaffac-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/git.html
repo.git.checkout(self.branch) docs: List[Document] = [] for item in repo.tree().traverse(): if not isinstance(item, Blob): continue file_path = os.path.join(self.repo_path, item.path) ignored_files = repo.ignored([file_path]) # type: ignore ...
ad11eb0c5c13-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/text.html
Source code for langchain.document_loaders.text import logging from typing import List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.document_loaders.helpers import detect_file_encodings logger = logging.getLogger(__name__) [docs]class T...
ad11eb0c5c13-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/text.html
raise RuntimeError(f"Error loading {self.file_path}") from e metadata = {"source": self.file_path} return [Document(page_content=text, metadata=metadata)] By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
7f0300386431-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/image.html
Source code for langchain.document_loaders.image """Loader that loads image files.""" from typing import List from langchain.document_loaders.unstructured import UnstructuredFileLoader [docs]class UnstructuredImageLoader(UnstructuredFileLoader): """Loader that uses unstructured to load image files, such as PNGs and...
e471f26299c8-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/srt.html
Source code for langchain.document_loaders.srt """Loader for .srt (subtitle) files.""" from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class SRTLoader(BaseLoader): """Loader for .srt (subtitle) files.""" def __init__(self, fil...
6b8b261b926b-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/url_selenium.html
Source code for langchain.document_loaders.url_selenium """Loader that uses Selenium to load a page, then uses unstructured to load the html. """ import logging from typing import TYPE_CHECKING, List, Literal, Optional, Union if TYPE_CHECKING: from selenium.webdriver import Chrome, Firefox from langchain.docstore.d...
6b8b261b926b-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/url_selenium.html
"`pip install selenium`" ) try: import unstructured # noqa:F401 except ImportError: raise ImportError( "unstructured package not found, please install it with " "`pip install unstructured`" ) self.urls = urls ...
6b8b261b926b-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/url_selenium.html
if self.binary_location is not None: firefox_options.binary_location = self.binary_location if self.executable_path is None: return Firefox(options=firefox_options) return Firefox( executable_path=self.executable_path, options=firefox_options ...
7fbaeb6b254e-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/notion.html
Source code for langchain.document_loaders.notion """Loader that loads Notion directory dump.""" from pathlib import Path from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class NotionDirectoryLoader(BaseLoader): """Loader that load...
c55574bfff35-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/evernote.html
Source code for langchain.document_loaders.evernote """Load documents from Evernote. https://gist.github.com/foxmask/7b29c43a161e001ff04afdb2f181e31c """ import hashlib import logging from base64 import b64decode from time import strptime from typing import Any, Dict, Iterator, List, Optional from langchain.docstore.do...
c55574bfff35-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/evernote.html
[docs] def load(self) -> List[Document]: """Load documents from EverNote export file.""" documents = [ Document( page_content=note["content"], metadata={ **{ key: value for key, value in no...
c55574bfff35-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/evernote.html
else: rsc_dict[elem.tag] = elem.text return rsc_dict @staticmethod def _parse_note(note: List, prefix: Optional[str] = None) -> dict: note_dict: Dict[str, Any] = {} resources = [] def add_prefix(element_tag: str) -> str: if prefix is None: ...
c55574bfff35-3
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/evernote.html
try: from lxml import etree except ImportError as e: logging.error( "Could not import `lxml`. Although it is not a required package to use " "Langchain, using the EverNote loader requires `lxml`. Please install " "`lxml` via `pip install lx...
c09bfca3ecd9-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/reddit.html
Source code for langchain.document_loaders.reddit """Reddit document loader.""" from __future__ import annotations from typing import TYPE_CHECKING, Iterable, List, Optional, Sequence from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader if TYPE_CHECKING: import pra...
c09bfca3ecd9-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/reddit.html
for category in self.categories: docs = self._subreddit_posts_loader( search_query=search_query, category=category, reddit=reddit ) results.extend(docs) elif self.mode == "username": for search_query in self.search_q...
c09bfca3ecd9-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/reddit.html
for post in cat_posts: metadata = { "post_subreddit": post.subreddit_name_prefixed, "post_category": category, "post_title": post.title, "post_score": post.score, "post_id": post.id, "post_url": post.url, ...
7447a61649b0-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/url_playwright.html
Source code for langchain.document_loaders.url_playwright """Loader that uses Playwright to load a page, then uses unstructured to load the html. """ import logging from typing import List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader logger = logging....
7447a61649b0-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/url_playwright.html
"""Load the specified URLs using Playwright and create Document instances. Returns: List[Document]: A list of Document instances with loaded content. """ from playwright.sync_api import sync_playwright from unstructured.partition.html import partition_html docs: List[...
c65d682497e8-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/github.html
Source code for langchain.document_loaders.github from abc import ABC from datetime import datetime from typing import Dict, Iterator, List, Literal, Optional, Union import requests from pydantic import BaseModel, root_validator, validator from langchain.docstore.document import Document from langchain.document_loaders...
c65d682497e8-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/github.html
"""Filter on issue state. Can be one of: 'open', 'closed', 'all'.""" assignee: Optional[str] = None """Filter on assigned user. Pass 'none' for no user and '*' for any user.""" creator: Optional[str] = None """Filter on the user that created the issue.""" mentioned: Optional[str] = None """Filte...
c65d682497e8-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/github.html
- page_content - metadata - url - title - creator - created_at - last_update_time - closed_time - number of comments - state ...
c65d682497e8-3
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/github.html
"comments": issue["comments"], "state": issue["state"], "labels": [label["name"] for label in issue["labels"]], "assignee": issue["assignee"]["login"] if issue["assignee"] else None, "milestone": issue["milestone"]["title"] if issue["milestone"] else None, "lo...
eb64388fb536-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/mastodon.html
Source code for langchain.document_loaders.mastodon """Mastodon document loader.""" from __future__ import annotations import os from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Sequence from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader if TYPE...
eb64388fb536-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/mastodon.html
self.api = mastodon.Mastodon( access_token=access_token, api_base_url=api_base_url ) self.mastodon_accounts = mastodon_accounts self.number_toots = number_toots self.exclude_replies = exclude_replies [docs] def load(self) -> List[Document]: """Load toots into docum...
a88741340a3b-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/twitter.html
Source code for langchain.document_loaders.twitter """Twitter document loader.""" from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Sequence, Union from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader if TYPE_CHEC...
a88741340a3b-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/twitter.html
docs = self._format_tweets(tweets, user) results.extend(docs) return results def _format_tweets( self, tweets: List[Dict[str, Any]], user_info: dict ) -> Iterable[Document]: """Format tweets into a string.""" for tweet in tweets: metadata = { ...
a88741340a3b-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/twitter.html
consumer_secret=consumer_secret, ) return cls( auth_handler=auth, twitter_users=twitter_users, number_tweets=number_tweets, ) By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 04, 2023.
0d9a835ece9d-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/gcs_directory.html
Source code for langchain.document_loaders.gcs_directory """Loading logic for loading documents from an GCS directory.""" from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.document_loaders.gcs_file import GCSFileLoader [docs]cl...
d2352aff4828-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/html.html
Source code for langchain.document_loaders.html """Loader that uses unstructured to load HTML files.""" from typing import List from langchain.document_loaders.unstructured import UnstructuredFileLoader [docs]class UnstructuredHTMLLoader(UnstructuredFileLoader): """Loader that uses unstructured to load HTML files."...
a3ff3f7bda98-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
Source code for langchain.document_loaders.confluence """Load Data from a Confluence Space""" import logging from io import BytesIO from typing import Any, Callable, List, Optional, Union from tenacity import ( before_sleep_log, retry, stop_after_attempt, wait_exponential, ) from langchain.docstore.docu...
a3ff3f7bda98-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
:param url: _description_ :type url: str :param api_key: _description_, defaults to None :type api_key: str, optional :param username: _description_, defaults to None :type username: str, optional :param oauth2: _description_, defaults to {} :type oauth2: dict, optional :param token: _de...
a3ff3f7bda98-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
errors = ConfluenceLoader.validate_init_args( url, api_key, username, oauth2, token ) if errors: raise ValueError(f"Error(s) while validating input: {errors}") self.base_url = url self.number_of_retries = number_of_retries self.min_retry_seconds = min_retr...
a3ff3f7bda98-3
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
"If one of `api_key` or `username` is provided, " "the other must be as well." ) if (api_key or username) and oauth2: errors.append( "Cannot provide a value for `api_key` and/or " "`username` and provide a value for `oauth2`" ) ...
a3ff3f7bda98-4
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
:type space_key: Optional[str], optional :param page_ids: List of specific page IDs to load, defaults to None :type page_ids: Optional[List[str]], optional :param label: Get all pages with this label, defaults to None :type label: Optional[str], optional :param cql: CQL Expressio...
a3ff3f7bda98-5
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
status="any" if include_archived_content else "current", expand="body.storage.value", ) docs += self.process_pages( pages, include_restricted_content, include_attachments, include_comments ) if label: pages = self.paginate_request( ...
a3ff3f7bda98-6
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
if not include_restricted_content and not self.is_public_page(page): continue doc = self.process_page(page, include_attachments, include_comments) docs.append(doc) return docs [docs] def paginate_request(self, retrieval_method: Callable, **kwargs: Any) -> L...
a3ff3f7bda98-7
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
min=self.min_retry_seconds, # type: ignore[arg-type] max=self.max_retry_seconds, # type: ignore[arg-type] ), before_sleep=before_sleep_log(logger, logging.WARNING), )(retrieval_method) batch = get_pages(**kwargs, start=len(docs)) ...
a3ff3f7bda98-8
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
if include_attachments: attachment_texts = self.process_attachment(page["id"]) else: attachment_texts = [] text = BeautifulSoup(page["body"]["storage"]["value"], "lxml").get_text( " ", strip=True ) + "".join(attachment_texts) if include_comments: ...
a3ff3f7bda98-9
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
media_type == "image/png" or media_type == "image/jpg" or media_type == "image/jpeg" ): text = title + self.process_image(absolute_url) elif ( media_type == "application/vnd.openxmlformats-officedocument" ".wordproce...
a3ff3f7bda98-10
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
import pytesseract # noqa: F401 from PIL import Image # noqa: F401 except ImportError: raise ImportError( "`pytesseract` or `Pillow` package not found, " "please run `pip install pytesseract Pillow`" ) response = self.confluence.reque...
a3ff3f7bda98-11
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/confluence.html
or response.content is None ): return text workbook = xlrd.open_workbook(file_contents=response.content) for sheet in workbook.sheets(): text += f"{sheet.name}:\n" for row in range(sheet.nrows): for col in range(sheet.ncols): ...
076993c3062c-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/slack_directory.html
Source code for langchain.document_loaders.slack_directory """Loader for documents from a Slack export.""" import json import zipfile from pathlib import Path from typing import Dict, List, Optional from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class Slack...
076993c3062c-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/slack_directory.html
if channel_path.endswith(".json"): messages = self._read_json(zip_file, channel_path) for message in messages: document = self._convert_message_to_document( message, channel_name ) ...
076993c3062c-2
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/slack_directory.html
Get the message source as a string. Args: channel_name (str): The name of the channel the message belongs to. user (str): The user ID who sent the message. timestamp (str): The timestamp of the message. Returns: str: The message source. """ ...
18f0eb80d641-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/hn.html
Source code for langchain.document_loaders.hn """Loader that loads HN.""" from typing import Any, List from langchain.docstore.document import Document from langchain.document_loaders.web_base import WebBaseLoader [docs]class HNLoader(WebBaseLoader): """Load Hacker News data from either main page results or the com...
18f0eb80d641-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/hn.html
title = lineItem.find("span", {"class": "titleline"}).text.strip() metadata = { "source": self.web_path, "title": title, "link": link, "ranking": ranking, } documents.append( Document( ...
d9fd0d73067d-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/gutenberg.html
Source code for langchain.document_loaders.gutenberg """Loader that loads .txt web files.""" from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader [docs]class GutenbergLoader(BaseLoader): """Loader that uses urllib to load .txt web files.""" ...
515ce4f55024-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/email.html
Source code for langchain.document_loaders.email """Loader that loads email files.""" import os from typing import List from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader from langchain.document_loaders.unstructured import ( UnstructuredFileLoader, satisfies_...
515ce4f55024-1
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/email.html
) [docs] def load(self) -> List[Document]: """Load data into document objects.""" import extract_msg msg = extract_msg.Message(self.file_path) return [ Document( page_content=msg.body, metadata={ "subject": msg.subject, ...
73756ad1ca35-0
https://python.langchain.com/en/latest/_modules/langchain/document_loaders/sitemap.html
Source code for langchain.document_loaders.sitemap """Loader that fetches a sitemap and loads those URLs.""" import itertools import re from typing import Any, Callable, Generator, Iterable, List, Optional from langchain.document_loaders.web_base import WebBaseLoader from langchain.schema import Document def _default_p...