Skip to content

Commit a32b10b

Browse files
committed
Remove patches, fix bugs
1 parent 625482d commit a32b10b

File tree

13 files changed

+62
-310
lines changed

13 files changed

+62
-310
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ server = [
3232
"langchain-aimlapi==0.1.0",
3333
"langchain-cohere==0.4.6",
3434
"langchain-community==0.3.31",
35-
"langchain-fireworks==0.3.0",
35+
#"langchain-fireworks==0.3.0",
3636
"langchain-google-genai==2.1.12",
3737
"langchain-ibm==0.3.20",
3838
"langchain-mcp-adapters==0.1.13",
@@ -43,7 +43,7 @@ server = [
4343
"langchain-openai==0.3.35",
4444
"langchain-together==0.3.1",
4545
"langgraph==1.0.1",
46-
"litellm==1.80.0",
46+
"litellm==1.80.7",
4747
"llama-index==0.14.8",
4848
"lxml==6.0.2",
4949
"matplotlib==3.10.7",
@@ -70,6 +70,7 @@ test = [
7070
"pytest",
7171
"pytest-asyncio",
7272
"pytest-cov",
73+
"types-jsonschema",
7374
"yamllint"
7475
]
7576

src/common/schema.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,18 @@ class ChatRequest(LanguageModelParameters):
346346
#####################################################
347347
# Testbed
348348
#####################################################
349-
class TestSets(BaseModel):
350-
"""TestSets"""
349+
class QASets(BaseModel):
350+
"""QA Sets - Collection of Q&A test sets for testbed evaluation"""
351351

352352
tid: str = Field(description="Test ID")
353-
name: str = Field(description="Name of TestSet")
354-
created: str = Field(description="Date TestSet Loaded")
353+
name: str = Field(description="Name of QA Set")
354+
created: str = Field(description="Date QA Set Loaded")
355355

356356

357-
class TestSetQA(BaseModel):
358-
"""TestSet Q&A"""
357+
class QASetData(BaseModel):
358+
"""QA Set Data - Question/Answer pairs for testbed evaluation"""
359359

360-
qa_data: list = Field(description="TestSet Q&A Data")
360+
qa_data: list = Field(description="QA Set Data")
361361

362362

363363
class Evaluation(BaseModel):
@@ -390,6 +390,6 @@ class EvaluationReport(Evaluation):
390390
ModelEnabledType = ModelAccess.__annotations__["enabled"]
391391
OCIProfileType = OracleCloudSettings.__annotations__["auth_profile"]
392392
OCIResourceOCID = OracleResource.__annotations__["ocid"]
393-
TestSetsIdType = TestSets.__annotations__["tid"]
394-
TestSetsNameType = TestSets.__annotations__["name"]
395-
TestSetDateType = TestSets.__annotations__["created"]
393+
QASetsIdType = QASets.__annotations__["tid"]
394+
QASetsNameType = QASets.__annotations__["name"]
395+
QASetsDateType = QASets.__annotations__["created"]

src/launch_server.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
# spell-checker:ignore configfile fastmcp noauth getpid procs litellm giskard ollama
66
# spell-checker:ignore dotenv apiserver laddr
77

8-
# Patch litellm for Giskard/Ollama issue
9-
import server.patches.litellm_patch # pylint: disable=unused-import, wrong-import-order
10-
118
# Set OS Environment before importing other modules
129
# Set OS Environment (Don't move their position to reflect on imports)
1310
# pylint: disable=wrong-import-position

src/server/api/utils/databases.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ def _test(config: Database) -> None:
100100
except oracledb.DatabaseError:
101101
logger.info("Refreshing %s database connection.", config.name)
102102
_ = connect(config)
103-
except ValueError as ex:
104-
raise DbException(status_code=400, detail=f"Database: {str(ex)}") from ex
103+
except DbException:
104+
raise
105105
except PermissionError as ex:
106106
raise DbException(status_code=401, detail=f"Database: {str(ex)}") from ex
107107
except ConnectionError as ex:
108108
raise DbException(status_code=503, detail=f"Database: {str(ex)}") from ex
109+
except ValueError as ex:
110+
raise DbException(status_code=400, detail=f"Database: {str(ex)}") from ex
109111
except Exception as ex:
110112
raise DbException(status_code=500, detail=str(ex)) from ex
111113

@@ -136,7 +138,7 @@ def connect(config: Database) -> oracledb.Connection:
136138
include_fields = set(DatabaseAuth.model_fields.keys())
137139
db_authn = config.model_dump(include=include_fields)
138140
if any(not db_authn[key] for key in ("user", "password", "dsn")):
139-
raise ValueError("missing connection details")
141+
raise DbException(status_code=400, detail=f"Database: {config.name} missing connection details.")
140142

141143
logger.info("Connecting to Database: %s", config.dsn)
142144
# If a wallet password is provided but no wallet location is set
@@ -249,7 +251,7 @@ def get_databases(
249251
for db in databases:
250252
try:
251253
db_conn = connect(config=db)
252-
except (ValueError, PermissionError, ConnectionError, LookupError):
254+
except (DbException, PermissionError, ConnectionError, LookupError):
253255
continue
254256
db.vector_stores = _get_vs(db_conn)
255257
db.connected = True

src/server/api/utils/oci.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ def get_namespace(config: OracleCloudSettings) -> str:
185185
client = init_client(client_type, config)
186186
config.namespace = client.get_namespace().data
187187
logger.info("OCI: Namespace = %s", config.namespace)
188+
except OciException:
189+
# Re-raise OciException from init_client without wrapping
190+
raise
188191
except oci.exceptions.InvalidConfig as ex:
189192
raise OciException(status_code=400, detail="Invalid Config") from ex
190193
except oci.exceptions.ServiceError as ex:

src/server/api/utils/testbed.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,25 @@ def get_testsets(db_conn: Connection) -> list:
9595
sql = "SELECT tid, name, to_char(created) FROM oai_testsets ORDER BY created"
9696
results = utils_databases.execute_sql(db_conn, sql)
9797
try:
98-
testsets = [schema.TestSets(tid=tid.hex(), name=name, created=created) for tid, name, created in results]
98+
testsets = [schema.QASets(tid=tid.hex(), name=name, created=created) for tid, name, created in results]
9999
except TypeError:
100100
create_testset_objects(db_conn)
101101

102102
return testsets
103103

104104

105-
def get_testset_qa(db_conn: Connection, tid: schema.TestSetsIdType) -> schema.TestSetQA:
105+
def get_testset_qa(db_conn: Connection, tid: schema.QASetsIdType) -> schema.QASetData:
106106
"""Get list of TestSet Q&A"""
107107
logger.info("Getting TestSet Q&A for TID: %s", tid)
108108
binds = {"tid": tid}
109109
sql = "SELECT qa_data FROM oai_testset_qa where tid=:tid"
110110
results = utils_databases.execute_sql(db_conn, sql, binds)
111111
qa_data = [qa_data[0] for qa_data in results]
112112

113-
return schema.TestSetQA(qa_data=qa_data)
113+
return schema.QASetData(qa_data=qa_data)
114114

115115

116-
def get_evaluations(db_conn: Connection, tid: schema.TestSetsIdType) -> list[schema.Evaluation]:
116+
def get_evaluations(db_conn: Connection, tid: schema.QASetsIdType) -> list[schema.Evaluation]:
117117
"""Get list of Evaluations for a TID"""
118118
logger.info("Getting Evaluations for: %s", tid)
119119
evaluations = []
@@ -133,7 +133,7 @@ def get_evaluations(db_conn: Connection, tid: schema.TestSetsIdType) -> list[sch
133133

134134
def delete_qa(
135135
db_conn: Connection,
136-
tid: schema.TestSetsIdType,
136+
tid: schema.QASetsIdType,
137137
) -> None:
138138
"""Delete Q&A"""
139139
binds = {"tid": tid}
@@ -144,11 +144,11 @@ def delete_qa(
144144

145145
def upsert_qa(
146146
db_conn: Connection,
147-
name: schema.TestSetsNameType,
148-
created: schema.TestSetDateType,
147+
name: schema.QASetsNameType,
148+
created: schema.QASetsDateType,
149149
json_data: json,
150-
tid: schema.TestSetsIdType = None,
151-
) -> schema.TestSetsIdType:
150+
tid: schema.QASetsIdType = None,
151+
) -> schema.QASetsIdType:
152152
"""Upsert Q&A"""
153153
logger.info("Upsert TestSet: %s - %s", name, created)
154154
parsed_data = json.loads(json_data)
@@ -270,7 +270,7 @@ def build_knowledge_base(
270270
return testset
271271

272272

273-
def process_report(db_conn: Connection, eid: schema.TestSetsIdType) -> schema.EvaluationReport:
273+
def process_report(db_conn: Connection, eid: schema.QASetsIdType) -> schema.EvaluationReport:
274274
"""Process an evaluate report"""
275275

276276
# Main

src/server/api/v1/databases.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,25 @@ async def databases_update(
7676

7777
db.connected = False
7878
try:
79-
payload.config_dir = db.config_dir
80-
payload.wallet_location = db.wallet_location
81-
logger.debug("Testing Payload: %s", payload)
82-
db_conn = utils_databases.connect(payload)
83-
except (ValueError, PermissionError, ConnectionError, LookupError) as ex:
79+
# Create a test config with payload values to test connection
80+
# Only update the actual db object after successful connection
81+
test_config = db.model_copy(update=payload.model_dump(exclude_unset=True))
82+
logger.debug("Testing Database: %s", test_config)
83+
db_conn = utils_databases.connect(test_config)
84+
except utils_databases.DbException as ex:
85+
raise HTTPException(status_code=ex.status_code, detail=ex.detail) from ex
86+
except (PermissionError, ConnectionError, LookupError) as ex:
8487
status_code = 500
85-
if isinstance(ex, ValueError):
86-
status_code = 400
87-
elif isinstance(ex, PermissionError):
88+
if isinstance(ex, PermissionError):
8889
status_code = 401
8990
elif isinstance(ex, LookupError):
9091
status_code = 404
9192
elif isinstance(ex, ConnectionError):
9293
status_code = 503
93-
else:
94-
raise
9594
raise HTTPException(status_code=status_code, detail=f"Database: {db.name} {ex}.") from ex
96-
for key, value in payload.model_dump().items():
95+
96+
# Connection successful - now update the actual db object
97+
for key, value in payload.model_dump(exclude_unset=True).items():
9798
setattr(db, key, value)
9899

99100
# Manage Connections; Unset and disconnect other databases

src/server/api/v1/testbed.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
@auth.get(
4141
"/testsets",
4242
description="Get Stored TestSets.",
43-
response_model=list[schema.TestSets],
43+
response_model=list[schema.QASets],
4444
)
4545
async def testbed_testsets(
4646
client: schema.ClientIdType = Header(default="server"),
47-
) -> list[schema.TestSets]:
47+
) -> list[schema.QASets]:
4848
"""Get a list of stored TestSets, create TestSet objects if they don't exist"""
4949
testsets = utils_testbed.get_testsets(db_conn=utils_databases.get_client_database(client).connection)
5050
return testsets
@@ -56,7 +56,7 @@ async def testbed_testsets(
5656
response_model=list[schema.Evaluation],
5757
)
5858
async def testbed_evaluations(
59-
tid: schema.TestSetsIdType,
59+
tid: schema.QASetsIdType,
6060
client: schema.ClientIdType = Header(default="server"),
6161
) -> list[schema.Evaluation]:
6262
"""Get Evaluations"""
@@ -72,7 +72,7 @@ async def testbed_evaluations(
7272
response_model=schema.EvaluationReport,
7373
)
7474
async def testbed_evaluation(
75-
eid: schema.TestSetsIdType,
75+
eid: schema.QASetsIdType,
7676
client: schema.ClientIdType = Header(default="server"),
7777
) -> schema.EvaluationReport:
7878
"""Get Evaluations"""
@@ -84,13 +84,13 @@ async def testbed_evaluation(
8484

8585
@auth.get(
8686
"/testset_qa",
87-
description="Get Stored schema.TestSets Q&A.",
88-
response_model=schema.TestSetQA,
87+
description="Get Stored Testbed Q&A.",
88+
response_model=schema.QASetData,
8989
)
9090
async def testbed_testset_qa(
91-
tid: schema.TestSetsIdType,
91+
tid: schema.QASetsIdType,
9292
client: schema.ClientIdType = Header(default="server"),
93-
) -> schema.TestSetQA:
93+
) -> schema.QASetData:
9494
"""Get TestSet Q&A"""
9595
return utils_testbed.get_testset_qa(
9696
db_conn=utils_databases.get_client_database(client).connection, tid=tid.upper()
@@ -102,7 +102,7 @@ async def testbed_testset_qa(
102102
description="Delete a TestSet",
103103
)
104104
async def testbed_delete_testset(
105-
tid: Optional[schema.TestSetsIdType] = None,
105+
tid: Optional[schema.QASetsIdType] = None,
106106
client: schema.ClientIdType = Header(default="server"),
107107
) -> JSONResponse:
108108
"""Delete TestSet"""
@@ -113,14 +113,14 @@ async def testbed_delete_testset(
113113
@auth.post(
114114
"/testset_load",
115115
description="Upsert TestSets.",
116-
response_model=schema.TestSetQA,
116+
response_model=schema.QASetData,
117117
)
118118
async def testbed_upsert_testsets(
119119
files: list[UploadFile],
120-
name: schema.TestSetsNameType,
121-
tid: Optional[schema.TestSetsIdType] = None,
120+
name: schema.QASetsNameType,
121+
tid: Optional[schema.QASetsIdType] = None,
122122
client: schema.ClientIdType = Header(default="server"),
123-
) -> schema.TestSetQA:
123+
) -> schema.QASetData:
124124
"""Update stored TestSet data"""
125125
created = datetime.now().isoformat()
126126
db_conn = utils_databases.get_client_database(client).connection
@@ -194,16 +194,16 @@ def _handle_testset_error(ex: Exception, temp_directory, ll_model: str):
194194
@auth.post(
195195
"/testset_generate",
196196
description="Generate Q&A Test Set.",
197-
response_model=schema.TestSetQA,
197+
response_model=schema.QASetData,
198198
)
199199
async def testbed_generate_qa(
200200
files: list[UploadFile],
201-
name: schema.TestSetsNameType,
201+
name: schema.QASetsNameType,
202202
ll_model: str,
203203
embed_model: str,
204204
questions: int = 2,
205205
client: schema.ClientIdType = Header(default="server"),
206-
) -> schema.TestSetQA:
206+
) -> schema.QASetData:
207207
"""Retrieve contents from a local file uploaded and generate Q&A"""
208208
# Get the Model Configuration
209209
try:
@@ -249,7 +249,7 @@ async def _collect_testbed_answers(loaded_testset: QATestset, client: str) -> li
249249
response_model=schema.EvaluationReport,
250250
)
251251
async def testbed_evaluate(
252-
tid: schema.TestSetsIdType,
252+
tid: schema.QASetsIdType,
253253
judge: str,
254254
client: schema.ClientIdType = Header(default="server"),
255255
) -> schema.EvaluationReport:

src/server/patches/__init__.py

Whitespace-only changes.

src/server/patches/litellm_patch.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)