Skip to content

Commit eff6bf0

Browse files
committed
feat: upload a reference dataset
1 parent c48341a commit eff6bf0

File tree

15 files changed

+346
-29
lines changed

15 files changed

+346
-29
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
3+
import pandas as pd
4+
from openlayer import Openlayer
5+
from openlayer.lib import data
6+
from openlayer.types.inference_pipelines import data_stream_params
7+
8+
os.environ["OPENLAYER_API_KEY"] = "YOUR_API_KEY"
9+
pipeline_id = "YOUR_INFERENCE_PIPELINE_ID"
10+
11+
df = pd.DataFrame(
12+
{
13+
"CreditScore": [600],
14+
"Geography": ["France"],
15+
"Gender": ["Male"],
16+
"Age": [40],
17+
"Tenure": [5],
18+
"Balance": [100000],
19+
"NumOfProducts": [1],
20+
"HasCrCard": [1],
21+
"IsActiveMember": [1],
22+
"EstimatedSalary": [50000],
23+
"AggregateRate": [0.5],
24+
"Year": [2020],
25+
"Exited": [0],
26+
}
27+
)
28+
29+
config = data_stream_params.ConfigTabularClassificationData(
30+
categorical_feature_names=["Gender", "Geography"],
31+
class_names=["Retained", "Exited"],
32+
feature_names=[
33+
"CreditScore",
34+
"Geography",
35+
"Gender",
36+
"Age",
37+
"Tenure",
38+
"Balance",
39+
"NumOfProducts",
40+
"HasCrCard",
41+
"IsActiveMember",
42+
"EstimatedSalary",
43+
"AggregateRate",
44+
"Year",
45+
],
46+
label_column_name="Exited",
47+
)
48+
49+
data.upload_reference_dataframe(
50+
client=Openlayer(),
51+
inference_pipeline_id=pipeline_id,
52+
dataset_df=df,
53+
config=config,
54+
storage_type=data.StorageType.FS,
55+
)

examples/rest-api/development_test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
# This is the default and can be omitted
1010
api_key=os.environ.get("OPENLAYER_API_KEY"),
1111
)
12-
response = client.commits.test_results.list(id=commit_id)
12+
response = client.commits.test_results.list(commit_id=commit_id)
1313

1414
print(response.items)

examples/rest-api/monitoring_test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
# This is the default and can be omitted
1010
api_key=os.environ.get("OPENLAYER_API_KEY"),
1111
)
12-
response = client.inference_pipelines.test_results.list(id=inference_pipeline_id)
12+
response = client.inference_pipelines.test_results.list(inference_pipeline_id=inference_pipeline_id)
1313

1414
print(response.items)

examples/rest-api/stream_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
from openlayer import Openlayer
44

5+
# Prepare the config for the data, which depends on your project's task type. In this
6+
# case, we have an LLM project:
7+
from openlayer.types.inference_pipelines import data_stream_params
8+
59
# Let's say we want to stream the following row, which represents a model prediction:
610
data = {"user_query": "what's the meaning of life?", "output": "42", "tokens": 7, "cost": 0.02, "timestamp": 1620000000}
711

@@ -10,10 +14,6 @@
1014
api_key=os.environ.get("OPENLAYER_API_KEY"),
1115
)
1216

13-
# Prepare the config for the data, which depends on your project's task type. In this
14-
# case, we have an LLM project:
15-
from openlayer.types.inference_pipelines import data_stream_params
16-
1717
config = data_stream_params.ConfigLlmData(
1818
input_variable_names=["user_query"],
1919
output_column_name="output",
@@ -25,7 +25,7 @@
2525

2626

2727
data_stream_response = client.inference_pipelines.data.stream(
28-
id="YOUR_INFERENCE_PIPELINE_ID",
28+
inference_pipeline_id="YOUR_INFERENCE_PIPELINE_ID",
2929
rows=[data],
3030
config=config,
3131
)

examples/tracing/anthropic/anthropic_tracing.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@
9595
"response = anthropic_client.messages.create(\n",
9696
" model=\"claude-3-opus-20240229\",\n",
9797
" max_tokens=1024,\n",
98-
" messages=[\n",
99-
" {\"role\": \"user\", \"content\": \"How are you doing today?\"}],\n",
98+
" messages=[{\"role\": \"user\", \"content\": \"How are you doing today?\"}],\n",
10099
")"
101100
]
102101
},

