Commit Graph

8683 Commits (562b546bcc3e17328cf03421a8558137909cc131)
 

Author SHA1 Message Date
Bagatur 562b546bcc
docs: update chat openai (#20331) 2 months ago
Bagatur 2c4741b5ed
docs: add tool-calling agent (#20328) 2 months ago
ccurme f02e55aaf7
docs: add component page for tool calls (#20282)
Note: includes links to API reference pages for ToolCall and other
objects that currently don't exist (e.g.,
https://api.python.langchain.com/en/latest/messages/langchain_core.messages.tool.ToolCall.html#langchain_core.messages.tool.ToolCall).
2 months ago
Bagatur 6608089030
langchain[patch]: Release 0.1.16 (#20335) 2 months ago
Eugene Yurtsev 0e74fb4ec1
docs: Update list of chat models tool calling providers (#20330)
Will follow up with a few missing providers
2 months ago
Eugene Yurtsev 653489a1a9
docs: Update documentation for custom LLMs (#19972)
Update documentation for customizing LLMs
2 months ago
Bagatur 799714c629
release anthropic, fireworks, openai, groq, mistral (#20333) 2 months ago
Bagatur e72330aacc
core[patch]: Release 0.1.42 (#20332) 2 months ago
ccurme 795c728f71
mistral[patch]: add IDs to tool calls (#20299)
Mistral gives us one ID per response, no individual IDs for tool calls.

```python
from langchain.agents import AgentExecutor, create_tool_calling_agent, tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_mistralai import ChatMistralAI


prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are a helpful assistant"),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
    ]
)
model = ChatMistralAI(model="mistral-large-latest", temperature=0)

@tool
def magic_function(input: int) -> int:
    """Applies a magic function to an input."""
    return input + 2

tools = [magic_function]

agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke({"input": "what is the value of magic_function(3)?"})
```

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
2 months ago
Eugene Yurtsev 22fd844e8a
community[patch]: Add deprecation warnings to postgres implementation (#20222)
Add deprecation warnings to postgres implementation that are in langchain-postgres.
2 months ago
Eugene Yurtsev f02f708f52
core[patch]: For now remove user warning (#20321)
Remove warning since it creates a lot of noise.
2 months ago
Mayank Solanki f709ab4cdf
docs: added backtick on RunnablePassthrough (#20310)
added backtick on RunnablePassthrough
Isuue: #20094
2 months ago
Bagatur c706689413
openai[patch]: use tool_calls in request (#20272) 2 months ago
Bagatur e936fba428
langchain[patch]: agents check prompt partial vars (#20303) 2 months ago
Bagatur cb25fa0d55
core[patch]: fix ChatGeneration.text with content blocks (#20294) 2 months ago
Bagatur 03b247cca1
core[patch]: include tool_calls in ai msg chunk serialization (#20291) 2 months ago
Erick Friis 0fa551c278
chroma: bump rc, keep optional (#20298) 2 months ago
Erick Friis 16f8fff14f
chroma: add required fastapi dep to restrict to <1 (#20297) 2 months ago
Erick Friis 991fd82532
chroma: add optional fastapi dep to restrict to <1 (#20295) 2 months ago
killind-dev f8a54d1d73
chroma: Add chroma partner package (#19292)
**Description:** Adds chroma to the partners package. Tests & code
mirror those in the community package.
**Dependencies:** None
**Twitter handle:** @akiradev0x

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2 months ago
Yuki Watanabe eef19954f3
core[patch]: fix duplicated kwargs in `_load_sql_databse_chain` (#19908)
`kwargs` is specified twice in [this
line](3218463f6a/libs/langchain/langchain/chains/loading.py (L386)),
causing runtime error when passing any keyword arguments.
2 months ago
ccurme 39471a9c87
docs: update tool calling cookbook (#20290)
Co-authored-by: Erick Friis <erick@langchain.dev>
2 months ago
Nuno Campos 15271ac832
core: mustache prompt templates (#19980)
Co-authored-by: Erick Friis <erick@langchain.dev>
2 months ago
Leonid Ganeline 4cb5f4c353
community[patch]: import flattening fix (#20110)
This PR should make it easier for linters to do type checking and for IDEs to jump to definition of code.

See #20050 as a template for this PR.
- As a byproduct: Added 3 missed `test_imports`.
- Added missed `SolarChat` in to __init___.py Added it into test_import
ut.
- Added `# type: ignore` to fix linting. It is not clear, why linting
errors appear after ^ changes.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
2 months ago
Yuki Oshima 12190ad728
openai[patch]: Fix langchain-openai unknown parameter error with gpt-4-turbo (#20271)
**Description:** 

I fixed langchain-openai unknown parameter error with gpt-4-turbo.

It seems that the behavior of the Chat Completions API implicitly
changed when using the latest gpt-4-turbo model, differing from previous
models. It now appears to reject parameters that are not listed in the
[API
Reference](https://platform.openai.com/docs/api-reference/chat/create).
So I found some errors and fixed them.

**Issue:** https://github.com/langchain-ai/langchain/issues/20264

**Dependencies:** none

**Twitter handle:** https://twitter.com/oshima_123
2 months ago
ccurme 21c1ce0bc1
update agents to use tool call messages (#20074)
```python
from langchain.agents import AgentExecutor, create_tool_calling_agent, tool
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are a helpful assistant"),
        MessagesPlaceholder("chat_history", optional=True),
        ("human", "{input}"),
        MessagesPlaceholder("agent_scratchpad"),
    ]
)
model = ChatAnthropic(model="claude-3-opus-20240229")

@tool
def magic_function(input: int) -> int:
    """Applies a magic function to an input."""
    return input + 2

tools = [magic_function]

agent = create_tool_calling_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke({"input": "what is the value of magic_function(3)?"})
```
```
> Entering new AgentExecutor chain...

Invoking: `magic_function` with `{'input': 3}`
responded: [{'text': '<thinking>\nThe user has asked for the value of magic_function applied to the input 3. Looking at the available tools, magic_function is the relevant one to use here, as it takes an integer input and returns an integer output.\n\nThe magic_function has one required parameter:\n- input (integer)\n\nThe user has directly provided the value 3 for the input parameter. Since the required parameter is present, we can proceed with calling the function.\n</thinking>', 'type': 'text'}, {'id': 'toolu_01HsTheJPA5mcipuFDBbJ1CW', 'input': {'input': 3}, 'name': 'magic_function', 'type': 'tool_use'}]

5
Therefore, the value of magic_function(3) is 5.

> Finished chain.
{'input': 'what is the value of magic_function(3)?',
 'output': 'Therefore, the value of magic_function(3) is 5.'}
```

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
2 months ago
Erick Friis 9eb6f538f0
infra, multiple: rc release versions (#20252) 2 months ago
Bagatur 0d0458d1a7
mistralai[patch]: Pre-release 0.1.2-rc.1 (#20251) 2 months ago
Bagatur e4046939d0
anthropic[patch]: Pre-release 0.1.8-rc.1 (#20250) 2 months ago
Bagatur a8eb0f5b1b
openai[patch]: pre-release 0.1.3-rc.1 (#20249) 2 months ago
Bagatur a43b9e4f33
core[patch]: Pre-release 0.1.42-rc.1 (#20248) 2 months ago
Bagatur 9514bc4d67
core[minor], ...: add tool calls message (#18947)
core[minor], langchain[patch], openai[minor], anthropic[minor], fireworks[minor], groq[minor], mistralai[minor]

```python
class ToolCall(TypedDict):
    name: str
    args: Dict[str, Any]
    id: Optional[str]

class InvalidToolCall(TypedDict):
    name: Optional[str]
    args: Optional[str]
    id: Optional[str]
    error: Optional[str]

class ToolCallChunk(TypedDict):
    name: Optional[str]
    args: Optional[str]
    id: Optional[str]
    index: Optional[int]


class AIMessage(BaseMessage):
    ...
    tool_calls: List[ToolCall] = []
    invalid_tool_calls: List[InvalidToolCall] = []
    ...


class AIMessageChunk(AIMessage, BaseMessageChunk):
    ...
    tool_call_chunks: Optional[List[ToolCallChunk]] = None
    ...
```
Important considerations:
- Parsing logic occurs within different providers;
- ~Changing output type is a breaking change for anyone doing explicit
type checking;~
- ~Langsmith rendering will need to be updated:
https://github.com/langchain-ai/langchainplus/pull/3561~
- ~Langserve will need to be updated~
- Adding chunks:
- ~AIMessage + ToolCallsMessage = ToolCallsMessage if either has
non-null .tool_calls.~
- Tool call chunks are appended, merging when having equal values of
`index`.
  - additional_kwargs accumulate the normal way.
- During streaming:
- ~Messages can change types (e.g., from AIMessageChunk to
AIToolCallsMessageChunk)~
- Output parsers parse additional_kwargs (during .invoke they read off
tool calls).

Packages outside of `partners/`:
- https://github.com/langchain-ai/langchain-cohere/pull/7
- https://github.com/langchain-ai/langchain-google/pull/123/files

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
2 months ago
Erick Friis 00552918ac
groq: xfail tool_choice tests (#20247) 2 months ago
Bagatur 2d83505be9
experimental[patch]: Release 0.0.57 (#20243) 2 months ago
Bagatur f06cb59ab9
groq[patch]: Release 0.1.1 (#20242) 2 months ago
Erick Friis ad3f1a9e85
docs: fix external repo partner docs (#20238) 2 months ago
Bagatur 0b2f0307d7
openai[patch]: Release 0.1.2 (#20241) 2 months ago
Bagatur 4b84c9b28c
anthropic[patch]: Release 0.1.7 (#20240) 2 months ago
Bagatur 74d04a4e80
mistralai[patch]: Release 0.1.1 (#20239) 2 months ago
Bagatur e5913c8758
langchain[patch]: Release 0.1.15 (#20237) 2 months ago
Bagatur e39fdfddf1
community[patch]: Release 0.0.32 (#20236) 2 months ago
Bagatur a07238d14e
core[patch]: Release 0.1.41 (#20233) 2 months ago
Chip Davis 806d4ae48f
community[patch]: fixed multithreading returning List[List[Documents]] instead of List[Documents] (#20230)
Description: When multithreading is set to True and using the
DirectoryLoader, there was a bug that caused the return type to be a
double nested list. This resulted in other places upstream not being
able to utilize the from_documents method as it was no longer a
`List[Documents]` it was a `List[List[Documents]]`. The change made was
to just loop through the `future.result()` and yield every item.
Issue: #20093
Dependencies: N/A
Twitter handle: N/A
2 months ago
Sholto Armstrong 230376f183
docs: Fix typo in citations example (#20218)
Small typo in the citations notebook "ojbects" changed to "objects"
2 months ago
Eugene Yurtsev fe35e13083
langchain[patch]: Update unit test (#20228)
This unit test fails likely validation by the openai client.

Newer openai library seems to be doing more validation so the existing
test fails since http_client needs to be of httpx instance
2 months ago
Casper da Costa-Luis b972f394c8
langchain[patch]: make BooleanOutputParser check words not substrings (#20064)
- **Description**: fixes BooleanOutputParser detecting sub-words ("NOW
this is likely (YES)" -> `True`, not `AmbiguousError`)
- **Issue(s)**: fixes #11408 (follow-up to #17810)
- **Dependencies**: None
- **GitHub handle**: @casperdcl

<!-- if unreviewd after a few days, @-mention one of baskaryan, efriis,
eyurtsev, hwchase17 -->

- [x] **Add tests and docs**: 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/docs/integrations` directory.
- [ ] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
2 months ago
seray add31f46d0
community[patch]: OpenLLM Async Client Fixes and Timeout Parameter (#20007)
Same changes as this merged
[PR](https://github.com/langchain-ai/langchain/pull/17478)
(https://github.com/langchain-ai/langchain/pull/17478), but for the
async client, as the same issues persist.

- Replaced 'responses' attribute of OpenLLM's GenerationOutput schema to
'outputs'.
reference:
66de54eae7/openllm-core/src/openllm_core/_schemas.py (L135)

- Added timeout parameter for the async client.

---------

Co-authored-by: Seray Arslan <seray.arslan@knime.com>
2 months ago
Erick Friis 37a9e23c05
community: switch to falkordb python client (#20229) 2 months ago
Christophe Bornet f43b48aebc
core[minor]: Implement aformat_messages for _StringImageMessagePromptTemplate (#20036) 2 months ago
Christophe Bornet 19001e6cb9
core[minor]: Implement aformat for FewShotPromptWithTemplates (#20039) 2 months ago