Skip to content

Commit 55fbf9f

Browse files
authored
Merge branch 'master' into mdrxy/anthropic-web-fetch
2 parents 9243e17 + 38afedd commit 55fbf9f

File tree

22 files changed

+662
-830
lines changed

22 files changed

+662
-830
lines changed

cookbook/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Notebook | Description
6464
[visual_RAG_vdms.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/visual_RAG_vdms.ipynb) | Performs Visual Retrieval-Augmented-Generation (RAG) using videos and scene descriptions generated by open source models.
6565
[contextual_rag.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/contextual_rag.ipynb) | Performs contextual retrieval-augmented generation (RAG) prepending chunk-specific explanatory context to each chunk before embedding.
6666
[rag-agents-locally-on-intel-cpu.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/local_rag_agents_intel_cpu.ipynb) | Build a RAG agent locally with open source models that routes questions through one of two paths to find answers. The agent generates answers based on documents retrieved from either the vector database or retrieved from web search. If the vector database lacks relevant information, the agent opts for web search. Open-source models for LLM and embeddings are used locally on an Intel Xeon CPU to execute this pipeline.
67+
[rag_mlflow_tracking_evaluation.ipynb](https://github.com/langchain-ai/langchain/tree/master/cookbook/rag_mlflow_tracking_evaluation.ipynb) | Guide on how to create a RAG pipeline and track + evaluate it with MLflow.

cookbook/rag_mlflow_tracking_evaluation.ipynb

Lines changed: 439 additions & 0 deletions
Large diffs are not rendered by default.

docs/api_reference/guide_imports.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/docs/how_to/indexing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
" * document addition by id (`add_documents` method with `ids` argument)\n",
6262
" * delete by id (`delete` method with `ids` argument)\n",
6363
"\n",
64-
"Compatible Vectorstores: `Aerospike`, `AnalyticDB`, `AstraDB`, `AwaDB`, `AzureCosmosDBNoSqlVectorSearch`, `AzureCosmosDBVectorSearch`, `AzureSearch`, `Bagel`, `Cassandra`, `Chroma`, `CouchbaseVectorStore`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `Milvus`, `MongoDBAtlasVectorSearch`, `MyScale`, `OpenSearchVectorSearch`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SingleStoreDB`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `Vald`, `VDMS`, `Vearch`, `VespaStore`, `Weaviate`, `Yellowbrick`, `ZepVectorStore`, `TencentVectorDB`, `OpenSearchVectorSearch`.\n",
64+
"Compatible Vectorstores: `AnalyticDB`, `AstraDB`, `AwaDB`, `AzureCosmosDBNoSqlVectorSearch`, `AzureCosmosDBVectorSearch`, `AzureSearch`, `Bagel`, `Cassandra`, `Chroma`, `CouchbaseVectorStore`, `DashVector`, `DatabricksVectorSearch`, `DeepLake`, `Dingo`, `ElasticVectorSearch`, `ElasticsearchStore`, `FAISS`, `HanaDB`, `Milvus`, `MongoDBAtlasVectorSearch`, `MyScale`, `OpenSearchVectorSearch`, `PGVector`, `Pinecone`, `Qdrant`, `Redis`, `Rockset`, `ScaNN`, `SingleStoreDB`, `SupabaseVectorStore`, `SurrealDBStore`, `TimescaleVector`, `Vald`, `VDMS`, `Vearch`, `VespaStore`, `Weaviate`, `Yellowbrick`, `ZepVectorStore`, `TencentVectorDB`, `OpenSearchVectorSearch`.\n",
6565
" \n",
6666
"## Caution\n",
6767
"\n",

docs/docs/integrations/callbacks/confident.ipynb

Lines changed: 25 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"source": [
88
"# Confident\n",
99
"\n",
10-
">[DeepEval](https://confident-ai.com) package for unit testing LLMs.\n",
11-
"> Using Confident, everyone can build robust language models through faster iterations\n",
12-
"> using both unit testing and integration testing. We provide support for each step in the iteration\n",
13-
"> from synthetic data creation to testing.\n"
10+
">[DeepEval](https://confident-ai.com) package for unit testing LLMs."
1411
]
1512
},
1613
{
@@ -42,7 +39,7 @@
4239
"metadata": {},
4340
"outputs": [],
4441
"source": [
45-
"%pip install --upgrade --quiet langchain langchain-openai langchain-community deepeval langchain-chroma"
42+
"!pip install deepeval langchain langchain-openai"
4643
]
4744
},
4845
{
@@ -62,149 +59,41 @@
6259
"When you log in, you will also be asked to set the `implementation` name. The implementation name is required to describe the type of implementation. (Think of what you want to call your project. We recommend making it descriptive.)"
6360
]
6461
},
65-
{
66-
"cell_type": "code",
67-
"execution_count": 11,
68-
"metadata": {},
69-
"outputs": [],
70-
"source": [
71-
"!deepeval login"
72-
]
73-
},
74-
{
75-
"attachments": {},
76-
"cell_type": "markdown",
77-
"metadata": {},
78-
"source": [
79-
"### Setup DeepEval\n",
80-
"\n",
81-
"You can, by default, use the `DeepEvalCallbackHandler` to set up the metrics you want to track. However, this has limited support for metrics at the moment (more to be added soon). It currently supports:\n",
82-
"- [Answer Relevancy](https://docs.confident-ai.com/docs/measuring_llm_performance/answer_relevancy)\n",
83-
"- [Bias](https://docs.confident-ai.com/docs/measuring_llm_performance/debias)\n",
84-
"- [Toxicness](https://docs.confident-ai.com/docs/measuring_llm_performance/non_toxic)"
85-
]
86-
},
87-
{
88-
"cell_type": "code",
89-
"execution_count": null,
90-
"metadata": {},
91-
"outputs": [],
92-
"source": [
93-
"from deepeval.metrics.answer_relevancy import AnswerRelevancy\n",
94-
"\n",
95-
"# Here we want to make sure the answer is minimally relevant\n",
96-
"answer_relevancy_metric = AnswerRelevancy(minimum_score=0.5)"
97-
]
98-
},
99-
{
100-
"attachments": {},
101-
"cell_type": "markdown",
102-
"metadata": {},
103-
"source": [
104-
"## Get Started"
105-
]
106-
},
107-
{
108-
"attachments": {},
109-
"cell_type": "markdown",
110-
"metadata": {},
111-
"source": [
112-
"To use the `DeepEvalCallbackHandler`, we need the `implementation_name`. "
113-
]
114-
},
11562
{
11663
"cell_type": "code",
11764
"execution_count": null,
11865
"metadata": {},
119-
"outputs": [],
120-
"source": [
121-
"from langchain_community.callbacks.confident_callback import DeepEvalCallbackHandler\n",
122-
"\n",
123-
"deepeval_callback = DeepEvalCallbackHandler(\n",
124-
" implementation_name=\"langchainQuickstart\", metrics=[answer_relevancy_metric]\n",
125-
")"
126-
]
127-
},
128-
{
129-
"attachments": {},
130-
"cell_type": "markdown",
131-
"metadata": {},
132-
"source": [
133-
"### Scenario 1: Feeding into LLM\n",
134-
"\n",
135-
"You can then feed it into your LLM with OpenAI."
136-
]
137-
},
138-
{
139-
"cell_type": "code",
140-
"execution_count": 7,
141-
"metadata": {},
14266
"outputs": [
14367
{
14468
"data": {
69+
"text/html": [
70+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">🎉🥳 Congratulations! You've successfully logged in! 🙌 \n",
71+
"</pre>\n"
72+
],
14573
"text/plain": [
146-
"LLMResult(generations=[[Generation(text='\\n\\nQ: What did the fish say when he hit the wall? \\nA: Dam.', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\\n\\nThe Moon \\n\\nThe moon is high in the midnight sky,\\nSparkling like a star above.\\nThe night so peaceful, so serene,\\nFilling up the air with love.\\n\\nEver changing and renewing,\\nA never-ending light of grace.\\nThe moon remains a constant view,\\nA reminder of life’s gentle pace.\\n\\nThrough time and space it guides us on,\\nA never-fading beacon of hope.\\nThe moon shines down on us all,\\nAs it continues to rise and elope.', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\\n\\nQ. What did one magnet say to the other magnet?\\nA. \"I find you very attractive!\"', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text=\"\\n\\nThe world is charged with the grandeur of God.\\nIt will flame out, like shining from shook foil;\\nIt gathers to a greatness, like the ooze of oil\\nCrushed. Why do men then now not reck his rod?\\n\\nGenerations have trod, have trod, have trod;\\nAnd all is seared with trade; bleared, smeared with toil;\\nAnd wears man's smudge and shares man's smell: the soil\\nIs bare now, nor can foot feel, being shod.\\n\\nAnd for all this, nature is never spent;\\nThere lives the dearest freshness deep down things;\\nAnd though the last lights off the black West went\\nOh, morning, at the brown brink eastward, springs —\\n\\nBecause the Holy Ghost over the bent\\nWorld broods with warm breast and with ah! bright wings.\\n\\n~Gerard Manley Hopkins\", generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text='\\n\\nQ: What did one ocean say to the other ocean?\\nA: Nothing, they just waved.', generation_info={'finish_reason': 'stop', 'logprobs': None})], [Generation(text=\"\\n\\nA poem for you\\n\\nOn a field of green\\n\\nThe sky so blue\\n\\nA gentle breeze, the sun above\\n\\nA beautiful world, for us to love\\n\\nLife is a journey, full of surprise\\n\\nFull of joy and full of surprise\\n\\nBe brave and take small steps\\n\\nThe future will be revealed with depth\\n\\nIn the morning, when dawn arrives\\n\\nA fresh start, no reason to hide\\n\\nSomewhere down the road, there's a heart that beats\\n\\nBelieve in yourself, you'll always succeed.\", generation_info={'finish_reason': 'stop', 'logprobs': None})]], llm_output={'token_usage': {'completion_tokens': 504, 'total_tokens': 528, 'prompt_tokens': 24}, 'model_name': 'text-davinci-003'})"
74+
"🎉🥳 Congratulations! You've successfully logged in! 🙌 \n"
14775
]
14876
},
149-
"execution_count": 7,
15077
"metadata": {},
151-
"output_type": "execute_result"
78+
"output_type": "display_data"
15279
}
15380
],
15481
"source": [
155-
"from langchain_openai import OpenAI\n",
82+
"import os\n",
83+
"import deepeval\n",
15684
"\n",
157-
"llm = OpenAI(\n",
158-
" temperature=0,\n",
159-
" callbacks=[deepeval_callback],\n",
160-
" verbose=True,\n",
161-
" openai_api_key=\"<YOUR_API_KEY>\",\n",
162-
")\n",
163-
"output = llm.generate(\n",
164-
" [\n",
165-
" \"What is the best evaluation tool out there? (no bias at all)\",\n",
166-
" ]\n",
167-
")"
85+
"api_key = os.getenv(\"DEEPEVAL_API_KEY\")\n",
86+
"deepeval.login(api_key)"
16887
]
16988
},
17089
{
17190
"attachments": {},
17291
"cell_type": "markdown",
17392
"metadata": {},
17493
"source": [
175-
"You can then check the metric if it was successful by calling the `is_successful()` method."
176-
]
177-
},
178-
{
179-
"cell_type": "code",
180-
"execution_count": null,
181-
"metadata": {},
182-
"outputs": [],
183-
"source": [
184-
"answer_relevancy_metric.is_successful()\n",
185-
"# returns True/False"
186-
]
187-
},
188-
{
189-
"attachments": {},
190-
"cell_type": "markdown",
191-
"metadata": {},
192-
"source": [
193-
"Once you have ran that, you should be able to see our dashboard below. \n",
194-
"\n",
195-
"![Dashboard](https://docs.confident-ai.com/assets/images/dashboard-screenshot-b02db73008213a211b1158ff052d969e.png)"
196-
]
197-
},
198-
{
199-
"attachments": {},
200-
"cell_type": "markdown",
201-
"metadata": {},
202-
"source": [
203-
"### Scenario 2: Tracking an LLM in a chain without callbacks\n",
204-
"\n",
205-
"To track an LLM in a chain without callbacks, you can plug into it at the end.\n",
94+
"### Setup Confident AI Callback (Modern)\n",
20695
"\n",
207-
"We can start by defining a simple chain as shown below."
96+
"The previous DeepEvalCallbackHandler and metric tracking are deprecated. Please use the new integration below."
20897
]
20998
},
21099
{
@@ -213,76 +102,29 @@
213102
"metadata": {},
214103
"outputs": [],
215104
"source": [
216-
"import requests\n",
217-
"from langchain.chains import RetrievalQA\n",
218-
"from langchain_chroma import Chroma\n",
219-
"from langchain_community.document_loaders import TextLoader\n",
220-
"from langchain_openai import OpenAI, OpenAIEmbeddings\n",
221-
"from langchain_text_splitters import CharacterTextSplitter\n",
105+
"from deepeval.integrations.langchain import CallbackHandler\n",
222106
"\n",
223-
"text_file_url = \"https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt\"\n",
224-
"\n",
225-
"openai_api_key = \"sk-XXX\"\n",
226-
"\n",
227-
"with open(\"state_of_the_union.txt\", \"w\") as f:\n",
228-
" response = requests.get(text_file_url)\n",
229-
" f.write(response.text)\n",
230-
"\n",
231-
"loader = TextLoader(\"state_of_the_union.txt\")\n",
232-
"documents = loader.load()\n",
233-
"text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
234-
"texts = text_splitter.split_documents(documents)\n",
235-
"\n",
236-
"embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)\n",
237-
"docsearch = Chroma.from_documents(texts, embeddings)\n",
238-
"\n",
239-
"qa = RetrievalQA.from_chain_type(\n",
240-
" llm=OpenAI(openai_api_key=openai_api_key),\n",
241-
" chain_type=\"stuff\",\n",
242-
" retriever=docsearch.as_retriever(),\n",
243-
")\n",
244-
"\n",
245-
"# Providing a new question-answering pipeline\n",
246-
"query = \"Who is the president?\"\n",
247-
"result = qa.run(query)"
248-
]
249-
},
250-
{
251-
"attachments": {},
252-
"cell_type": "markdown",
253-
"metadata": {},
254-
"source": [
255-
"After defining a chain, you can then manually check for answer similarity."
256-
]
257-
},
258-
{
259-
"cell_type": "code",
260-
"execution_count": null,
261-
"metadata": {},
262-
"outputs": [],
263-
"source": [
264-
"answer_relevancy_metric.measure(result, query)\n",
265-
"answer_relevancy_metric.is_successful()"
107+
"handler = CallbackHandler(\n",
108+
" name=\"My Trace\",\n",
109+
" tags=[\"production\", \"v1\"],\n",
110+
" metadata={\"experiment\": \"A/B\"},\n",
111+
" thread_id=\"thread-123\",\n",
112+
" user_id=\"user-456\",\n",
113+
")"
266114
]
267115
},
268116
{
269117
"attachments": {},
270118
"cell_type": "markdown",
271119
"metadata": {},
272120
"source": [
273-
"### What's next?\n",
274-
"\n",
275-
"You can create your own custom metrics [here](https://docs.confident-ai.com/docs/quickstart/custom-metrics). \n",
276-
"\n",
277-
"DeepEval also offers other features such as being able to [automatically create unit tests](https://docs.confident-ai.com/docs/quickstart/synthetic-data-creation), [tests for hallucination](https://docs.confident-ai.com/docs/measuring_llm_performance/factual_consistency).\n",
278-
"\n",
279-
"If you are interested, check out our Github repository here [https://github.com/confident-ai/deepeval](https://github.com/confident-ai/deepeval). We welcome any PRs and discussions on how to improve LLM performance."
121+
"## Get Started"
280122
]
281123
}
282124
],
283125
"metadata": {
284126
"kernelspec": {
285-
"display_name": "Python 3 (ipykernel)",
127+
"display_name": "langchain",
286128
"language": "python",
287129
"name": "python3"
288130
},
@@ -296,12 +138,7 @@
296138
"name": "python",
297139
"nbconvert_exporter": "python",
298140
"pygments_lexer": "ipython3",
299-
"version": "3.10.12"
300-
},
301-
"vscode": {
302-
"interpreter": {
303-
"hash": "a53ebf4a859167383b364e7e7521d0add3c2dbbdecce4edf676e8c4634ff3fbb"
304-
}
141+
"version": "3.12.11"
305142
}
306143
},
307144
"nbformat": 4,

