Skip to content

Commit

Permalink
Merge branch 'langchain-ai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
olgavrou authored Sep 5, 2023
2 parents 3a4c895 + c8d7ee6 commit 235dacc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
24 changes: 12 additions & 12 deletions .github/actions/poetry_setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ runs:
with:
python-version: ${{ inputs.python-version }}

- uses: actions/cache@v3
id: cache-bin-poetry
name: Cache Poetry binary - Python ${{ inputs.python-version }}
env:
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
with:
path: |
/opt/pipx/venvs/poetry
/opt/pipx_bin/poetry
# This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}
# - uses: actions/cache@v3
# id: cache-bin-poetry
# name: Cache Poetry binary - Python ${{ inputs.python-version }}
# env:
# SEGMENT_DOWNLOAD_TIMEOUT_MIN: "1"
# with:
# path: |
# /opt/pipx/venvs/poetry
# /opt/pipx_bin/poetry
# # This step caches the poetry installation, so make sure it's keyed on the poetry version as well.
# key: bin-poetry-${{ runner.os }}-${{ runner.arch }}-py-${{ inputs.python-version }}-${{ inputs.poetry-version }}

- name: Install poetry
if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
# if: steps.cache-bin-poetry.outputs.cache-hit != 'true'
shell: bash
env:
POETRY_VERSION: ${{ inputs.poetry-version }}
Expand Down
16 changes: 13 additions & 3 deletions libs/langchain/langchain/document_loaders/async_html.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import logging
import warnings
from typing import Any, Dict, Iterator, List, Optional, Union
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Dict, Iterator, List, Optional, Union, cast

import aiohttp
import requests
Expand Down Expand Up @@ -129,9 +130,18 @@ def lazy_load(self) -> Iterator[Document]:
def load(self) -> List[Document]:
"""Load text from the url(s) in web_path."""

results = asyncio.run(self.fetch_all(self.web_paths))
try:
# Raises RuntimeError if there is no current event loop.
asyncio.get_running_loop()
# If there is a current event loop, we need to run the async code
# in a separate loop, in a separate thread.
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(asyncio.run, self.fetch_all(self.web_paths))
results = future.result()
except RuntimeError:
results = asyncio.run(self.fetch_all(self.web_paths))
docs = []
for i, text in enumerate(results):
for i, text in enumerate(cast(List[str], results)):
metadata = {"source": self.web_paths[i]}
docs.append(Document(page_content=text, metadata=metadata))

Expand Down
2 changes: 1 addition & 1 deletion libs/langchain/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain"
version = "0.0.281"
version = "0.0.282"
description = "Building applications with LLMs through composability"
authors = []
license = "MIT"
Expand Down

0 comments on commit 235dacc

Please sign in to comment.