Skip to content

fix: fix rag-toolkit coverity scan (#742) #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
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
10 changes: 4 additions & 6 deletions usecases/ai/rag-toolkit/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import os
os.environ['HF_HOME'] = "./data/huggingface"

import io
import time
import uuid
import json
import magic
import asyncio
import logging
import requests
import numpy as np
Expand Down Expand Up @@ -79,12 +76,13 @@ async def lifespan(app: FastAPI):


app = FastAPI(lifespan=lifespan)
allowed_cors = json.loads(os.getenv("ALLOWED_CORS", '["http://localhost:8010"]'))
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=allowed_cors,
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']
allow_headers=['*'],
)


Expand Down
33 changes: 27 additions & 6 deletions usecases/ai/rag-toolkit/backend/scripts/convert_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import sys
import json
import argparse
from pathlib import Path

from transformers import AutoTokenizer
from template import ollama_template

MODELFILE_TEMPLATE = '''FROM ../llm

TEMPLATE """{chat_template}"""
'''


def create_modelfile(model_path, save_path):
with open(f"{model_path}/config.json", 'r') as f:
_data = f.read()
Expand All @@ -23,10 +24,30 @@ def create_modelfile(model_path, save_path):
with open(save_path, "w") as f:
f.write(data)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create a modified model file from a tokenizer.')
parser.add_argument('--model_path', type=str, required=True, help='The identifier for the model file')
parser.add_argument('--save_path', type=str, required=True, help='The path where the modified model file will be saved')
parser = argparse.ArgumentParser(
description='Create a modified model file from a tokenizer.'
)
parser.add_argument(
'--model_path',
type=str,
required=True,
help='The identifier for the model file'
)
parser.add_argument(
'--save_path',
type=str,
required=True,
help='The path where the modified model file will be saved'
)
args = parser.parse_args(None if len(sys.argv) > 1 else ["--help"])

create_modelfile(args.model_path, args.save_path)

safe_model_path = Path(args.model_path).resolve()
if not safe_model_path.is_dir():
print(f"Model path '{args.model_path}' is not a directory.")
sys.exit(1)

safe_save_path = Path(args.save_path).resolve()

create_modelfile(safe_model_path, safe_save_path)
3 changes: 3 additions & 0 deletions usecases/ai/rag-toolkit/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
- "127.0.0.1:8011:8011"
environment:
- OPENAI_BASE_URL=http://serving:8000/v1
- ALLOWED_CORS=["http://localhost:8010"]
- EMBEDDING_DEVICE=${EMBEDDING_DEVICE:-CPU}
- RERANKER_DEVICE=${RERANKER_DEVICE:-CPU}
depends_on:
Expand All @@ -59,6 +60,8 @@ services:
- /dev/dri:/dev/dri
networks:
- app-network
ports:
- "127.0.0.1:8012:8000"
environment:
- DEFAULT_MODEL_ID=Qwen/Qwen2.5-7B-Instruct
- MODEL_PATH=./data/models/llm
Expand Down