docs/docs/integrations/providers/aerospike.mdx

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/docs/integrations/providers/confident.mdx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,38 @@ pip install deepeval
2121

2222
See an [example](/docs/integrations/callbacks/confident).
2323

24+
25+
## Modern Integration Example
26+
27+
Install the required packages:
28+
29+
```bash
30+
pip install deepeval langchain langchain-openai
31+
```
32+
33+
Authenticate with your API key:
34+
2435
```python
25-
from langchain.callbacks.confident_callback import DeepEvalCallbackHandler
36+
import os
37+
import deepeval
38+
39+
# Load API key from environment variable for security
40+
api_key = os.environ.get("DEEPEVAL_API_KEY")
41+
deepeval.login(api_key)
42+
```
43+
44+
Use the new callback handler:
45+
46+
```python
47+
from deepeval.integrations.langchain import CallbackHandler
48+
49+
handler = CallbackHandler(
50+
name="My Trace",
51+
tags=["production", "v1"],
52+
metadata={"experiment": "A/B"},
53+
thread_id="thread-123",
54+
user_id="user-456"
55+
)
2656
```
57+
58+
See the [full example](/docs/integrations/callbacks/confident).

docs/docs/integrations/providers/ibm.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ from langchain_ibm import WatsonxRerank
7777
See a [usage example](/docs/integrations/tools/ibm_watsonx).
7878

7979
```python
80-
from langchain_ibm import WatsonxToolkit
80+
from langchain_ibm.agent_toolkits.utility import WatsonxToolkit
8181
```
8282

8383
## DB2

docs/docs/integrations/providers/modelscope.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ embeddings.embed_query("What is the meaning of life?")
4040
```
4141

4242
## LLMs
43-
`ModelScopeLLM` class exposes LLMs from ModelScope.
43+
`ModelScopeEndpoint` class exposes LLMs from ModelScope.
4444

4545
```python
46-
from langchain_modelscope import ModelScopeLLM
46+
from langchain_modelscope import ModelScopeEndpoint
4747

48-
llm = ModelScopeLLM(model="Qwen/Qwen2.5-Coder-32B-Instruct")
48+
llm = ModelScopeEndpoint(model="Qwen/Qwen2.5-Coder-32B-Instruct")
4949
llm.invoke("The meaning of life is")
5050
```

0 commit comments

Comments
 (0)