Skip to content
Closed
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
12 changes: 12 additions & 0 deletions mustache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Dict, Any
import chevron


def prepare_and_render_mustache(template_text: str, record_dict: Dict[str, Any]) -> str:
comb_dict = {
"rd": record_dict,
}
return chevron.render(
template=template_text,
data=comb_dict,
)
19 changes: 13 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ aiohappyeyeballs==2.4.3
# -r requirements/exec-env-requirements.txt
# aiohttp
aiohttp==3.11.7
# via
# -r requirements/exec-env-requirements.txt
# openai
# via -r requirements/exec-env-requirements.txt
aiosignal==1.3.1
# via
# -r requirements/exec-env-requirements.txt
Expand All @@ -23,6 +21,7 @@ anyio==4.6.2.post1
# -r requirements/exec-env-requirements.txt
# groq
# httpx
# openai
async-timeout==5.0.1
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -68,6 +67,8 @@ charset-normalizer==3.4.0
# via
# -r requirements/exec-env-requirements.txt
# requests
chevron==0.14.0
# via -r requirements/requirements.in
click==8.1.7
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -99,6 +100,7 @@ distro==1.9.0
# via
# -r requirements/exec-env-requirements.txt
# groq
# openai
docopt==0.6.2
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -144,6 +146,7 @@ httpx==0.27.2
# via
# -r requirements/exec-env-requirements.txt
# groq
# openai
idna==3.10
# via
# -r requirements/exec-env-requirements.txt
Expand All @@ -167,6 +170,8 @@ jinja2==3.1.4
# via
# -r requirements/exec-env-requirements.txt
# spacy
jiter==0.8.2
# via openai
joblib==1.4.2
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -254,8 +259,8 @@ numpy==1.23.4
# spacy
# textacy
# thinc
openai==0.27.7
# via -r requirements/exec-env-requirements.txt
openai==1.59.7
# via -r requirements/requirements.in
packaging==24.2
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -297,6 +302,7 @@ pydantic==2.7.4
# -r requirements/requirements.in
# confection
# groq
# openai
# spacy
# thinc
# weasel
Expand Down Expand Up @@ -343,7 +349,6 @@ requests==2.31.0
# -r requirements/exec-env-requirements.txt
# google-search-results
# lexmo
# openai
# spacy
# sumy
# textacy
Expand Down Expand Up @@ -380,6 +385,7 @@ sniffio==1.3.1
# anyio
# groq
# httpx
# openai
soupsieve==2.6
# via
# -r requirements/exec-env-requirements.txt
Expand Down Expand Up @@ -466,6 +472,7 @@ typing-extensions==4.12.2
# cloudpathlib
# groq
# multidict
# openai
# pydantic
# pydantic-core
# sqlalchemy
Expand Down
2 changes: 1 addition & 1 deletion requirements/exec-env-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ numpy==1.23.4
# spacy
# textacy
# thinc
openai==0.27.7
# openai==0.27.7
# via -r exec-env-requirements.in
packaging==24.2
# via
Expand Down
4 changes: 3 additions & 1 deletion requirements/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r exec-env-requirements.txt
pydantic==2.7.4
spacy[ja]==3.7.5
spacy[ja]==3.7.5
chevron==0.14.0
openai==1.59.7
11 changes: 9 additions & 2 deletions run_ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import spacy
import sys
from mustache import prepare_and_render_mustache
from spacy.tokens import DocBin


Expand All @@ -18,6 +19,8 @@ def get_check_data_type_function(data_type):
return [str], __check_data_type_text
elif data_type == "EMBEDDING_LIST":
return [list], __check_data_type_embedding_list
elif data_type == "LLM_RESPONSE":
return [str], __check_data_type_text
else:
raise ValueError(f"Unknown data type: {data_type}")

Expand Down Expand Up @@ -105,7 +108,7 @@ def parse_data_to_record_dict(record_chunk):

# This import statement will always be highlighted as a potential error, as during devtime,
# the script `labeling_functions` does not exist. It will be inserted at runtime
from attribute_calculators import ac
import attribute_calculators

vocab = spacy.blank(iso2_code).vocab

Expand All @@ -123,11 +126,15 @@ def parse_data_to_record_dict(record_chunk):
amount = len(record_dict_list)
__print_progress(0.0)
for record_dict in record_dict_list:
attribute_calculators.USER_PROMPT = prepare_and_render_mustache(
attribute_calculators.USER_PROMPT, record_dict
)

idx += 1
if idx % progress_size == 0:
progress = round(idx / amount, 2)
__print_progress(progress)
attr_value = ac(record_dict["data"])
attr_value = attribute_calculators.ac(record_dict["data"])
if not check_data_type(attr_value):
raise ValueError(
f"Attribute value `{attr_value}` is of type {type(attr_value)}, "
Expand Down
Loading