b026a62bc4
The specs used in chat-gpt plugins have only a few endpoints and have unrealistically small specifications. By contrast, a spec like spotify's has 60+ endpoints and is comprised 100k+ tokens. Here are some impressive traces from gpt-4 that string together non-trivial sequences of API calls. As noted in `planner.py`, gpt-3 is not as robust but can be improved with i) better retry, self-reflect, etc. logic and ii) better few-shots iii) etc. This PR's just a first attempt probing a few different directions that eventually can be made more core. `make me a playlist with songs from kind of blue. call it machine blues.` ``` > Entering new AgentExecutor chain... Action: api_planner Action Input: I need to find the right API calls to create a playlist with songs from Kind of Blue and name it Machine Blues Observation: 1. GET /search to find the album ID for "Kind of Blue". 2. GET /albums/{id}/tracks to get the tracks from the "Kind of Blue" album. 3. GET /me to get the current user's ID. 4. POST /users/{user_id}/playlists to create a new playlist named "Machine Blues" for the current user. 5. POST /playlists/{playlist_id}/tracks to add the tracks from "Kind of Blue" to the newly created "Machine Blues" playlist. Thought:I have a plan to create the playlist. Now, I will execute the API calls. Action: api_controller Action Input: 1. GET /search to find the album ID for "Kind of Blue". 2. GET /albums/{id}/tracks to get the tracks from the "Kind of Blue" album. 3. GET /me to get the current user's ID. 4. POST /users/{user_id}/playlists to create a new playlist named "Machine Blues" for the current user. 5. POST /playlists/{playlist_id}/tracks to add the tracks from "Kind of Blue" to the newly created "Machine Blues" playlist. > Entering new AgentExecutor chain... Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/search?q=Kind%20of%20Blue&type=album", "output_instructions": "Extract the id of the first album in the search results"} Observation: 1weenld61qoidwYuZ1GESA Thought:Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/albums/1weenld61qoidwYuZ1GESA/tracks", "output_instructions": "Extract the ids of all the tracks in the album"} Observation: ["7q3kkfAVpmcZ8g6JUThi3o"] Thought:Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/me", "output_instructions": "Extract the id of the current user"} Observation: 22rhrz4m4kvpxlsb5hezokzwi Thought:Action: requests_post Action Input: {"url": "https://api.spotify.com/v1/users/22rhrz4m4kvpxlsb5hezokzwi/playlists", "data": {"name": "Machine Blues"}, "output_instructions": "Extract the id of the newly created playlist"} Observation: 48YP9TMcEtFu9aGN8n10lg Thought:Action: requests_post Action Input: {"url": "https://api.spotify.com/v1/playlists/48YP9TMcEtFu9aGN8n10lg/tracks", "data": {"uris": ["spotify:track:7q3kkfAVpmcZ8g6JUThi3o"]}, "output_instructions": "Confirm that the tracks were added to the playlist"} Observation: The tracks were added to the playlist. The snapshot_id is "Miw4NTdmMWUxOGU5YWMxMzVmYmE3ZWE5MWZlYWNkMTc2NGVmNTI1ZjY5". Thought:I am finished executing the plan. Final Answer: The tracks from the "Kind of Blue" album have been added to the newly created "Machine Blues" playlist. The playlist ID is 48YP9TMcEtFu9aGN8n10lg. > Finished chain. Observation: The tracks from the "Kind of Blue" album have been added to the newly created "Machine Blues" playlist. The playlist ID is 48YP9TMcEtFu9aGN8n10lg. Thought:I am finished executing the plan and have created the playlist with songs from Kind of Blue, named Machine Blues. Final Answer: I have created a playlist called "Machine Blues" with songs from the "Kind of Blue" album. The playlist ID is 48YP9TMcEtFu9aGN8n10lg. > Finished chain. ``` or `give me a song in the style of tobe nwige` ``` > Entering new AgentExecutor chain... Action: api_planner Action Input: I need to find the right API calls to get a song in the style of Tobe Nwigwe Observation: 1. GET /search to find the artist ID for Tobe Nwigwe. 2. GET /artists/{id}/related-artists to find similar artists to Tobe Nwigwe. 3. Pick one of the related artists and use their artist ID in the next step. 4. GET /artists/{id}/top-tracks to get the top tracks of the chosen related artist. Thought: I'm ready to execute the API calls. Action: api_controller Action Input: 1. GET /search to find the artist ID for Tobe Nwigwe. 2. GET /artists/{id}/related-artists to find similar artists to Tobe Nwigwe. 3. Pick one of the related artists and use their artist ID in the next step. 4. GET /artists/{id}/top-tracks to get the top tracks of the chosen related artist. > Entering new AgentExecutor chain... Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/search?q=Tobe%20Nwigwe&type=artist", "output_instructions": "Extract the artist id for Tobe Nwigwe"} Observation: 3Qh89pgJeZq6d8uM1bTot3 Thought:Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/artists/3Qh89pgJeZq6d8uM1bTot3/related-artists", "output_instructions": "Extract the ids and names of the related artists"} Observation: [ { "id": "75WcpJKWXBV3o3cfluWapK", "name": "Lute" }, { "id": "5REHfa3YDopGOzrxwTsPvH", "name": "Deante' Hitchcock" }, { "id": "6NL31G53xThQXkFs7lDpL5", "name": "Rapsody" }, { "id": "5MbNzCW3qokGyoo9giHA3V", "name": "EARTHGANG" }, { "id": "7Hjbimq43OgxaBRpFXic4x", "name": "Saba" }, { "id": "1ewyVtTZBqFYWIcepopRhp", "name": "Mick Jenkins" } ] Thought:Action: requests_get Action Input: {"url": "https://api.spotify.com/v1/artists/75WcpJKWXBV3o3cfluWapK/top-tracks?country=US", "output_instructions": "Extract the ids and names of the top tracks"} Observation: [ { "id": "6MF4tRr5lU8qok8IKaFOBE", "name": "Under The Sun (with J. Cole & Lute feat. DaBaby)" } ] Thought:I am finished executing the plan. Final Answer: The top track of the related artist Lute is "Under The Sun (with J. Cole & Lute feat. DaBaby)" with the track ID "6MF4tRr5lU8qok8IKaFOBE". > Finished chain. Observation: The top track of the related artist Lute is "Under The Sun (with J. Cole & Lute feat. DaBaby)" with the track ID "6MF4tRr5lU8qok8IKaFOBE". Thought:I am finished executing the plan and have the information the user asked for. Final Answer: The song "Under The Sun (with J. Cole & Lute feat. DaBaby)" by Lute is in the style of Tobe Nwigwe. > Finished chain. ``` --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> |
||
---|---|---|
.github | ||
docs | ||
langchain | ||
tests | ||
.dockerignore | ||
.flake8 | ||
.gitignore | ||
CITATION.cff | ||
Dockerfile | ||
LICENSE | ||
Makefile | ||
poetry.lock | ||
poetry.toml | ||
pyproject.toml | ||
README.md | ||
readthedocs.yml |
🦜️🔗 LangChain
⚡ Building applications with LLMs through composability ⚡
Production Support: As you move your LangChains into production, we'd love to offer more comprehensive support. Please fill out this form and we'll set up a dedicated support Slack channel.
Quick Install
pip install langchain
🤔 What is this?
Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not. But using these LLMs in isolation is often not enough to create a truly powerful app - the real power comes when you can combine them with other sources of computation or knowledge.
This library is aimed at assisting in the development of those types of applications. Common examples of these types of applications include:
❓ Question Answering over specific documents
- Documentation
- End-to-end Example: Question Answering over Notion Database
💬 Chatbots
- Documentation
- End-to-end Example: Chat-LangChain
🤖 Agents
- Documentation
- End-to-end Example: GPT+WolframAlpha
📖 Documentation
Please see here for full documentation on:
- Getting started (installation, setting up the environment, simple examples)
- How-To examples (demos, integrations, helper functions)
- Reference (full API docs)
- Resources (high-level explanation of core concepts)
🚀 What can this help with?
There are six main areas that LangChain is designed to help with. These are, in increasing order of complexity:
📃 LLMs and Prompts:
This includes prompt management, prompt optimization, generic interface for all LLMs, and common utilities for working with LLMs.
🔗 Chains:
Chains go beyond just a single LLM call, and are sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.
📚 Data Augmented Generation:
Data Augmented Generation involves specific types of chains that first interact with an external datasource to fetch data to use in the generation step. Examples of this include summarization of long pieces of text and question/answering over specific data sources.
🤖 Agents:
Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end to end agents.
🧠 Memory:
Memory is the concept of persisting state between calls of a chain/agent. LangChain provides a standard interface for memory, a collection of memory implementations, and examples of chains/agents that use memory.
🧐 Evaluation:
[BETA] Generative models are notoriously hard to evaluate with traditional metrics. One new way of evaluating them is using language models themselves to do the evaluation. LangChain provides some prompts/chains for assisting in this.
For more information on these concepts, please see our full documentation.
💁 Contributing
As an open source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infra, or better documentation.
For detailed information on how to contribute, see here.