Skip to content

Commit

Permalink
DSPy docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jverre committed Jan 8, 2025
1 parent 59d0147 commit 378d7eb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/documentation_cookbook_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- apps/opik-documentation/documentation/docs/cookbook/openai.ipynb
- apps/opik-documentation/documentation/docs/cookbook/litellm.ipynb
- apps/opik-documentation/documentation/docs/cookbook/ragas.ipynb
- apps/opik-documentation/documentation/docs/cookbook/dspy.ipynb
env:
NOTEBOOK_TO_TEST: ${{ matrix.notebooks }}
steps:
Expand Down
48 changes: 39 additions & 9 deletions apps/opik-documentation/documentation/docs/cookbook/dspy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"OPIK: Opik is already configured. You can check the settings by viewing the config file at /Users/jacquesverre/.opik.config\n"
]
}
],
"source": [
"import opik\n",
"\n",
Expand All @@ -48,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -70,14 +78,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import dspy\n",
"from opik.integrations.dspy.callback import OpikCallback\n",
"\n",
"lm = dspy.LM('openai/gpt-4o-mini')\n",
"lm = dspy.LM(\"openai/gpt-4o-mini\")\n",
"\n",
"project_name = \"DSPY\"\n",
"opik_callback = OpikCallback(project_name=project_name)\n",
Expand All @@ -87,9 +95,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:langfuse:Langfuse client is disabled since no public_key was provided as a parameter or environment variable 'LANGFUSE_PUBLIC_KEY'. See our docs: https://langfuse.com/docs/sdk/python/low-level-sdk#initialize-client\n",
"OPIK: Started logging traces to the \"DSPY\" project at https://www.comet.com/opik/jacques-comet/redirect/projects?name=DSPY.\n"
]
},
{
"data": {
"text/plain": [
"Prediction(\n",
" reasoning='The meaning of life is a philosophical question that has been contemplated by humans for centuries. Different cultures, religions, and individuals have proposed various interpretations. Some suggest that the meaning of life is to seek happiness, fulfillment, and personal growth, while others believe it is about serving a higher purpose or contributing to the well-being of others. Ultimately, the meaning of life may vary from person to person, shaped by personal experiences, beliefs, and values.',\n",
" answer=\"The meaning of life is subjective and can vary greatly among individuals. It may involve seeking happiness, personal growth, and contributing to the well-being of others, or fulfilling a higher purpose, depending on one's beliefs and experiences.\"\n",
")"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cot = dspy.ChainOfThought(\"question -> answer\")\n",
"cot(question=\"What is the meaning of life?\")"
Expand All @@ -107,7 +137,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "py312_llm_eval",
"language": "python",
"name": "python3"
},
Expand All @@ -121,7 +151,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ description: Describes how to track DSPy calls using Opik

Opik integrates with DSPy to log traces for all DSPy calls.

<div style="display: flex; align-items: center; flex-wrap: wrap; margin: 20px 0;">
<span style="margin-right: 10px;">You can check out the Colab Notebook if you'd like to jump straight to the code:</span>
<a href="https://colab.research.google.com/github/comet-ml/opik/blob/main/apps/opik-documentation/documentation/docs/cookbook/dspy.ipynb" target="_blank" rel="noopener noreferrer">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" style="vertical-align: middle;"/>
</a>
</div>

## Getting started

First, ensure you have both `opik` and `dspy` installed:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/opik-documentation/python-sdk-docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ langchain_core
botocore
anthropic
haystack-ai
dpsy

0 comments on commit 378d7eb

Please sign in to comment.