Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helloworld example for CometLLM #141

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- guides/get-started/Comet_Quickstart.ipynb
- guides/manage_data/A_Guide_to_Remote_Artifacts.ipynb
- guides/manage_data/Introduction_to_Artifacts.ipynb
- integrations/llm/comet-llm/notebooks/CometLLM_hello_world.ipynb
- integrations/model-evaluation/gradio/notebooks/Gradio_and_Comet.ipynb
- integrations/model-evaluation/gradio/notebooks/Logging_Model_Inferences_with_Comet_and_Gradio.ipynb
- integrations/model-training/hugging_face/notebooks/Comet_with_Hugging_Face_Trainer.ipynb
Expand Down
147 changes: 147 additions & 0 deletions integrations/llm/comet-llm/notebooks/CometLLM_hello_world.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "PWVljpddz_vN"
},
"source": [
"<img src=\"https://cdn.comet.ml/img/notebook_logo.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "A0-thQauBRRL"
},
"source": [
"[Comet’s LLMOps tools](https://www.comet.com/site/products/llmops/) are designed to allow users to leverage the latest advancement in Prompt Management and query models in Comet to iterate quicker, identify performance bottlenecks, and visualize the internal state of the Prompt Chains.\n",
"\n",
"Get a preview for what's to come. Check out a completed project created from this notebook [here](https://www.comet.com/examples/comet-example-llm-hello-world/prompts).\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "V2UZtdWitSLf"
},
"source": [
"# Install Dependencies"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vIQsPNvatQIU"
},
"outputs": [],
"source": [
"%pip install comet_llm"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lpCFdN33tday"
},
"source": [
"# Initialize Comet"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kGyz_i-dtfk4"
},
"outputs": [],
"source": [
"import comet_ml\n",
"\n",
"comet_ml.init(project_name=\"comet-example-llm-hello-world\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Log a single prompt and response\n",
"\n",
"This minimal example logs only the minimum amount of data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import comet_llm\n",
"\n",
"comet_llm.log_prompt(\n",
" prompt=\"What is your name?\",\n",
" output=\" My name is Alex.\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Log everything\n",
"\n",
"You can also logs a lot more data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import comet_llm\n",
"\n",
"comet_llm.log_prompt(\n",
" prompt=\"Answer the question and if the question can't be answered, say \\\"I don't know\\\"\\n\\n---\\n\\nQuestion: What is your name?\\nAnswer:\",\n",
" prompt_template=\"Answer the question and if the question can't be answered, say \\\"I don't know\\\"\\n\\n---\\n\\nQuestion: {{question}}?\\nAnswer:\",\n",
" prompt_template_variables={\"question\": \"What is your name?\"},\n",
" metadata={\n",
" \"usage.prompt_tokens\": 7,\n",
" \"usage.completion_tokens\": 5,\n",
" \"usage.total_tokens\": 12,\n",
" },\n",
" output=\" My name is Alex.\",\n",
" duration=16.598,\n",
")"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"name": "Comet and Pytorch.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}