Skip to content
Open
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
5 changes: 3 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ x-llm: &llm
LLAMA_ARG_ENDPOINT_METRICS: 1
LLAMA_ARG_PORT: 8080
LLAMA_ARG_N_GPU_LAYERS: 99
LLAMA_ARG_JINJA: 1
NO_PROXY: ${NO_PROXY:-}
volumes:
- models_data:/models
Expand Down Expand Up @@ -86,13 +87,13 @@ services:

llm_cpu:
<<: *llm
image: ghcr.io/ggml-org/llama.cpp:server-b5170
image: ghcr.io/ggml-org/llama.cpp:server
profiles:
- cpu

llm_gpu:
<<: *llm
image: ghcr.io/ggml-org/llama.cpp:server-cuda-b5170
image: ghcr.io/ggml-org/llama.cpp:server-cuda
deploy:
resources:
reservations:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"djangorestframework>=3.15.2",
"environs[django]>=14.1.1",
"humanize>=4.12.1",
"instructor>=1.11.3",
"Markdown>=3.7",
"openai>=1.64.0",
"openpyxl>=3.1.5",
Expand Down
14 changes: 7 additions & 7 deletions radis/chats/utils/chat_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import Iterable

import instructor
import openai
from django.conf import settings
from openai.types.chat import ChatCompletionMessageParam
Expand Down Expand Up @@ -49,20 +50,19 @@ def __init__(self) -> None:
base_url = _get_base_url()
api_key = settings.EXTERNAL_LLM_PROVIDER_API_KEY

self._client = openai.OpenAI(base_url=base_url, api_key=api_key)
client = openai.OpenAI(base_url=base_url, api_key=api_key)
self._client = instructor.from_openai(client)
self._llm_model_name = settings.LLM_MODEL_NAME

def extract_data(self, prompt: str, schema: type[BaseModel]) -> BaseModel:
logger.debug("Sending prompt and schema to LLM to extract data.")
logger.debug("Prompt:\n%s", prompt)
logger.debug("Schema:\n%s", schema.model_json_schema())

completion = self._client.beta.chat.completions.parse(
result = self._client.chat.completions.create(
model=self._llm_model_name,
messages=[{"role": "system", "content": prompt}],
response_format=schema,
response_model=schema,
)
event = completion.choices[0].message.parsed
assert event
logger.debug("Received from LLM: %s", event)
return event
logger.debug("Received from LLM: %s", result)
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the assertion check for the parsed event could lead to returning None or invalid results. The original code had assert event to ensure a valid response was received before returning it.

Suggested change
logger.debug("Received from LLM: %s", result)
logger.debug("Received from LLM: %s", result)
assert result is not None, "LLM returned None for extract_data"

Copilot uses AI. Check for mistakes.
return result
Loading
Loading