Skip to content

Commit 023ffbe

Browse files
authored
Add ruff rules for naming (#545)
1 parent 264a258 commit 023ffbe

File tree

21 files changed

+93
-91
lines changed

21 files changed

+93
-91
lines changed

docs/modules/examples/pages/qa-with-cassio.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ for filename in SAMPLEDATA:
113113
+
114114
[source,python]
115115
----
116-
cassVStore = Cassandra.from_documents(
116+
cass_vstore = Cassandra.from_documents(
117117
documents=documents,
118118
embedding=OpenAIEmbeddings(),
119119
session=session,
@@ -137,7 +137,7 @@ print(f"\nProcessing done.")
137137
----
138138
prompt = "Who is Luchesi?"
139139
140-
matched_docs = cassVStore.similarity_search(query=prompt, k=1)
140+
matched_docs = cass_vstore.similarity_search(query=prompt, k=1)
141141
142142
for i, d in enumerate(matched_docs):
143143
print(f"\n## Document {i}\n")
@@ -149,7 +149,7 @@ Create an Index on top of the vector store.
149149
+
150150
[source,python]
151151
----
152-
index = VectorStoreIndexWrapper(vectorstore=cassVStore)
152+
index = VectorStoreIndexWrapper(vectorstore=cass_vstore)
153153
----
154154
+
155155
. Create a retriever from the Index.
@@ -182,7 +182,7 @@ Your answer:
182182
"""
183183
prompt = ChatPromptTemplate.from_template(prompt)
184184
185-
qa = RetrievalQA.from_chain_type(llm=OpenAI(), retriever=cassVStore.as_retriever(), chain_type_kwargs={"prompt": prompt})
185+
qa = RetrievalQA.from_chain_type(llm=OpenAI(), retriever=cass_vstore.as_retriever(), chain_type_kwargs={"prompt": prompt})
186186
187187
result = qa.run("{question: Who is Luchesi?")
188188
result

docs/modules/examples/pages/rag-with-cassio.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ for filename in SAMPLEDATA:
142142
if len(new_docs) > 0:
143143
documents.extend(new_docs)
144144
145-
cassVStore = Cassandra.from_documents(
145+
cass_vstore = Cassandra.from_documents(
146146
documents=documents,
147147
embedding=OpenAIEmbeddings(),
148148
session=session,
@@ -158,7 +158,7 @@ print(f"\nProcessing done.")
158158
Use `VectorStoreIndexWrapper` from `langchain.indexes.vectorstore` for querying.
159159
[source,python]
160160
----
161-
index = VectorStoreIndexWrapper(vectorstore=cassVStore)
161+
index = VectorStoreIndexWrapper(vectorstore=cass_vstore)
162162
query = "Who is Luchesi?"
163163
index.query(query,llm=llm)
164164
query = "What motivates Montresor to seek revenge against Fortunato?"

examples/evaluation/langchain_trulens_full.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,12 @@
336336
"from trulens_eval.feedback.provider import AzureOpenAI\n",
337337
"\n",
338338
"# Initialize provider class\n",
339-
"azureOpenAI = AzureOpenAI(deployment_name=\"gpt-35-turbo\")\n",
339+
"azure_open_ai = AzureOpenAI(deployment_name=\"gpt-35-turbo\")\n",
340340
"\n",
341341
"context = App.select_context(rag_chain)\n",
342342
"\n",
343343
"# Define a groundedness feedback function\n",
344-
"grounded = Groundedness(groundedness_provider=azureOpenAI)\n",
344+
"grounded = Groundedness(groundedness_provider=azure_open_ai)\n",
345345
"f_groundedness = (\n",
346346
" Feedback(grounded.groundedness_measure_with_cot_reasons, name=\"groundedness\")\n",
347347
" .on(context.collect())\n",
@@ -351,19 +351,19 @@
351351
"\n",
352352
"# Question/answer relevance between overall question and answer.\n",
353353
"f_answer_relevance = Feedback(\n",
354-
" azureOpenAI.relevance_with_cot_reasons, name=\"answer_relevance\"\n",
354+
" azure_open_ai.relevance_with_cot_reasons, name=\"answer_relevance\"\n",
355355
").on_input_output()\n",
356356
"\n",
357357
"# Question/statement relevance between question and each context chunk.\n",
358358
"f_context_relevance = (\n",
359-
" Feedback(azureOpenAI.qs_relevance_with_cot_reasons, name=\"context_relevance\")\n",
359+
" Feedback(azure_open_ai.qs_relevance_with_cot_reasons, name=\"context_relevance\")\n",
360360
" .on_input()\n",
361361
" .on(context)\n",
362362
" .aggregate(np.mean)\n",
363363
")\n",
364364
"\n",
365365
"# GroundTruth for comparing the Answer to the Ground-Truth Answer\n",
366-
"ground_truth_collection = GroundTruthAgreement(golden_set, provider=azureOpenAI)\n",
366+
"ground_truth_collection = GroundTruthAgreement(golden_set, provider=azure_open_ai)\n",
367367
"f_answer_correctness = Feedback(\n",
368368
" ground_truth_collection.agreement_measure, name=\"answer_correctness\"\n",
369369
").on_input_output()"
@@ -441,7 +441,7 @@
441441
"outputs": [],
442442
"source": [
443443
"# this downloads the full set of records from the database for an app(s)\n",
444-
"dfRecords, feedbackColumns = tru.get_records_and_feedback([app_id])"
444+
"df_records, feedback_columns = tru.get_records_and_feedback([app_id])"
445445
]
446446
},
447447
{
@@ -455,7 +455,7 @@
455455
"\n",
456456
"# note that token & cost data collection is currently broken with AzureOpenAI\n",
457457
"\n",
458-
"columns_to_keep = feedbackColumns + [\n",
458+
"columns_to_keep = feedback_columns + [\n",
459459
" \"record_id\",\n",
460460
" \"input\",\n",
461461
" \"output\",\n",
@@ -465,11 +465,11 @@
465465
" \"total_cost\",\n",
466466
"]\n",
467467
"\n",
468-
"columns_to_drop = [col for col in dfRecords.columns if col not in columns_to_keep]\n",
468+
"columns_to_drop = [col for col in df_records.columns if col not in columns_to_keep]\n",
469469
"\n",
470-
"dfRecords.drop(columns=columns_to_drop, inplace=True)\n",
470+
"df_records.drop(columns=columns_to_drop, inplace=True)\n",
471471
"\n",
472-
"dfRecords"
472+
"df_records"
473473
]
474474
},
475475
{
@@ -490,7 +490,7 @@
490490
"import numpy as np\n",
491491
"import pandas as pd\n",
492492
"\n",
493-
"tests = feedbackColumns + [\"latency\", \"total_tokens\", \"total_cost\"]\n",
493+
"tests = feedback_columns + [\"latency\", \"total_tokens\", \"total_cost\"]\n",
494494
"\n",
495495
"results = pd.DataFrame(\n",
496496
" columns=[\"records\", \"mean\", \"median\", \"95th_percentile\", \"99th_percentile\"]\n",
@@ -506,7 +506,7 @@
506506
")\n",
507507
"\n",
508508
"for test in tests:\n",
509-
" data = dfRecords[test].dropna().to_list()\n",
509+
" data = df_records[test].dropna().to_list()\n",
510510
"\n",
511511
" records = len(data)\n",
512512
" mean = np.mean(data)\n",

examples/evaluation/tru_download.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
tru = tru_shared.init_tru()
55

6-
dfAll = pd.DataFrame()
6+
df_all = pd.DataFrame()
77

88
for app in tru.get_apps():
99
app_id = app["app_id"]
1010
print(f"Downloading data for {app_id}...")
11-
dfRecords, feedbackColumns = tru.get_records_and_feedback([app_id])
11+
df_records, feedback_columns = tru.get_records_and_feedback([app_id])
1212

13-
columns_to_keep = feedbackColumns + [
13+
columns_to_keep = feedback_columns + [
1414
"record_id",
1515
"input",
1616
"output",
@@ -19,16 +19,16 @@
1919
"total_tokens",
2020
"total_cost",
2121
]
22-
columns_to_drop = [col for col in dfRecords.columns if col not in columns_to_keep]
22+
columns_to_drop = [col for col in df_records.columns if col not in columns_to_keep]
2323

24-
dfRecords.drop(columns=columns_to_drop, inplace=True)
24+
df_records.drop(columns=columns_to_drop, inplace=True)
2525

26-
dfRecords["test"] = app_id.split("#")[0]
27-
dfRecords["test_uuid"] = app_id.split("#")[1]
28-
dfRecords["dataset"] = app_id.split("#")[2]
26+
df_records["test"] = app_id.split("#")[0]
27+
df_records["test_uuid"] = app_id.split("#")[1]
28+
df_records["dataset"] = app_id.split("#")[2]
2929

30-
dfAll = pd.concat([dfAll, dfRecords], axis=0, ignore_index=True)
30+
df_all = pd.concat([df_all, df_records], axis=0, ignore_index=True)
3131

3232
print("Writing results to parquet file.")
33-
dfAll.to_parquet("results.parquet")
33+
df_all.to_parquet("results.parquet")
3434
print("Done!")

examples/evaluation/tru_langchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
collection_name = "open_ai_512"
99

1010
vstore = tru_shared.get_astra_vector_store(framework, collection_name)
11-
chatModel = tru_shared.get_azure_chat_model(framework, "gpt-35-turbo", "0613")
11+
chat_model = tru_shared.get_azure_chat_model(framework, "gpt-35-turbo", "0613")
1212
embeddings = tru_shared.get_azure_embeddings_model(framework)
1313

1414
prompt_template = """
@@ -22,7 +22,7 @@
2222
pipeline = (
2323
{"context": vstore.as_retriever(), "question": RunnablePassthrough()}
2424
| prompt
25-
| chatModel
25+
| chat_model
2626
| StrOutputParser()
2727
)
2828

examples/evaluation/tru_llamaindex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
collection_name = "llama_512"
1414

1515
vstore = tru_shared.get_astra_vector_store(framework, collection_name)
16-
chatModel = tru_shared.get_azure_chat_model(framework, "gpt-35-turbo", "0613")
16+
chat_model = tru_shared.get_azure_chat_model(framework, "gpt-35-turbo", "0613")
1717
embeddings = tru_shared.get_azure_embeddings_model(framework)
1818

19-
service_context = ServiceContext.from_defaults(llm=chatModel, embed_model=embeddings)
19+
service_context = ServiceContext.from_defaults(llm=chat_model, embed_model=embeddings)
2020
storage_context = StorageContext.from_defaults(vector_store=vstore)
2121
vector_store_index = VectorStoreIndex.from_vector_store(
2222
vector_store=vstore, service_context=service_context

examples/evaluation/tru_shared.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ def init_tru():
6767

6868
def get_feedback_functions(pipeline, golden_set):
6969
# Initialize provider class
70-
azureOpenAI = AzureOpenAI(deployment_name="gpt-35-turbo")
70+
azure_open_ai = AzureOpenAI(deployment_name="gpt-35-turbo")
7171

7272
context = App.select_context(pipeline)
7373

7474
# Define a groundedness feedback function
75-
grounded = Groundedness(groundedness_provider=azureOpenAI)
75+
grounded = Groundedness(groundedness_provider=azure_open_ai)
7676
f_groundedness = (
7777
Feedback(grounded.groundedness_measure_with_cot_reasons, name="groundedness")
7878
.on(context.collect())
@@ -82,19 +82,19 @@ def get_feedback_functions(pipeline, golden_set):
8282

8383
# Question/answer relevance between overall question and answer.
8484
f_answer_relevance = Feedback(
85-
azureOpenAI.relevance_with_cot_reasons, name="answer_relevance"
85+
azure_open_ai.relevance_with_cot_reasons, name="answer_relevance"
8686
).on_input_output()
8787

8888
# Question/statement relevance between question and each context chunk.
8989
f_context_relevance = (
90-
Feedback(azureOpenAI.qs_relevance_with_cot_reasons, name="context_relevance")
90+
Feedback(azure_open_ai.qs_relevance_with_cot_reasons, name="context_relevance")
9191
.on_input()
9292
.on(context)
9393
.aggregate(np.mean)
9494
)
9595

9696
# GroundTruth for comparing the Answer to the Ground-Truth Answer
97-
ground_truth_collection = GroundTruthAgreement(golden_set, provider=azureOpenAI)
97+
ground_truth_collection = GroundTruthAgreement(golden_set, provider=azure_open_ai)
9898
f_answer_correctness = Feedback(
9999
ground_truth_collection.agreement_measure, name="answer_correctness"
100100
).on_input_output()
@@ -210,11 +210,11 @@ def execute_experiment(framework: Framework, pipeline, experiment_name: str):
210210

211211
# use a short uuid to ensure that multiple experiments with the same name don't
212212
# collide in the DB
213-
shortUuid = str(uuid.uuid4())[9:13]
213+
short_uuid = str(uuid.uuid4())[9:13]
214214
datasets, golden_set = get_test_data()
215215

216216
for dataset_name in datasets:
217-
app_id = f"{experiment_name}#{shortUuid}#{dataset_name}"
217+
app_id = f"{experiment_name}#{short_uuid}#{dataset_name}"
218218
tru_recorder = get_recorder(framework, pipeline, app_id, golden_set)
219219
for query in datasets[dataset_name]:
220220
try:

examples/notebooks/QA_with_cassio.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
" if len(new_docs) > 0:\n",
249249
" documents.extend(new_docs)\n",
250250
"\n",
251-
"cassVStore = Cassandra.from_documents(\n",
251+
"cass_vstore = Cassandra.from_documents(\n",
252252
" documents=documents,\n",
253253
" embedding=OpenAIEmbeddings(),\n",
254254
" session=None,\n",
@@ -395,7 +395,7 @@
395395
"query = \"Who is Luchesi?\"\n",
396396
"\n",
397397
"# find matching documentation using similarity search\n",
398-
"matched_docs = cassVStore.similarity_search(query=query, k=1)\n",
398+
"matched_docs = cass_vstore.similarity_search(query=query, k=1)\n",
399399
"\n",
400400
"# print out the relevant context that an LLM will use to produce an answer\n",
401401
"for i, d in enumerate(matched_docs):\n",
@@ -450,7 +450,7 @@
450450
"from langchain.indexes.vectorstore import VectorStoreIndexWrapper\n",
451451
"\n",
452452
"llm = ChatOpenAI(model=\"gpt-3.5-turbo-1106\")\n",
453-
"index = VectorStoreIndexWrapper(vectorstore=cassVStore)\n",
453+
"index = VectorStoreIndexWrapper(vectorstore=cass_vstore)\n",
454454
"\n",
455455
"# Query the index for relevant vectors to our prompt\n",
456456
"query = \"Who is Luchesi?\"\n",
@@ -495,7 +495,7 @@
495495
"query = ChatPromptTemplate.from_template(query)\n",
496496
"\n",
497497
"qa = RetrievalQA.from_chain_type(\n",
498-
" llm=llm, retriever=cassVStore.as_retriever(), chain_type_kwargs={\"prompt\": query}\n",
498+
" llm=llm, retriever=cass_vstore.as_retriever(), chain_type_kwargs={\"prompt\": query}\n",
499499
")\n",
500500
"\n",
501501
"result = qa.run(\"{question: Who is Luchesi?\")\n",
@@ -518,14 +518,14 @@
518518
"nbmake": {
519519
"post_cell_execute": [
520520
"# Deletes collection for test suite to allow each test to run with a fresh collection",
521-
"cassVStore.delete_collection()"
521+
"cass_vstore.delete_collection()"
522522
]
523523
}
524524
},
525525
"outputs": [],
526526
"source": [
527527
"# WARNING: This will delete the collection and all documents in the collection\n",
528-
"# cassVStore.delete_collection()"
528+
"# cass_vstore.delete_collection()"
529529
]
530530
}
531531
],

libs/colbert/tests/unit_tests/test_colbert_baseline_embeddings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,21 @@ def test_colbert_embedding_against_vanilla_impl():
122122

123123
embeddings_flat, _ = encoder.encode_passages(arctic_botany_chunks)
124124

125-
colbertSvc = ColbertEmbeddingModel(
125+
colbert_svc = ColbertEmbeddingModel(
126126
checkpoint=DEFAULT_COLBERT_MODEL,
127127
)
128-
embedded_chunks = colbertSvc.embed_texts(arctic_botany_chunks)
128+
embedded_chunks = colbert_svc.embed_texts(arctic_botany_chunks)
129129

130130
are_they_similar(embedded_chunks, embeddings_flat)
131131

132132

133133
def model_embedding(model: str):
134134
logging.info(f"test model compatibility {model}")
135-
colbertSvc = ColbertEmbeddingModel(
135+
colbert_svc = ColbertEmbeddingModel(
136136
checkpoint=model,
137137
query_maxlen=32,
138138
)
139-
embeddings = colbertSvc.embed_texts(arctic_botany_chunks)
139+
embeddings = colbert_svc.embed_texts(arctic_botany_chunks)
140140

141141
assert len(embeddings) == 8
142142
n = 0
@@ -148,7 +148,7 @@ def model_embedding(model: str):
148148
assert n == 645
149149

150150
# recall embeddings test
151-
embedding = colbertSvc.embed_query(
151+
embedding = colbert_svc.embed_query(
152152
query="What adaptations enable Arctic plants to survive and thrive "
153153
"in extremely cold temperatures and minimal sunlight?",
154154
query_maxlen=32,

libs/colbert/tests/unit_tests/test_colbert_embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test_colbert_query_embeddings():
3636
colbert = ColbertEmbeddingModel()
3737

3838
embedding = colbert.embed_query("who is the president of the united states?")
39-
queryTensor = torch.tensor(embedding)
40-
assert queryTensor.shape == (12, 128)
39+
query_tensor = torch.tensor(embedding)
40+
assert query_tensor.shape == (12, 128)
4141

4242
# test query encoding
4343
embedding = colbert.embed_query("test-query", query_maxlen=512)

0 commit comments

Comments
 (0)