Skip to content

Commit 9285c1b

Browse files
authored
Merge pull request lightspeed-core#651 from tisnik/lcore-642-llama-stack-configuration-regeneration
LCORE-642: Llama Stack configuration regeneration
2 parents 4113f9d + 86e21de commit 9285c1b

2 files changed

Lines changed: 455 additions & 3 deletions

File tree

src/llama_stack_configuration.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""Llama Stack configuration handling."""
22

3+
from typing import Any
4+
35
import yaml
46

57
from log import get_logger
68

7-
from models.config import Configuration
9+
from models.config import Configuration, ByokRag
810

911
logger = get_logger(__name__)
1012

@@ -28,10 +30,81 @@ def generate_configuration(
2830
with open(input_file, "r", encoding="utf-8") as file:
2931
ls_config = yaml.safe_load(file)
3032

31-
logger.info("Processing Llama Stack configuration")
32-
_ = config
33+
if len(config.byok_rag) == 0:
34+
logger.info("BYOK RAG is not configured: finishing")
35+
else:
36+
logger.info("Processing Llama Stack configuration")
37+
# create or update configuration section vector_dbs
38+
ls_config["vector_dbs"] = construct_vector_dbs_section(
39+
ls_config, config.byok_rag
40+
)
41+
# create or update configuration section providers/vector_io
42+
ls_config["providers"]["vector_io"] = construct_vector_io_providers_section(
43+
ls_config, config.byok_rag
44+
)
3345

3446
logger.info("Writing Llama Stack configuration into file %s", output_file)
3547

3648
with open(output_file, "w", encoding="utf-8") as file:
3749
yaml.dump(ls_config, file, Dumper=YamlDumper, default_flow_style=False)
50+
51+
52+
def construct_vector_dbs_section(
53+
ls_config: dict[str, Any], byok_rag: list[ByokRag]
54+
) -> list[dict[str, Any]]:
55+
"""Construct vector_dbs section in Llama Stack configuration file."""
56+
output = []
57+
58+
# fill-in existing vector_dbs entries
59+
if "vector_dbs" in ls_config:
60+
output = ls_config["vector_dbs"]
61+
62+
# append new vector_dbs entries
63+
for brag in byok_rag:
64+
output.append(
65+
{
66+
"vector_db_id": brag.vector_db_id,
67+
"provider_id": "byok_" + brag.vector_db_id,
68+
"embedding_model": brag.embedding_model,
69+
"embedding_dimension": brag.embedding_dimension,
70+
}
71+
)
72+
logger.info(
73+
"Added %s items into vector_dbs section, total items %s",
74+
len(byok_rag),
75+
len(output),
76+
)
77+
return output
78+
79+
80+
def construct_vector_io_providers_section(
81+
ls_config: dict[str, Any], byok_rag: list[ByokRag]
82+
) -> list[dict[str, Any]]:
83+
"""Construct providers/vector_io section in Llama Stack configuration file."""
84+
output = []
85+
86+
# fill-in existing vector_io entries
87+
if "vector_io" in ls_config["providers"]:
88+
output = ls_config["providers"]["vector_io"]
89+
90+
# append new vector_io entries
91+
for brag in byok_rag:
92+
output.append(
93+
{
94+
"provider_id": "byok_" + brag.vector_db_id,
95+
"provider_type": brag.rag_type,
96+
"config": {
97+
"kvstore": {
98+
"db_path": ".llama/" + brag.vector_db_id + ".db",
99+
"namespace": None,
100+
"type": "sqlite",
101+
}
102+
},
103+
}
104+
)
105+
logger.info(
106+
"Added %s items into providers/vector_io section, total items %s",
107+
len(byok_rag),
108+
len(output),
109+
)
110+
return output

0 commit comments

Comments
 (0)