Skip to content

Commit e157c7b

Browse files
feat: make the model names configurable
1 parent 48f4f84 commit e157c7b

5 files changed

Lines changed: 38 additions & 16 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ You should add an `.env` file in the root folder with the following contents:
2727
OPENAI_API_KEY=<your-llm-api-key> # token for the AI4EOSC LLM
2828
GRADIO_PASSWORD=<password-for-gradio-ui> # password for Gradio UI (user: admin)
2929
IS_DEV=True # shows the DEV UI with the finegrained configuration
30+
LLM_ENDPOINT="https://vllm.cloud.ai4eosc.eu"
31+
LLM_EMBEDDINGS="AI4EOSC/Qwen/Qwen3-Embedding-4B"
32+
LLM_CHAT="AI4EOSC/mistralai/Mistral-Small-3.1-24B-Instruct-2503"
3033
```
3134

3235
## Usage

docker/docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ services:
44
image: "ignacioheredia/dome-copilot:latest"
55
restart: always
66
environment:
7-
- OPENAI_API_KEY=*****************************
8-
- GRADIO_PASSWORD=****************************
7+
OPENAI_API_KEY: "*****************************"
8+
GRADIO_PASSWORD: "****************************"
9+
IS_DEV: False
10+
LLM_ENDPOINT: "https://vllm.cloud.ai4eosc.eu"
11+
LLM_EMBEDDINGS: "AI4EOSC/Qwen/Qwen3-Embedding-4B"
12+
LLM_CHAT: "AI4EOSC/mistralai/Mistral-Small-3.1-24B-Instruct-2503"
913
ports:
1014
- 5000:7860

dome_copilot/conf.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,25 @@
22
from pathlib import Path
33
import yaml
44

5-
from jinja2 import Template
65
from dotenv import load_dotenv
6+
from jinja2 import Template
7+
from openai import OpenAI
78

89

910
main_path = Path(__file__).parents[1].absolute()
1011
load_dotenv(main_path / ".env")
1112

12-
# Load envars
13+
# Load optional envars
14+
IS_DEV = os.environ.get("IS_DEV", "false").lower() == "true"
15+
LLM_ENDPOINT = os.environ.get("LLM_ENDPOINT", "https://vllm.cloud.ai4eosc.eu")
16+
LLM_EMBEDDINGS = os.environ.get("LLM_EMBEDDINGS", "AI4EOSC/Qwen/Qwen3-Embedding-4B")
17+
LLM_CHAT = os.environ.get(
18+
"LLM_CHAT", "AI4EOSC/mistralai/Mistral-Small-3.1-24B-Instruct-2503"
19+
)
20+
21+
# Load secrets
1322
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
1423
GRADIO_PASSWORD = os.environ.get("GRADIO_PASSWORD")
15-
IS_DEV = os.environ.get("IS_DEV", "false").lower() == "true"
1624

1725
if not all([OPENAI_API_KEY, GRADIO_PASSWORD]):
1826
raise Exception("Please provide an OPENAI_API_KEY and GRADIO_PASSWORD.")
@@ -31,12 +39,21 @@ def load_jinja(path):
3139
pre_prompt = load_jinja(templates_dir / "prompt-preprocessing.jinja")
3240
post_prompt = load_jinja(templates_dir / "prompt-postprocessing.jinja")
3341

34-
# DOME questionnaire
35-
3642

43+
# DOME questionnaire
3744
def load_yaml(path):
3845
with open(path) as stream:
3946
return yaml.safe_load(stream)
4047

4148

4249
dome = load_yaml(templates_dir / "dome-questionnaire.yml")
50+
51+
# Check that the models exist, to catch typos
52+
openai_client = OpenAI(api_key=OPENAI_API_KEY, base_url=LLM_ENDPOINT)
53+
models = [model.id for model in openai_client.models.list().data]
54+
if LLM_EMBEDDINGS not in models:
55+
raise Exception(
56+
f"Invalid embeddings model name:\n'{LLM_EMBEDDINGS}' not in {models}"
57+
)
58+
if LLM_CHAT not in models:
59+
raise Exception(f"Invalid chat model name:\n'{LLM_CHAT}' not in {models}")

dome_copilot/inference.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
# Initialize LLM and embedding model
2626
Settings.embed_model = OpenAILikeEmbedding(
27-
api_base="https://vllm.cloud.ai4eosc.eu",
27+
api_base=conf.LLM_ENDPOINT,
2828
api_key=conf.OPENAI_API_KEY,
29-
model_name="AI4EOSC/Qwen3-Embedding",
29+
model_name=conf.LLM_EMBEDDINGS,
3030
)
3131
Settings.llm = OpenAILike(
32-
api_base="https://vllm.cloud.ai4eosc.eu",
32+
api_base=conf.LLM_ENDPOINT,
3333
api_key=conf.OPENAI_API_KEY,
34-
model="AI4EOSC/Small",
34+
model=conf.LLM_CHAT,
3535
context_window=25000,
3636
is_chat_model=True,
3737
is_function_calling_model=False,
@@ -266,14 +266,11 @@ def postprocessing(annotations: dict, post_prompt: str = None):
266266
post_prompt = post_prompt.render()
267267

268268
# Initialize the OpenAI client with a longer timeout
269-
client = OpenAI(
270-
api_key=conf.OPENAI_API_KEY,
271-
base_url="https://vllm.cloud.ai4eosc.eu",
272-
)
269+
client = OpenAI(api_key=conf.OPENAI_API_KEY, base_url=conf.LLM_ENDPOINT)
273270

274271
# Call the LLM (override timeout per request as well)
275272
response = client.chat.completions.create(
276-
model="AI4EOSC/Small",
273+
model=conf.LLM_CHAT,
277274
messages=[
278275
{"role": "system", "content": post_prompt},
279276
{"role": "user", "content": json.dumps(annotations)},

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ python-dotenv>=1.2.2,<2.0
22
llama-index==0.14.4
33
llama-index-llms-openai-like==0.5.3
44
llama-index-embeddings-openai-like==0.2.2
5+
openai>=1.109.1, <2.0
56
gradio>5.49.1,<6.0
67
docling>2.63.0,<3.0
78
llama-index-readers-docling>=0.4.2

0 commit comments

Comments
 (0)