Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 39b8a6b

Browse files
authored
Merge branch 'main' into vllm-integration-tests
2 parents 972b498 + e68580c commit 39b8a6b

File tree

7 files changed

+137
-25
lines changed

7 files changed

+137
-25
lines changed

.github/workflows/update-model-costs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Update model prices and context window JSON file
33

44
on:
55
workflow_call:
6+
workflow_dispatch:
67
schedule:
78
- cron: '0 2 * * 0' # Run every Sunday at 2:00 AM
89

api/openapi.json

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@
10091009
"content": {
10101010
"application/json": {
10111011
"schema": {
1012-
"$ref": "#/components/schemas/TokenUsage"
1012+
"$ref": "#/components/schemas/TokenUsageAggregate"
10131013
}
10141014
}
10151015
}
@@ -1233,10 +1233,10 @@
12331233
"format": "date-time",
12341234
"title": "Conversation Timestamp"
12351235
},
1236-
"token_usage": {
1236+
"token_usage_agg": {
12371237
"anyOf": [
12381238
{
1239-
"$ref": "#/components/schemas/TokenUsage"
1239+
"$ref": "#/components/schemas/TokenUsageAggregate"
12401240
},
12411241
{
12421242
"type": "null"
@@ -1251,7 +1251,7 @@
12511251
"type",
12521252
"chat_id",
12531253
"conversation_timestamp",
1254-
"token_usage"
1254+
"token_usage_agg"
12551255
],
12561256
"title": "Conversation",
12571257
"description": "Represents a conversation."
@@ -1467,7 +1467,8 @@
14671467
"anthropic",
14681468
"vllm",
14691469
"ollama",
1470-
"lm_studio"
1470+
"lm_studio",
1471+
"llamacpp"
14711472
],
14721473
"title": "ProviderType",
14731474
"description": "Represents the different types of providers we support."
@@ -1505,25 +1506,51 @@
15051506
"title": "QuestionType"
15061507
},
15071508
"TokenUsage": {
1509+
"properties": {
1510+
"input_tokens": {
1511+
"type": "integer",
1512+
"title": "Input Tokens",
1513+
"default": 0
1514+
},
1515+
"output_tokens": {
1516+
"type": "integer",
1517+
"title": "Output Tokens",
1518+
"default": 0
1519+
},
1520+
"input_cost": {
1521+
"type": "number",
1522+
"title": "Input Cost",
1523+
"default": 0
1524+
},
1525+
"output_cost": {
1526+
"type": "number",
1527+
"title": "Output Cost",
1528+
"default": 0
1529+
}
1530+
},
1531+
"type": "object",
1532+
"title": "TokenUsage",
1533+
"description": "TokenUsage it's not a table, it's a model to represent the token usage.\nThe data is stored in the outputs table."
1534+
},
1535+
"TokenUsageAggregate": {
15081536
"properties": {
15091537
"tokens_by_model": {
1510-
"items": {
1538+
"additionalProperties": {
15111539
"$ref": "#/components/schemas/TokenUsageByModel"
15121540
},
1513-
"type": "array",
1541+
"type": "object",
15141542
"title": "Tokens By Model"
15151543
},
1516-
"used_tokens": {
1517-
"type": "integer",
1518-
"title": "Used Tokens"
1544+
"token_usage": {
1545+
"$ref": "#/components/schemas/TokenUsage"
15191546
}
15201547
},
15211548
"type": "object",
15221549
"required": [
15231550
"tokens_by_model",
1524-
"used_tokens"
1551+
"token_usage"
15251552
],
1526-
"title": "TokenUsage",
1553+
"title": "TokenUsageAggregate",
15271554
"description": "Represents the tokens used. Includes the information of the tokens used by model.\n`used_tokens` are the total tokens used in the `tokens_by_model` list."
15281555
},
15291556
"TokenUsageByModel": {
@@ -1535,16 +1562,15 @@
15351562
"type": "string",
15361563
"title": "Model"
15371564
},
1538-
"used_tokens": {
1539-
"type": "integer",
1540-
"title": "Used Tokens"
1565+
"token_usage": {
1566+
"$ref": "#/components/schemas/TokenUsage"
15411567
}
15421568
},
15431569
"type": "object",
15441570
"required": [
15451571
"provider_type",
15461572
"model",
1547-
"used_tokens"
1573+
"token_usage"
15481574
],
15491575
"title": "TokenUsageByModel",
15501576
"description": "Represents the tokens used by a model."

model_cost_data/model_prices_and_context_window.json

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,6 +4608,20 @@
46084608
"litellm_provider": "replicate",
46094609
"mode": "chat"
46104610
},
4611+
"openrouter/deepseek/deepseek-r1": {
4612+
"max_tokens": 8192,
4613+
"max_input_tokens": 64000,
4614+
"max_output_tokens": 8192,
4615+
"input_cost_per_token": 0.00000055,
4616+
"input_cost_per_token_cache_hit": 0.00000014,
4617+
"output_cost_per_token": 0.00000219,
4618+
"litellm_provider": "openrouter",
4619+
"mode": "chat",
4620+
"supports_function_calling": true,
4621+
"supports_assistant_prefill": true,
4622+
"supports_tool_choice": true,
4623+
"supports_prompt_caching": true
4624+
},
46114625
"openrouter/deepseek/deepseek-chat": {
46124626
"max_tokens": 8192,
46134627
"max_input_tokens": 66000,
@@ -5210,6 +5224,24 @@
52105224
"mode": "chat",
52115225
"supports_system_messages": true
52125226
},
5227+
"ai21.jamba-1-5-large-v1:0": {
5228+
"max_tokens": 256000,
5229+
"max_input_tokens": 256000,
5230+
"max_output_tokens": 256000,
5231+
"input_cost_per_token": 0.000002,
5232+
"output_cost_per_token": 0.000008,
5233+
"litellm_provider": "bedrock",
5234+
"mode": "chat"
5235+
},
5236+
"ai21.jamba-1-5-mini-v1:0": {
5237+
"max_tokens": 256000,
5238+
"max_input_tokens": 256000,
5239+
"max_output_tokens": 256000,
5240+
"input_cost_per_token": 0.0000002,
5241+
"output_cost_per_token": 0.0000004,
5242+
"litellm_provider": "bedrock",
5243+
"mode": "chat"
5244+
},
52135245
"amazon.titan-text-lite-v1": {
52145246
"max_tokens": 4000,
52155247
"max_input_tokens": 42000,
@@ -5528,8 +5560,8 @@
55285560
"max_tokens": 8192,
55295561
"max_input_tokens": 200000,
55305562
"max_output_tokens": 8192,
5531-
"input_cost_per_token": 0.000001,
5532-
"output_cost_per_token": 0.000005,
5563+
"input_cost_per_token": 0.0000008,
5564+
"output_cost_per_token": 0.000004,
55335565
"litellm_provider": "bedrock",
55345566
"mode": "chat",
55355567
"supports_assistant_prefill": true,
@@ -5598,8 +5630,8 @@
55985630
"max_tokens": 8192,
55995631
"max_input_tokens": 200000,
56005632
"max_output_tokens": 8192,
5601-
"input_cost_per_token": 0.000001,
5602-
"output_cost_per_token": 0.000005,
5633+
"input_cost_per_token": 0.0000008,
5634+
"output_cost_per_token": 0.000004,
56035635
"litellm_provider": "bedrock",
56045636
"mode": "chat",
56055637
"supports_assistant_prefill": true,
@@ -5668,8 +5700,8 @@
56685700
"max_tokens": 8192,
56695701
"max_input_tokens": 200000,
56705702
"max_output_tokens": 8192,
5671-
"input_cost_per_token": 0.000001,
5672-
"output_cost_per_token": 0.000005,
5703+
"input_cost_per_token": 0.00000025,
5704+
"output_cost_per_token": 0.00000125,
56735705
"litellm_provider": "bedrock",
56745706
"mode": "chat",
56755707
"supports_function_calling": true,
@@ -6043,8 +6075,8 @@
60436075
"max_tokens": 8191,
60446076
"max_input_tokens": 100000,
60456077
"max_output_tokens": 8191,
6046-
"input_cost_per_token": 0.00000163,
6047-
"output_cost_per_token": 0.00000551,
6078+
"input_cost_per_token": 0.0000008,
6079+
"output_cost_per_token": 0.0000024,
60486080
"litellm_provider": "bedrock",
60496081
"mode": "chat"
60506082
},

src/codegate/api/v1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ async def add_provider_endpoint(
128128
return provend
129129

130130

131+
@v1.put(
132+
"/provider-endpoints/{provider_id}/auth-material",
133+
tags=["Providers"],
134+
generate_unique_id_function=uniq_name,
135+
status_code=204,
136+
)
137+
async def configure_auth_material(
138+
provider_id: UUID,
139+
request: v1_models.ConfigureAuthMaterial,
140+
):
141+
"""Configure auth material for a provider."""
142+
try:
143+
await pcrud.configure_auth_material(provider_id, request)
144+
except provendcrud.ProviderNotFoundError:
145+
raise HTTPException(status_code=404, detail="Provider endpoint not found")
146+
except Exception:
147+
raise HTTPException(status_code=500, detail="Internal server error")
148+
149+
return Response(status_code=204)
150+
151+
131152
@v1.put(
132153
"/provider-endpoints/{provider_id}", tags=["Providers"], generate_unique_id_function=uniq_name
133154
)

src/codegate/api/v1_models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class ProviderEndpoint(pydantic.BaseModel):
223223
description: str = ""
224224
provider_type: ProviderType
225225
endpoint: str
226-
auth_type: ProviderAuthType
226+
auth_type: Optional[ProviderAuthType] = ProviderAuthType.none
227227

228228
@staticmethod
229229
def from_db_model(db_model: db_models.ProviderEndpoint) -> "ProviderEndpoint":
@@ -250,6 +250,15 @@ def get_from_registry(self, registry: ProviderRegistry) -> Optional[BaseProvider
250250
return registry.get_provider(self.provider_type)
251251

252252

253+
class ConfigureAuthMaterial(pydantic.BaseModel):
254+
"""
255+
Represents a request to configure auth material for a provider.
256+
"""
257+
258+
auth_type: ProviderAuthType
259+
api_key: Optional[str] = None
260+
261+
253262
class ModelByProvider(pydantic.BaseModel):
254263
"""
255264
Represents a model supported by a provider.

src/codegate/db/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ async def push_provider_auth_material(self, auth_material: ProviderAuthMaterial)
441441
UPDATE provider_endpoints
442442
SET auth_type = :auth_type, auth_blob = :auth_blob
443443
WHERE id = :provider_endpoint_id
444+
RETURNING id as provider_endpoint_id, auth_type, auth_blob
444445
"""
445446
)
447+
# Here we DONT want to return the result
446448
_ = await self._execute_update_pydantic_model(auth_material, sql, should_raise=True)
447449
return
448450

src/codegate/providers/crud/crud.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@ async def update_endpoint(
8181
dbendpoint = await self._db_writer.update_provider_endpoint(endpoint.to_db_model())
8282
return apimodelsv1.ProviderEndpoint.from_db_model(dbendpoint)
8383

84+
async def configure_auth_material(
85+
self, provider_id: UUID, config: apimodelsv1.ConfigureAuthMaterial
86+
):
87+
"""Add an API key."""
88+
if config.auth_type == apimodelsv1.ProviderAuthType.api_key and not config.api_key:
89+
raise ValueError("API key must be provided for API auth type")
90+
elif config.auth_type != apimodelsv1.ProviderAuthType.api_key and config.api_key:
91+
raise ValueError("API key provided for non-API auth type")
92+
93+
dbendpoint = await self._db_reader.get_provider_endpoint_by_id(str(provider_id))
94+
if dbendpoint is None:
95+
raise ProviderNotFoundError("Provider not found")
96+
97+
await self._db_writer.push_provider_auth_material(
98+
dbmodels.ProviderAuthMaterial(
99+
provider_endpoint_id=dbendpoint.id,
100+
auth_type=config.auth_type,
101+
auth_blob=config.api_key if config.api_key else "",
102+
)
103+
)
104+
84105
async def delete_endpoint(self, provider_id: UUID):
85106
"""Delete an endpoint."""
86107

0 commit comments

Comments
 (0)