examples/tracing/azure-openai/azure_openai_tracing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
" model=os.environ.get(\"AZURE_OPENAI_DEPLOYMENT_NAME\"),\n",
107107
" messages=[\n",
108108
" {\"role\": \"user\", \"content\": \"How are you doing today?\"},\n",
109-
" ]\n",
109+
" ],\n",
110110
")"
111111
]
112112
},

examples/tracing/openai-assistant/openai_assistant_tracing.ipynb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
"thread = openai_client.beta.threads.create(\n",
103103
" messages=[\n",
104104
" {\n",
105-
" \"role\": \"user\",\n",
106-
" \"content\": \"Create a data visualization of the american GDP.\",\n",
105+
" \"role\": \"user\",\n",
106+
" \"content\": \"Create a data visualization of the american GDP.\",\n",
107107
" }\n",
108108
" ]\n",
109109
")"
@@ -117,10 +117,7 @@
117117
"outputs": [],
118118
"source": [
119119
"# Run assistant on thread\n",
120-
"run = openai_client.beta.threads.runs.create(\n",
121-
" thread_id=thread.id,\n",
122-
" assistant_id=assistant.id\n",
123-
")"
120+
"run = openai_client.beta.threads.runs.create(thread_id=thread.id, assistant_id=assistant.id)"
124121
]
125122
},
126123
{

examples/tracing/openai/openai_tracing.ipynb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@
9393
"outputs": [],
9494
"source": [
9595
"completion = openai_client.chat.completions.create(\n",
96-
" model=\"gpt-3.5-turbo\",\n",
97-
" messages=[\n",
98-
" {\"role\": \"user\", \"content\": \"How are you doing today?\"}\n",
99-
" ]\n",
96+
" model=\"gpt-3.5-turbo\", messages=[{\"role\": \"user\", \"content\": \"How are you doing today?\"}]\n",
10097
")"
10198
]
10299
},

examples/tracing/rag/rag_tracing.ipynb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@
7878
"source": [
7979
"class RagPipeline:\n",
8080
" def __init__(self, context_path: str):\n",
81-
" # Wrap OpenAI client with Openlayer's `trace_openai` to trace it \n",
81+
" # Wrap OpenAI client with Openlayer's `trace_openai` to trace it\n",
8282
" self.openai_client = trace_openai(OpenAI())\n",
83-
" \n",
83+
"\n",
8484
" self.vectorizer = TfidfVectorizer()\n",
85-
" with open(context_path, 'r', encoding='utf-8') as file:\n",
86-
" self.context_sections = file.read().split('\\n\\n') \n",
85+
" with open(context_path, \"r\", encoding=\"utf-8\") as file:\n",
86+
" self.context_sections = file.read().split(\"\\n\\n\")\n",
8787
" self.tfidf_matrix = self.vectorizer.fit_transform(self.context_sections)\n",
8888
"\n",
8989
" # Decorate the functions you'd like to trace with @trace()\n",
@@ -100,8 +100,8 @@
100100
"\n",
101101
" @trace()\n",
102102
" def retrieve_context(self, query: str) -> str:\n",
103-
" \"\"\"Context retriever. \n",
104-
" \n",
103+
" \"\"\"Context retriever.\n",
104+
"\n",
105105
" Given the query, returns the most similar context (using TFIDF).\n",
106106
" \"\"\"\n",
107107
" query_vector = self.vectorizer.transform([query])\n",
@@ -115,7 +115,10 @@
115115
" the prompt (formatted to conform with OpenAI models).\"\"\"\n",
116116
" return [\n",
117117
" {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",
118-
" {\"role\": \"user\", \"content\": f\"Answer the user query using only the following context: {context}. \\nUser query: {query}\"}\n",
118+
" {\n",
119+
" \"role\": \"user\",\n",
120+
" \"content\": f\"Answer the user query using only the following context: {context}. \\nUser query: {query}\",\n",
121+
" },\n",
119122
" ]\n",
120123
"\n",
121124
" @trace()\n",

src/openlayer/lib/core/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import os
99
from dataclasses import asdict, dataclass, field
10-
from typing import Any, Dict, List, Optional, Union, Set
10+
from typing import Any, Dict, List, Optional, Set, Union
1111

1212
import pandas as pd
1313

0 commit comments

Comments
 (0)