You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/libs/community/langchain_community
葛尧 e780433f6b
Fix token_usage None issue in ChatOpenAI with local Chatglm2-6B (#14493)
When using local Chatglm2-6B by changing OPENAI_BASE_URL to localhost,
the token_usage in ChatOpenAI becomes None. This leads to an
AttributeError when trying to access token_usage.items().

This commit adds a check to ensure token_usage is not None before
accessing its items. This change prevents the AttributeError and allows
ChatOpenAI to work seamlessly with a local Chatglm2-6B model, aligning
with the way it operates with the OpenAI API.

<!-- Thank you for contributing to LangChain!

Replace this entire comment with:
  - **Description:** a description of the change, 
  - **Issue:** the issue # it fixes (if applicable),
  - **Dependencies:** any dependencies required for this change,
- **Tag maintainer:** for a quicker response, tag the relevant
maintainer (see below),
- **Twitter handle:** we announce bigger features on Twitter. If your PR
gets announced, and you'd like a mention, we'll gladly shout you out!

Please make sure your PR is passing linting and testing before
submitting. Run `make format`, `make lint` and `make test` to check this
locally.

See contribution guidelines for more information on how to write/run
tests, lint, etc:

https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

If you're adding a new integration, please include:
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in `docs/extras`
directory.

If no one reviews your PR within a few days, please @-mention one of
@baskaryan, @eyurtsev, @hwchase17.
 -->

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
9 months ago
..
adapters community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
agent_toolkits infra: import CI fix (#14562) 9 months ago
callbacks community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
chat_loaders community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
chat_message_histories community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
chat_models Fix token_usage None issue in ChatOpenAI with local Chatglm2-6B (#14493) 9 months ago
docstore community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
document_loaders community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
document_transformers community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
embeddings fix(embeddings): huggingface hub embeddings and TEI (#14489) 9 months ago
graphs community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
indexes community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
llms community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
retrievers community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
storage community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
tools community[patch]: Release 0.0.2 (#14610) 9 months ago
utilities community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
utils community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
vectorstores fix a bug in RedisNum filter againt value 0 (#14587) 9 months ago
__init__.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
cache.py community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago
py.typed community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (#14463) 9 months ago