Commit Graph

148 Commits (main)

Author SHA1 Message Date
Harrison Chase 4b5d427421
Harrison/source docs (#1275)
Co-authored-by: Tushar Dhadiwal <tushardhadiwal@users.noreply.github.com>
1 year ago
Jon Luo 8a35811556
Don't instruct LLM to use the LIMIT clause, which is incompatible with SQL Server (#1242)
The current prompt specifically instructs the LLM to use the `LIMIT`
clause. This will cause issues with MS SQL Server, which uses `SELECT
TOP` instead of `LIMIT`. The generated SQL will use `LIMIT`; the
instruction to "always limit... using the LIMIT clause" seems to
override the "create a syntactically correct mssql query to run"
portion. Reported here:
https://github.com/hwchase17/langchain/issues/1103#issuecomment-1441144224

I don't have access to a SQL Server instance to test, but removing that
part of the prompt in OpenAI Playground results in the correct `SELECT
TOP` syntax, whereas keeping it in results in the `LIMIT` clause, even
when instructing it to generate syntactically correct mssql. It's also
still correctly using `LIMIT` in my MariaDB database. I think in this
case we can assume that the model will select the appropriate method
based on the dialect specified.

In general, it would be nice to be able to test a suite of SQL dialects
for things like dialect-specific syntax and other issues we've run into
in the past, but I'm not quite sure how to best approach that yet.
1 year ago
djacobs7 4e28982d2b
Fix typo in constitutional_ai base.py (#1216)
Found a typo in the documentation code for the constitutional_ai module
1 year ago
Francisco Ingham 0b6a650cb4
added ability to override default verbose and memory when load chain … (#1153)
It is useful to be able to specify `verbose` or `memory` while still
keeping the chain's overall structure.

---------

Co-authored-by: Francisco Ingham <>
1 year ago
Zach Schillaci 159c560c95
Refactor some loops into list comprehensions (#1185) 1 year ago
Ji ed37fbaeff
for ChatVectorDBChain, add top_k_docs_for_context to allow control how many chunks of context will be retrieved (#1155)
given that we allow user define chunk size, think it would be useful for
user to define how many chunks of context will be retrieved.
1 year ago
Harrison Chase 955c89fccb
pass in prompts to vectordbqa (#1158) 1 year ago
CG80499 af8f5c1a49
Added constitutional chain. (#1147)
- Added self-critique constitutional chain based on this
[paper](https://www.anthropic.com/constitutional.pdf).
1 year ago
kekayan 9111f4ca8a
fix chatvectordbchain to use pinecone namespace (#1139)
In the similarity search, the pinecone namespace is not used, which
makes the bot return _I don't know_ where the embeddings are stored in
the pinecone namespace. Now we can query by passing the namespace
optionally.
```result = qa({"question": query, "chat_history": chat_history, "namespace":"01gshyhjcfgkq1q5wxjtm17gjh"})```
1 year ago
Harrison Chase 511d41114f
return source documents for chat vector db chain (#1128) 1 year ago
Harrison Chase badeeb37b0
fix stuff count (#1083) 1 year ago
Ankush Gola caa8e4742e
Enable streaming for OpenAI LLM (#986)
* Support a callback `on_llm_new_token` that users can implement when
`OpenAI.streaming` is set to `True`
1 year ago
Harrison Chase ec727bf166
Align table info (#999) (#1034)
Currently the chain is getting the column names and types on the one
side and the example rows on the other. It is easier for the llm to read
the table information if the column name and examples are shown together
so that it can easily understand to which columns do the examples refer
to. For an instantiation of this, please refer to the changes in the
`sqlite.ipynb` notebook.

Also changed `eval` for `ast.literal_eval` when interpreting the results
from the sample row query since it is a better practice.

---------

Co-authored-by: Francisco Ingham <>

---------

Co-authored-by: Francisco Ingham <fpingham@gmail.com>
1 year ago
Harrison Chase 0c553d2064
Harrion/kg (#1016)
Co-authored-by: William FH <13333726+hinthornw@users.noreply.github.com>
1 year ago
Harrison Chase 3d639d1539
update lint (#975)
Co-authored-by: Harrison Chase <harrisonchase@Harrisons-MBP.attlocal.net>
1 year ago
Ankush Gola bc7e56e8df
Add asyncio support for LLM (OpenAI), Chain (LLMChain, LLMMathChain), and Agent (#841)
Supporting asyncio in langchain primitives allows for users to run them
concurrently and creates more seamless integration with
asyncio-supported frameworks (FastAPI, etc.)

Summary of changes:

**LLM**
* Add `agenerate` and `_agenerate`
* Implement in OpenAI by leveraging `client.Completions.acreate`

**Chain**
* Add `arun`, `acall`, `_acall`
* Implement them in `LLMChain` and `LLMMathChain` for now

**Agent**
* Refactor and leverage async chain and llm methods
* Add ability for `Tools` to contain async coroutine
* Implement async SerpaPI `arun`

Create demo notebook.

Open questions:
* Should all the async stuff go in separate classes? I've seen both
patterns (keeping the same class and having async and sync methods vs.
having class separation)
1 year ago
Harrison Chase 2584663e44
remove unused buffer (#919) 1 year ago
Harrison Chase 87fad8fc00
analyze document (#731)
add analyze document chain, which does text splitting and then analysis
1 year ago
Harrison Chase 2a68be3e8d
chat vector db chain (#902) 1 year ago
Harrison Chase a2b699dcd2
prompt template from string (#884) 1 year ago
Zach Schillaci 4c79100b15
Correct prompt typo + update example for SQLDatabaseChain (#868)
See https://github.com/hwchase17/langchain/issues/821
1 year ago
Harrison Chase 364b771743
sql return direct (#864) 1 year ago
Harrison Chase 483441d305
pass kwargs through to loading (#863) 1 year ago
Harrison Chase 0de55048b7
return code for pal (#844) 1 year ago
Nick Furlotte 576609e665
Update PAL to allow passing local and global context to PythonREPL (#774)
Passing additional variables to the python environment can be useful for
example if you want to generate code to analyze a dataset.

I also added a tracker for the executed code - `code_history`.
1 year ago
Harrison Chase 3f952eb597
add from string method (#820) 1 year ago
Ikko Eltociear Ashimine ba26a879e0
Fix typo in crawler.py (#842)
seperator -> separator
1 year ago
Zach Schillaci b4eb043b81
Minor fix to SQLDatabaseChain doc (#826) 1 year ago
Raza Habib 9f8e05ffd4
Update __init__.py (#827)
Remove duplicate APIChain
1 year ago
Harrison Chase 94ae126747
return sql intermediate steps (#792) 1 year ago
Roy Williams 6086292252
Centralize logic for loading from LangChainHub, add ability to pin dependencies (#805)
It's generally considered to be a good practice to pin dependencies to
prevent surprise breakages when a new version of a dependency is
released. This commit adds the ability to pin dependencies when loading
from LangChainHub.

Centralizing this logic and using urllib fixes an issue identified by
some windows users highlighted in this video -
https://youtu.be/aJ6IQUh8MLQ?t=537
1 year ago
Harrison Chase b3916f74a7
enable mmr search (#807) 1 year ago
Harrison Chase f46f1d28af
expose memory key name (#808) 1 year ago
Francisco Ingham 213c2e33e5
Sql prompt improvement (#787)
Co-authored-by: Francisco Ingham <>
1 year ago
Samantha Whitmore be7de427ca
Serialize all the chains! (#761)
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
1 year ago
Harrison Chase f273c50d62
add loading chains from hub (#757) 1 year ago
Smit Shah 28efbb05bf
Add params to reduce K dynamically to reduce it below token limit (#739)
Referring to #687, I implemented the functionality to reduce K if it
exceeds the token limit.

Edit: I should have ran make lint locally. Also, this only applies to
`StuffDocumentChain`
1 year ago
Roy Williams d2f882158f
Add type information for crawler.py (#738)
Added type information to `crawler.py` to make it safer to use and
understand.
1 year ago
Ankush Gola 57609845df
add tracing support to langchain (#741)
* add implementations of `BaseCallbackHandler` to support tracing:
`SharedTracer` which is thread-safe and `Tracer` which is not and is
meant to be used locally.
* Tracers persist runs to locally running `langchain-server`

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
1 year ago
scadEfUr e3df8ab6dc
move hyde into chains (#728)
Co-authored-by: scadEfUr <>
1 year ago
Harrison Chase 0ffeabd14f
Harrison/serialize llm chain (#671) 1 year ago
Harrison Chase cbc146720b
verbose flag (#683) 1 year ago
Samantha Whitmore 77e3d58922
ConversationEntityMemory: Chain which uses an entity extraction & sum… (#678)
…marization prompt to maintain a key-value store of memory information

cc @devennavani

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
1 year ago
Harrison Chase 983b73f47c
add search kwargs (#664) 1 year ago
vertinski 65f3a341b0
Prompt fix for empty intermediate steps in summarization (#660)
Adding quotation marks around {text} avoids generating empty or
completely random responses from OpenAI davinci-003. Empty or completely
unrelated intermediate responses in summarization messes up the final
result or makes it very inaccurate.
The error from OpenAI would be: "The model predicted a completion that
begins with a stop sequence, resulting in no output. Consider adjusting
your prompt or stop sequences."
This fix corrects the prompting for summarization chain. This works on
API too, the images are for demonstrative purposes.
This approach can be applied to other similar prompts too. 

Examples:

1) Without quotation marks
![Screenshot from 2023-01-20
07-18-19](https://user-images.githubusercontent.com/22897470/213624365-9dfc18f9-5f3f-45d2-abe1-56de67397e22.png)

2) With quotation marks
![Screenshot from 2023-01-20
07-18-35](https://user-images.githubusercontent.com/22897470/213624478-c958e742-a4a7-46fe-a163-eca6326d9dae.png)
1 year ago
iocuydi 207e319a70
Add search_kwargs option for VectorDBQAWithSourcesChain (#657)
Allows for passing additional vectorstore params like namespace, etc. to
VectorDBQAWithSourcesChain

Example:
`chain = VectorDBQAWithSourcesChain.from_llm(OpenAI(temperature=0),
vectorstore=store, search_kwargs={"namespace": namespace})`
1 year ago
Harrison Chase 6be5f4e4c4
Harrison/sql db chain (#641)
Co-authored-by: Bruno Bornsztein <bruno.bornsztein@gmail.com>
1 year ago
Francisco Ingham b929fd9f59
Exclude reference to 'example' in api prompt (#629)
Co-authored-by: lesscomfortable <pancho_ingham@hotmail.com>
1 year ago
Harrison Chase 3d43906572
Harrison/new api chain (#623)
Co-authored-by: Francisco Ingham <fpingham@gmail.com>
Co-authored-by: lesscomfortable <pancho_ingham@hotmail.com>
1 year ago
Harrison Chase 1c71fadfdc
more complex sql chain (#619)
add a more complex sql chain that first subsets the necessary tables
1 year ago