Spaces:
Runtime error
Runtime error
Commit Β·
30b40e4
1
Parent(s): 4f7a2e6
Refactor imports to use langchain_classic and update temperature setting in model configuration
Browse files- app.py +3 -3
- tests/.chainlit/config.toml +150 -0
- tests/test_ragas.ipynb +137 -96
- tests/test_ragas.py +1 -1
app.py
CHANGED
|
@@ -12,8 +12,8 @@ from pydantic import SecretStr
|
|
| 12 |
load_dotenv()
|
| 13 |
|
| 14 |
|
| 15 |
-
from
|
| 16 |
-
from
|
| 17 |
from langchain_nebius import ChatNebius
|
| 18 |
|
| 19 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
@@ -62,7 +62,7 @@ embedding_model = NebiusEmbeddings(
|
|
| 62 |
model = ChatNebius(
|
| 63 |
model="meta-llama/Llama-3.3-70B-Instruct",
|
| 64 |
streaming=False, # Change for Production
|
| 65 |
-
temperature=0.
|
| 66 |
max_tokens=8192,
|
| 67 |
top_p=0.95,
|
| 68 |
api_key=SecretStr(os.getenv("OPENAI_API_KEY")),
|
|
|
|
| 12 |
load_dotenv()
|
| 13 |
|
| 14 |
|
| 15 |
+
from langchain_classic.chains import create_retrieval_chain
|
| 16 |
+
from langchain_classic.chains.combine_documents import create_stuff_documents_chain
|
| 17 |
from langchain_nebius import ChatNebius
|
| 18 |
|
| 19 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
|
|
| 62 |
model = ChatNebius(
|
| 63 |
model="meta-llama/Llama-3.3-70B-Instruct",
|
| 64 |
streaming=False, # Change for Production
|
| 65 |
+
temperature=0.2,
|
| 66 |
max_tokens=8192,
|
| 67 |
top_p=0.95,
|
| 68 |
api_key=SecretStr(os.getenv("OPENAI_API_KEY")),
|
tests/.chainlit/config.toml
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
# List of environment variables to be provided by each user to use the app.
|
| 3 |
+
user_env = []
|
| 4 |
+
|
| 5 |
+
# Duration (in seconds) during which the session is saved when the connection is lost
|
| 6 |
+
session_timeout = 3600
|
| 7 |
+
|
| 8 |
+
# Duration (in seconds) of the user session expiry
|
| 9 |
+
user_session_timeout = 1296000 # 15 days
|
| 10 |
+
|
| 11 |
+
# Enable third parties caching (e.g., LangChain cache)
|
| 12 |
+
cache = false
|
| 13 |
+
|
| 14 |
+
# Whether to persist user environment variables (API keys) to the database
|
| 15 |
+
# Set to true to store user env vars in DB, false to exclude them for security
|
| 16 |
+
persist_user_env = false
|
| 17 |
+
|
| 18 |
+
# Whether to mask user environment variables (API keys) in the UI with password type
|
| 19 |
+
# Set to true to show API keys as ***, false to show them as plain text
|
| 20 |
+
mask_user_env = false
|
| 21 |
+
|
| 22 |
+
# Authorized origins
|
| 23 |
+
allow_origins = ["*"]
|
| 24 |
+
|
| 25 |
+
[features]
|
| 26 |
+
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
|
| 27 |
+
unsafe_allow_html = false
|
| 28 |
+
|
| 29 |
+
# Process and display mathematical expressions. This can clash with "$" characters in messages.
|
| 30 |
+
latex = false
|
| 31 |
+
|
| 32 |
+
# Autoscroll new user messages at the top of the window
|
| 33 |
+
user_message_autoscroll = true
|
| 34 |
+
|
| 35 |
+
# Automatically tag threads with the current chat profile (if a chat profile is used)
|
| 36 |
+
auto_tag_thread = true
|
| 37 |
+
|
| 38 |
+
# Allow users to edit their own messages
|
| 39 |
+
edit_message = true
|
| 40 |
+
|
| 41 |
+
# Allow users to share threads (backend + UI). Requires an app-defined on_shared_thread_view callback.
|
| 42 |
+
allow_thread_sharing = false
|
| 43 |
+
|
| 44 |
+
[features.slack]
|
| 45 |
+
# Add emoji reaction when message is received (requires reactions:write OAuth scope)
|
| 46 |
+
reaction_on_message_received = false
|
| 47 |
+
|
| 48 |
+
# Authorize users to spontaneously upload files with messages
|
| 49 |
+
[features.spontaneous_file_upload]
|
| 50 |
+
enabled = true
|
| 51 |
+
# Define accepted file types using MIME types
|
| 52 |
+
# Examples:
|
| 53 |
+
# 1. For specific file types:
|
| 54 |
+
# accept = ["image/jpeg", "image/png", "application/pdf"]
|
| 55 |
+
# 2. For all files of certain type:
|
| 56 |
+
# accept = ["image/*", "audio/*", "video/*"]
|
| 57 |
+
# 3. For specific file extensions:
|
| 58 |
+
# accept = { "application/octet-stream" = [".xyz", ".pdb"] }
|
| 59 |
+
# Note: Using "*/*" is not recommended as it may cause browser warnings
|
| 60 |
+
accept = ["*/*"]
|
| 61 |
+
max_files = 20
|
| 62 |
+
max_size_mb = 500
|
| 63 |
+
|
| 64 |
+
[features.audio]
|
| 65 |
+
# Enable audio features
|
| 66 |
+
enabled = false
|
| 67 |
+
# Sample rate of the audio
|
| 68 |
+
sample_rate = 24000
|
| 69 |
+
|
| 70 |
+
[features.mcp]
|
| 71 |
+
# Enable Model Context Protocol (MCP) features
|
| 72 |
+
enabled = false
|
| 73 |
+
|
| 74 |
+
[features.mcp.sse]
|
| 75 |
+
enabled = true
|
| 76 |
+
|
| 77 |
+
[features.mcp.streamable-http]
|
| 78 |
+
enabled = true
|
| 79 |
+
|
| 80 |
+
[features.mcp.stdio]
|
| 81 |
+
enabled = true
|
| 82 |
+
# Only the executables in the allow list can be used for MCP stdio server.
|
| 83 |
+
# Only need the base name of the executable, e.g. "npx", not "/usr/bin/npx".
|
| 84 |
+
# Please don't comment this line for now, we need it to parse the executable name.
|
| 85 |
+
allowed_executables = [ "npx", "uvx" ]
|
| 86 |
+
|
| 87 |
+
[UI]
|
| 88 |
+
# Name of the assistant.
|
| 89 |
+
name = "Assistant"
|
| 90 |
+
|
| 91 |
+
# default_theme = "dark"
|
| 92 |
+
|
| 93 |
+
# layout = "wide"
|
| 94 |
+
|
| 95 |
+
# default_sidebar_state = "open"
|
| 96 |
+
|
| 97 |
+
# Description of the assistant. This is used for HTML tags.
|
| 98 |
+
# description = ""
|
| 99 |
+
|
| 100 |
+
# Chain of Thought (CoT) display mode. Can be "hidden", "tool_call" or "full".
|
| 101 |
+
cot = "full"
|
| 102 |
+
|
| 103 |
+
# Specify a CSS file that can be used to customize the user interface.
|
| 104 |
+
# The CSS file can be served from the public directory or via an external link.
|
| 105 |
+
# custom_css = "/public/test.css"
|
| 106 |
+
|
| 107 |
+
# Specify additional attributes for a custom CSS file
|
| 108 |
+
# custom_css_attributes = "media=\"print\""
|
| 109 |
+
|
| 110 |
+
# Specify a JavaScript file that can be used to customize the user interface.
|
| 111 |
+
# The JavaScript file can be served from the public directory.
|
| 112 |
+
# custom_js = "/public/test.js"
|
| 113 |
+
|
| 114 |
+
# The style of alert boxes. Can be "classic" or "modern".
|
| 115 |
+
alert_style = "classic"
|
| 116 |
+
|
| 117 |
+
# Specify additional attributes for custom JS file
|
| 118 |
+
# custom_js_attributes = "async type = \"module\""
|
| 119 |
+
|
| 120 |
+
# Custom login page image, relative to public directory or external URL
|
| 121 |
+
# login_page_image = "/public/custom-background.jpg"
|
| 122 |
+
|
| 123 |
+
# Custom login page image filter (Tailwind internal filters, no dark/light variants)
|
| 124 |
+
# login_page_image_filter = "brightness-50 grayscale"
|
| 125 |
+
# login_page_image_dark_filter = "contrast-200 blur-sm"
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
# Specify a custom meta image url.
|
| 129 |
+
# custom_meta_image_url = "https://chainlit-cloud.s3.eu-west-3.amazonaws.com/logo/chainlit_banner.png"
|
| 130 |
+
|
| 131 |
+
# Load assistant logo directly from URL.
|
| 132 |
+
logo_file_url = ""
|
| 133 |
+
|
| 134 |
+
# Load assistant avatar image directly from URL.
|
| 135 |
+
default_avatar_file_url = ""
|
| 136 |
+
|
| 137 |
+
# Specify a custom build directory for the frontend.
|
| 138 |
+
# This can be used to customize the frontend code.
|
| 139 |
+
# Be careful: If this is a relative path, it should not start with a slash.
|
| 140 |
+
# custom_build = "./public/build"
|
| 141 |
+
|
| 142 |
+
# Specify optional one or more custom links in the header.
|
| 143 |
+
# [[UI.header_links]]
|
| 144 |
+
# name = "Issues"
|
| 145 |
+
# display_name = "Report Issue"
|
| 146 |
+
# icon_url = "https://avatars.githubusercontent.com/u/128686189?s=200&v=4"
|
| 147 |
+
# url = "https://github.com/Chainlit/chainlit/issues"
|
| 148 |
+
|
| 149 |
+
[meta]
|
| 150 |
+
generated_by = "2.8.0"
|
tests/test_ragas.ipynb
CHANGED
|
@@ -2,30 +2,25 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"id": "6bb3bb7d",
|
| 7 |
"metadata": {},
|
| 8 |
-
"outputs": [
|
| 9 |
-
{
|
| 10 |
-
"name": "stderr",
|
| 11 |
-
"output_type": "stream",
|
| 12 |
-
"text": [
|
| 13 |
-
"f:\\Dissertation\\prod-rag-chat\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
| 14 |
-
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 15 |
-
]
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
"name": "stdout",
|
| 19 |
-
"output_type": "stream",
|
| 20 |
-
"text": [
|
| 21 |
-
"2025-08-16 16:34:21 - Loaded .env file\n"
|
| 22 |
-
]
|
| 23 |
-
}
|
| 24 |
-
],
|
| 25 |
"source": [
|
| 26 |
"from datasets import Dataset\n",
|
| 27 |
"from app import retrieve_relevant_documents, emb_text, model, embedding_model\n",
|
| 28 |
-
"from
|
| 29 |
"from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
| 30 |
"from langchain.schema.runnable import RunnableLambda\n",
|
| 31 |
"from langchain_core.documents import Document"
|
|
@@ -33,7 +28,7 @@
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"cell_type": "code",
|
| 36 |
-
"execution_count":
|
| 37 |
"id": "e572fb31",
|
| 38 |
"metadata": {},
|
| 39 |
"outputs": [],
|
|
@@ -105,7 +100,7 @@
|
|
| 105 |
},
|
| 106 |
{
|
| 107 |
"cell_type": "code",
|
| 108 |
-
"execution_count":
|
| 109 |
"id": "330ee35d",
|
| 110 |
"metadata": {},
|
| 111 |
"outputs": [],
|
|
@@ -149,7 +144,7 @@
|
|
| 149 |
},
|
| 150 |
{
|
| 151 |
"cell_type": "code",
|
| 152 |
-
"execution_count":
|
| 153 |
"id": "ba3810dd",
|
| 154 |
"metadata": {},
|
| 155 |
"outputs": [
|
|
@@ -157,18 +152,18 @@
|
|
| 157 |
"name": "stdout",
|
| 158 |
"output_type": "stream",
|
| 159 |
"text": [
|
| 160 |
-
"2025-
|
| 161 |
-
"Relevant documents: {'text': 'What is a provision, criterion or practice? The phrase βprovision, criterion or practiceβ is not defined by the Act. These concepts should be construed widely so as to include, for example, any formal or informal policies, rules, practices, arrangements, criteria, procedures, activities or provisions. They can cover one-off decisions and actions. In simple terms, they are about the way an education provider does things. Example:', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 95, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': '3ae881ad6f81487213a9e234debf0921'}, 'score': 0.
|
| 162 |
-
"2025-
|
| 163 |
-
"2025-
|
| 164 |
-
"2025-
|
| 165 |
-
"Relevant documents: {'text': 'βReasonableβ means having regard to all of the circumstances including the nature of the act and how obviously discriminatory it is, the authority of the person making the statement and the knowledge that the helper has or ought to have.', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 36, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': 'c5e3a60e2a6ccc88e0eff961f645a962'}, 'score': 0.
|
| 166 |
-
"2025-
|
| 167 |
-
"2025-
|
| 168 |
-
"2025-
|
| 169 |
-
"Relevant documents: {'text': 'The Act states that disadvantage must be substantial, which is defined as more than minor or trivial. Whether such a disadvantage exists in a particular case is a question of fact, and is assessed on an objective basis. s212(1)', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 89, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': 'b9e8ef04daf9150c9f7e32736b53df5b'}, 'score': 0.
|
| 170 |
-
"2025-
|
| 171 |
-
"2025-
|
| 172 |
]
|
| 173 |
}
|
| 174 |
],
|
|
@@ -211,7 +206,7 @@
|
|
| 211 |
},
|
| 212 |
{
|
| 213 |
"cell_type": "code",
|
| 214 |
-
"execution_count":
|
| 215 |
"id": "3e016be2",
|
| 216 |
"metadata": {},
|
| 217 |
"outputs": [
|
|
@@ -226,123 +221,169 @@
|
|
| 226 |
"name": "stdout",
|
| 227 |
"output_type": "stream",
|
| 228 |
"text": [
|
| 229 |
-
"2025-
|
| 230 |
-
"2025-
|
| 231 |
-
"2025-
|
| 232 |
-
"2025-
|
| 233 |
-
"2025-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
"
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
"2025-
|
| 248 |
-
"2025-
|
| 249 |
-
"2025-
|
| 250 |
-
"2025-
|
| 251 |
-
"2025-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
]
|
| 253 |
},
|
| 254 |
{
|
| 255 |
"name": "stderr",
|
| 256 |
"output_type": "stream",
|
| 257 |
"text": [
|
| 258 |
-
"Evaluating:
|
| 259 |
]
|
| 260 |
},
|
| 261 |
{
|
| 262 |
"name": "stdout",
|
| 263 |
"output_type": "stream",
|
| 264 |
"text": [
|
| 265 |
-
"2025-
|
| 266 |
-
"2025-
|
| 267 |
-
"2025-
|
| 268 |
-
"2025-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
]
|
| 270 |
},
|
| 271 |
{
|
| 272 |
"name": "stderr",
|
| 273 |
"output_type": "stream",
|
| 274 |
"text": [
|
| 275 |
-
"Evaluating:
|
| 276 |
]
|
| 277 |
},
|
| 278 |
{
|
| 279 |
"name": "stdout",
|
| 280 |
"output_type": "stream",
|
| 281 |
"text": [
|
| 282 |
-
"2025-
|
| 283 |
-
"2025-08-16 16:35:29 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 284 |
-
"2025-08-16 16:35:31 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 285 |
-
"2025-08-16 16:35:31 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 286 |
-
"2025-08-16 16:35:31 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n"
|
| 287 |
]
|
| 288 |
},
|
| 289 |
{
|
| 290 |
"name": "stderr",
|
| 291 |
"output_type": "stream",
|
| 292 |
"text": [
|
| 293 |
-
"Evaluating:
|
| 294 |
]
|
| 295 |
},
|
| 296 |
{
|
| 297 |
"name": "stdout",
|
| 298 |
"output_type": "stream",
|
| 299 |
"text": [
|
| 300 |
-
"2025-
|
| 301 |
-
"2025-08-16 16:35:32 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 302 |
-
"2025-08-16 16:35:33 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 303 |
]
|
| 304 |
},
|
| 305 |
{
|
| 306 |
"name": "stderr",
|
| 307 |
"output_type": "stream",
|
| 308 |
"text": [
|
| 309 |
-
"Evaluating:
|
| 310 |
]
|
| 311 |
},
|
| 312 |
{
|
| 313 |
"name": "stdout",
|
| 314 |
"output_type": "stream",
|
| 315 |
"text": [
|
| 316 |
-
"2025-
|
| 317 |
]
|
| 318 |
},
|
| 319 |
{
|
| 320 |
"name": "stderr",
|
| 321 |
"output_type": "stream",
|
| 322 |
"text": [
|
| 323 |
-
"Evaluating:
|
| 324 |
]
|
| 325 |
},
|
| 326 |
{
|
| 327 |
"name": "stdout",
|
| 328 |
"output_type": "stream",
|
| 329 |
"text": [
|
| 330 |
-
"2025-
|
| 331 |
-
"2025-08-16 16:35:35 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 332 |
-
"2025-08-16 16:35:35 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 333 |
-
"2025-08-16 16:35:36 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 334 |
-
"2025-08-16 16:35:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 335 |
-
"2025-08-16 16:35:39 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 336 |
-
"2025-08-16 16:35:39 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 337 |
-
"2025-08-16 16:35:41 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 338 |
-
"2025-08-16 16:35:43 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 339 |
]
|
| 340 |
},
|
| 341 |
{
|
| 342 |
"name": "stderr",
|
| 343 |
"output_type": "stream",
|
| 344 |
"text": [
|
| 345 |
-
"Evaluating:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
]
|
| 347 |
}
|
| 348 |
],
|
|
@@ -379,7 +420,7 @@
|
|
| 379 |
},
|
| 380 |
{
|
| 381 |
"cell_type": "code",
|
| 382 |
-
"execution_count":
|
| 383 |
"id": "d8514ff3",
|
| 384 |
"metadata": {
|
| 385 |
"slideshow": {
|
|
@@ -402,19 +443,19 @@
|
|
| 402 |
"2 [The Act states that disadvantage must be subs... \n",
|
| 403 |
"\n",
|
| 404 |
" response \\\n",
|
| 405 |
-
"0
|
| 406 |
-
"1
|
| 407 |
-
"2
|
| 408 |
"\n",
|
| 409 |
" reference context_precision \\\n",
|
| 410 |
-
"0 The Equality and Human Rights Commission (EHRC...
|
| 411 |
-
"1 There are two key considerations of 'reasonabl...
|
| 412 |
-
"2 'Substantial' is defined in the Act as 'more t...
|
| 413 |
"\n",
|
| 414 |
" context_recall faithfulness answer_relevancy \n",
|
| 415 |
-
"0
|
| 416 |
-
"1
|
| 417 |
-
"2
|
| 418 |
]
|
| 419 |
}
|
| 420 |
],
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
+
"id": "cb2ff14b",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import sys\n",
|
| 11 |
+
"sys.path.append('..')"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 3,
|
| 17 |
"id": "6bb3bb7d",
|
| 18 |
"metadata": {},
|
| 19 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"source": [
|
| 21 |
"from datasets import Dataset\n",
|
| 22 |
"from app import retrieve_relevant_documents, emb_text, model, embedding_model\n",
|
| 23 |
+
"from langchain_classic.chains.combine_documents import create_stuff_documents_chain\n",
|
| 24 |
"from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
| 25 |
"from langchain.schema.runnable import RunnableLambda\n",
|
| 26 |
"from langchain_core.documents import Document"
|
|
|
|
| 28 |
},
|
| 29 |
{
|
| 30 |
"cell_type": "code",
|
| 31 |
+
"execution_count": 4,
|
| 32 |
"id": "e572fb31",
|
| 33 |
"metadata": {},
|
| 34 |
"outputs": [],
|
|
|
|
| 100 |
},
|
| 101 |
{
|
| 102 |
"cell_type": "code",
|
| 103 |
+
"execution_count": 5,
|
| 104 |
"id": "330ee35d",
|
| 105 |
"metadata": {},
|
| 106 |
"outputs": [],
|
|
|
|
| 144 |
},
|
| 145 |
{
|
| 146 |
"cell_type": "code",
|
| 147 |
+
"execution_count": 6,
|
| 148 |
"id": "ba3810dd",
|
| 149 |
"metadata": {},
|
| 150 |
"outputs": [
|
|
|
|
| 152 |
"name": "stdout",
|
| 153 |
"output_type": "stream",
|
| 154 |
"text": [
|
| 155 |
+
"2025-11-27 02:10:22 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 156 |
+
"Relevant documents: {'text': 'What is a provision, criterion or practice? The phrase βprovision, criterion or practiceβ is not defined by the Act. These concepts should be construed widely so as to include, for example, any formal or informal policies, rules, practices, arrangements, criteria, procedures, activities or provisions. They can cover one-off decisions and actions. In simple terms, they are about the way an education provider does things. Example:', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 95, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': '3ae881ad6f81487213a9e234debf0921'}, 'score': 0.7807720899581909}\n",
|
| 157 |
+
"2025-11-27 02:10:34 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 158 |
+
"2025-11-27 02:10:34 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 159 |
+
"2025-11-27 02:10:35 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 160 |
+
"Relevant documents: {'text': 'βReasonableβ means having regard to all of the circumstances including the nature of the act and how obviously discriminatory it is, the authority of the person making the statement and the knowledge that the helper has or ought to have.', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 36, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': 'c5e3a60e2a6ccc88e0eff961f645a962'}, 'score': 0.7367081046104431}\n",
|
| 161 |
+
"2025-11-27 02:10:51 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 162 |
+
"2025-11-27 02:10:52 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 163 |
+
"2025-11-27 02:10:52 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 164 |
+
"Relevant documents: {'text': 'The Act states that disadvantage must be substantial, which is defined as more than minor or trivial. Whether such a disadvantage exists in a particular case is a question of fact, and is assessed on an objective basis. s212(1)', 'metadata': {'source': 'data\\\\technical-guidance-further-higher-education.docx', 'file_directory': 'data', 'filename': 'technical-guidance-further-higher-education.docx', 'last_modified': '2025-07-02T21:00:50', 'page_number': 89, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'category': 'CompositeElement', 'element_id': 'b9e8ef04daf9150c9f7e32736b53df5b'}, 'score': 0.8376985788345337}\n",
|
| 165 |
+
"2025-11-27 02:11:10 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 166 |
+
"2025-11-27 02:11:10 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n"
|
| 167 |
]
|
| 168 |
}
|
| 169 |
],
|
|
|
|
| 206 |
},
|
| 207 |
{
|
| 208 |
"cell_type": "code",
|
| 209 |
+
"execution_count": 7,
|
| 210 |
"id": "3e016be2",
|
| 211 |
"metadata": {},
|
| 212 |
"outputs": [
|
|
|
|
| 221 |
"name": "stdout",
|
| 222 |
"output_type": "stream",
|
| 223 |
"text": [
|
| 224 |
+
"2025-11-27 02:11:16 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 225 |
+
"2025-11-27 02:11:22 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 226 |
+
"2025-11-27 02:11:23 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 227 |
+
"2025-11-27 02:11:23 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 228 |
+
"2025-11-27 02:11:23 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n"
|
| 229 |
+
]
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"name": "stderr",
|
| 233 |
+
"output_type": "stream",
|
| 234 |
+
"text": [
|
| 235 |
+
"Evaluating: 8%|β | 1/12 [00:10<01:50, 10.08s/it]"
|
| 236 |
+
]
|
| 237 |
+
},
|
| 238 |
+
{
|
| 239 |
+
"name": "stdout",
|
| 240 |
+
"output_type": "stream",
|
| 241 |
+
"text": [
|
| 242 |
+
"2025-11-27 02:11:24 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 243 |
+
"2025-11-27 02:11:24 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 244 |
+
"2025-11-27 02:11:24 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 245 |
+
"2025-11-27 02:11:24 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 246 |
+
"2025-11-27 02:11:24 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 247 |
+
"2025-11-27 02:11:26 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 248 |
+
"2025-11-27 02:11:27 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 249 |
+
"2025-11-27 02:11:27 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 250 |
+
"2025-11-27 02:11:27 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 251 |
+
"2025-11-27 02:11:34 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 252 |
+
"2025-11-27 02:11:34 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 253 |
+
"2025-11-27 02:11:35 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n",
|
| 254 |
+
"2025-11-27 02:11:35 - HTTP Request: POST https://api.studio.nebius.ai/v1/embeddings \"HTTP/1.1 200 OK\"\n"
|
| 255 |
+
]
|
| 256 |
+
},
|
| 257 |
+
{
|
| 258 |
+
"name": "stderr",
|
| 259 |
+
"output_type": "stream",
|
| 260 |
+
"text": [
|
| 261 |
+
"Evaluating: 17%|ββ | 2/12 [00:23<02:01, 12.20s/it]"
|
| 262 |
+
]
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"name": "stdout",
|
| 266 |
+
"output_type": "stream",
|
| 267 |
+
"text": [
|
| 268 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 269 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 270 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 271 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 272 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 273 |
+
"2025-11-27 02:11:38 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"name": "stderr",
|
| 278 |
+
"output_type": "stream",
|
| 279 |
+
"text": [
|
| 280 |
+
"Evaluating: 33%|ββββ | 4/12 [00:34<01:02, 7.87s/it]"
|
| 281 |
+
]
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "stdout",
|
| 285 |
+
"output_type": "stream",
|
| 286 |
+
"text": [
|
| 287 |
+
"2025-11-27 02:11:48 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 288 |
+
"2025-11-27 02:11:48 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 289 |
]
|
| 290 |
},
|
| 291 |
{
|
| 292 |
"name": "stderr",
|
| 293 |
"output_type": "stream",
|
| 294 |
"text": [
|
| 295 |
+
"Evaluating: 50%|βββββ | 6/12 [00:36<00:27, 4.59s/it]"
|
| 296 |
]
|
| 297 |
},
|
| 298 |
{
|
| 299 |
"name": "stdout",
|
| 300 |
"output_type": "stream",
|
| 301 |
"text": [
|
| 302 |
+
"2025-11-27 02:11:54 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 303 |
+
"2025-11-27 02:11:57 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 304 |
+
"2025-11-27 02:11:59 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 305 |
+
"2025-11-27 02:12:03 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 306 |
+
"2025-11-27 02:12:04 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 307 |
+
"2025-11-27 02:12:06 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 308 |
+
"2025-11-27 02:12:08 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
|
| 309 |
+
"2025-11-27 02:12:09 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 310 |
]
|
| 311 |
},
|
| 312 |
{
|
| 313 |
"name": "stderr",
|
| 314 |
"output_type": "stream",
|
| 315 |
"text": [
|
| 316 |
+
"Evaluating: 58%|ββββββ | 7/12 [00:57<00:43, 8.69s/it]"
|
| 317 |
]
|
| 318 |
},
|
| 319 |
{
|
| 320 |
"name": "stdout",
|
| 321 |
"output_type": "stream",
|
| 322 |
"text": [
|
| 323 |
+
"2025-11-27 02:12:11 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
]
|
| 325 |
},
|
| 326 |
{
|
| 327 |
"name": "stderr",
|
| 328 |
"output_type": "stream",
|
| 329 |
"text": [
|
| 330 |
+
"Evaluating: 67%|βββββββ | 8/12 [00:58<00:27, 6.89s/it]"
|
| 331 |
]
|
| 332 |
},
|
| 333 |
{
|
| 334 |
"name": "stdout",
|
| 335 |
"output_type": "stream",
|
| 336 |
"text": [
|
| 337 |
+
"2025-11-27 02:12:14 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
|
|
|
|
|
|
| 338 |
]
|
| 339 |
},
|
| 340 |
{
|
| 341 |
"name": "stderr",
|
| 342 |
"output_type": "stream",
|
| 343 |
"text": [
|
| 344 |
+
"Evaluating: 75%|ββββββββ | 9/12 [01:01<00:17, 5.81s/it]"
|
| 345 |
]
|
| 346 |
},
|
| 347 |
{
|
| 348 |
"name": "stdout",
|
| 349 |
"output_type": "stream",
|
| 350 |
"text": [
|
| 351 |
+
"2025-11-27 02:12:37 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 352 |
]
|
| 353 |
},
|
| 354 |
{
|
| 355 |
"name": "stderr",
|
| 356 |
"output_type": "stream",
|
| 357 |
"text": [
|
| 358 |
+
"Evaluating: 83%|βββββββββ | 10/12 [01:24<00:21, 10.59s/it]"
|
| 359 |
]
|
| 360 |
},
|
| 361 |
{
|
| 362 |
"name": "stdout",
|
| 363 |
"output_type": "stream",
|
| 364 |
"text": [
|
| 365 |
+
"2025-11-27 02:12:49 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
]
|
| 367 |
},
|
| 368 |
{
|
| 369 |
"name": "stderr",
|
| 370 |
"output_type": "stream",
|
| 371 |
"text": [
|
| 372 |
+
"Evaluating: 92%|ββββββββββ| 11/12 [01:37<00:11, 11.16s/it]"
|
| 373 |
+
]
|
| 374 |
+
},
|
| 375 |
+
{
|
| 376 |
+
"name": "stdout",
|
| 377 |
+
"output_type": "stream",
|
| 378 |
+
"text": [
|
| 379 |
+
"2025-11-27 02:12:55 - HTTP Request: POST https://api.studio.nebius.ai/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
|
| 380 |
+
]
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"name": "stderr",
|
| 384 |
+
"output_type": "stream",
|
| 385 |
+
"text": [
|
| 386 |
+
"Evaluating: 100%|ββββββββββ| 12/12 [01:42<00:00, 8.57s/it]\n"
|
| 387 |
]
|
| 388 |
}
|
| 389 |
],
|
|
|
|
| 420 |
},
|
| 421 |
{
|
| 422 |
"cell_type": "code",
|
| 423 |
+
"execution_count": 8,
|
| 424 |
"id": "d8514ff3",
|
| 425 |
"metadata": {
|
| 426 |
"slideshow": {
|
|
|
|
| 443 |
"2 [The Act states that disadvantage must be subs... \n",
|
| 444 |
"\n",
|
| 445 |
" response \\\n",
|
| 446 |
+
"0 According to the context documents, the phrase... \n",
|
| 447 |
+
"1 According to the context documents, 'reasonabl... \n",
|
| 448 |
+
"2 According to the provided context documents, '... \n",
|
| 449 |
"\n",
|
| 450 |
" reference context_precision \\\n",
|
| 451 |
+
"0 The Equality and Human Rights Commission (EHRC... 0.9500 \n",
|
| 452 |
+
"1 There are two key considerations of 'reasonabl... 0.8875 \n",
|
| 453 |
+
"2 'Substantial' is defined in the Act as 'more t... 0.8875 \n",
|
| 454 |
"\n",
|
| 455 |
" context_recall faithfulness answer_relevancy \n",
|
| 456 |
+
"0 1.0 0.875000 0.736830 \n",
|
| 457 |
+
"1 1.0 0.850000 0.751613 \n",
|
| 458 |
+
"2 0.8 0.666667 0.878305 \n"
|
| 459 |
]
|
| 460 |
}
|
| 461 |
],
|
tests/test_ragas.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from datasets import Dataset
|
| 2 |
from app import retrieve_relevant_documents, emb_text, model, embedding_model
|
| 3 |
-
from
|
| 4 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 5 |
from langchain.schema.runnable import RunnableLambda
|
| 6 |
from langchain_core.documents import Document
|
|
|
|
| 1 |
from datasets import Dataset
|
| 2 |
from app import retrieve_relevant_documents, emb_text, model, embedding_model
|
| 3 |
+
from langchain_classic.chains.combine_documents import create_stuff_documents_chain
|
| 4 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 5 |
from langchain.schema.runnable import RunnableLambda
|
| 6 |
from langchain_core.documents import Document
|