diff --git a/llama_stack/providers/inline/batches/reference/batches.py b/llama_stack/providers/inline/batches/reference/batches.py index e049518a4..39f45d7d1 100644 --- a/llama_stack/providers/inline/batches/reference/batches.py +++ b/llama_stack/providers/inline/batches/reference/batches.py @@ -178,9 +178,9 @@ class ReferenceBatchesImpl(Batches): # TODO: set expiration time for garbage collection - if endpoint not in ["/v1/chat/completions", "/v1/completions"]: + if endpoint not in ["/v1/chat/completions", "/v1/completions", "/v1/embeddings"]: raise ValueError( - f"Invalid endpoint: {endpoint}. Supported values: /v1/chat/completions, /v1/completions. Code: invalid_value. Param: endpoint", + f"Invalid endpoint: {endpoint}. Supported values: /v1/chat/completions, /v1/completions, /v1/embeddings. Code: invalid_value. Param: endpoint", ) if completion_window != "24h": @@ -425,18 +425,23 @@ class ReferenceBatchesImpl(Batches): valid = False if batch.endpoint == "/v1/chat/completions": - required_params = [ + required_params: list[tuple[str, Any, str]] = [ ("model", str, "a string"), # messages is specific to /v1/chat/completions # we could skip validating messages here and let inference fail. however, # that would be a very expensive way to find out messages is wrong. ("messages", list, "an array"), # TODO: allow messages to be a string? ] - else: # /v1/completions + elif batch.endpoint == "/v1/completions": required_params = [ ("model", str, "a string"), ("prompt", str, "a string"), # TODO: allow prompt to be a list of strings?? ] + else: # /v1/embeddings + required_params = [ + ("model", str, "a string"), + ("input", (str, list), "a string or array of strings"), + ] for param, expected_type, type_string in required_params: if param not in body: @@ -614,7 +619,7 @@ class ReferenceBatchesImpl(Batches): "body": chat_response.model_dump_json(), }, } - else: # /v1/completions + elif request.url == "/v1/completions": completion_response = await self.inference_api.openai_completion(**request.body) # this is for mypy, we don't allow streaming so we'll get the right type @@ -630,6 +635,20 @@ class ReferenceBatchesImpl(Batches): "body": completion_response.model_dump_json(), }, } + else: # /v1/embeddings + embeddings_response = await self.inference_api.openai_embeddings(**request.body) + assert hasattr(embeddings_response, "model_dump_json"), ( + "Embeddings response must have model_dump_json method" + ) + return { + "id": request_id, + "custom_id": request.custom_id, + "response": { + "status_code": 200, + "request_id": request_id, # TODO: should this be different? + "body": embeddings_response.model_dump_json(), + }, + } except Exception as e: logger.info(f"Error processing request {request.custom_id} in batch {batch_id}: {e}") return { diff --git a/tests/integration/batches/recordings/1d782697e7261920e2c21babd28d5126609fdc27c61a1d793792e713a48f6368.json b/tests/integration/batches/recordings/1d782697e7261920e2c21babd28d5126609fdc27c61a1d793792e713a48f6368.json new file mode 100644 index 000000000..c96b0bde8 --- /dev/null +++ b/tests/integration/batches/recordings/1d782697e7261920e2c21babd28d5126609fdc27c61a1d793792e713a48f6368.json @@ -0,0 +1,1206 @@ +{ + "test_id": "tests/integration/batches/test_batches.py::TestBatchesIntegration::test_batch_e2e_embeddings[emb=ollama/all-minilm:l6-v2]", + "request": { + "method": "POST", + "url": "http://0.0.0.0:11434/v1/v1/embeddings", + "headers": {}, + "body": { + "model": "all-minilm:l6-v2", + "input": [ + "How are you?", + "Good morning", + "Have a great day" + ], + "encoding_format": "float" + }, + "endpoint": "/v1/embeddings", + "model": "all-minilm:l6-v2" + }, + "response": { + "body": { + "__type__": "openai.types.create_embedding_response.CreateEmbeddingResponse", + "__data__": { + "data": [ + { + "embedding": [ + 0.0069620265, + 0.01094919, + 0.08730505, + 0.08677503, + 0.026604276, + -0.067699, + 0.072650306, + -0.025137117, + -0.08260308, + 0.016288513, + -0.0059634144, + 0.021893453, + -0.014844859, + 0.026276434, + 0.043832693, + -0.052769832, + 0.058766205, + -0.12824233, + -0.09479588, + 0.039485294, + -0.11324302, + 0.038061623, + 0.029431377, + 0.11588057, + -0.026578259, + -0.004148723, + -0.042966843, + -0.007125199, + 0.021863377, + -0.066874556, + -0.12788324, + 0.04219816, + -0.08644679, + -0.03378584, + -0.0387981, + -0.012082744, + -0.01377726, + -0.109074354, + -0.015455687, + 0.00926984, + 0.031882305, + -0.030273998, + -0.018641746, + -0.031002996, + 0.07745517, + -0.03599416, + 0.016853025, + 0.04181667, + 0.09213733, + 0.025376223, + -0.096536845, + -0.03958827, + -0.04546788, + 0.022860946, + -0.004847932, + -0.007844372, + -0.04907143, + 0.05842486, + 0.058869448, + -0.0311611, + 0.052651893, + 0.0058047865, + -0.07925791, + 0.034241866, + 0.061405163, + 0.01727779, + -0.037056115, + -0.0431168, + -0.03700382, + -0.014409387, + -0.0349633, + -0.07832774, + 0.06407517, + 0.041914545, + 0.015118112, + -0.07118399, + 0.060636368, + -0.07046343, + 0.095750414, + 0.05210073, + 0.035014015, + 0.02561262, + -0.0084085055, + 0.024139598, + -0.1008911, + -0.050012913, + 0.06554008, + 0.06784252, + 0.014911199, + 0.021127723, + -0.016916825, + 0.05327187, + 0.060536385, + 0.004947355, + 0.044616435, + 0.01850348, + 0.07844247, + 0.01610686, + -0.07016926, + 0.17061207, + 0.009558954, + 0.07672501, + 0.03883033, + -0.039801788, + -0.015828522, + -0.018782567, + -0.05314649, + 0.06397424, + -0.0017792752, + -0.065490805, + -0.018281994, + -0.014554831, + -0.0068800277, + 0.059996247, + 0.026568834, + 0.033968493, + 0.054951597, + 0.078294225, + 0.04026787, + 0.027457401, + 0.011338397, + 0.013631172, + -0.0028005866, + 0.02906015, + -0.022045234, + 0.04519289, + 0.023878276, + -4.0817583e-33, + 0.11951192, + -0.08369012, + 0.0827968, + 0.08484549, + -0.01620364, + 0.01931262, + 0.022204285, + -0.027940609, + 0.057476316, + 0.034429334, + 0.09182369, + 0.0101823555, + -0.029327707, + -0.026887769, + 0.028785188, + -0.04777552, + -0.060430776, + 0.041163843, + 0.008629699, + 0.115784265, + -0.021419767, + -0.07631758, + -0.054899275, + 0.04849591, + 0.01820428, + -0.02857143, + -0.051891994, + -0.066517085, + -0.029432349, + -0.018801715, + -0.057336025, + 0.050356966, + 0.062174562, + -0.043937422, + 0.04709282, + 0.03493125, + -0.02043357, + -0.011575923, + -0.0011123308, + 0.037825495, + 0.02184749, + -0.01826203, + 0.040588006, + -0.056284837, + -0.035502367, + -0.04816801, + -0.028440557, + 0.030739177, + -0.087275244, + -0.0694685, + -0.020636193, + 0.0057930094, + -0.06391942, + 0.012107013, + -0.04009067, + -0.021143993, + 0.004213952, + 0.008591898, + -0.024006026, + 0.0324714, + 0.03783457, + 0.09099059, + -0.0062868916, + -0.088974684, + -0.14320053, + -0.009016283, + -0.045446053, + -0.0003069883, + 0.06741114, + -0.1530436, + -0.002174887, + 0.0029532255, + -0.0046353145, + 0.057488102, + 0.012418762, + 0.018427594, + -0.06905235, + -0.053686094, + -0.046660636, + -0.07989403, + 0.010693424, + 0.08947703, + -0.027004695, + -0.021568634, + -0.040594254, + -0.031580914, + -0.013580625, + -0.051635634, + 0.037055064, + 0.08082445, + -0.0048920843, + 0.018148402, + 0.025499638, + -0.02505582, + -0.09722802, + 1.3371345e-33, + 0.052455395, + -0.021139719, + -0.05505728, + 0.03206651, + -0.066784665, + -0.055702224, + -0.014446009, + 0.08516562, + 0.03471153, + 0.024656896, + 0.06533943, + 0.018156208, + 0.034035064, + 0.037902445, + -0.00023498005, + -0.025868421, + 0.08381628, + -0.027879614, + 0.0032222737, + 0.02324647, + -0.07133222, + 0.09625788, + -0.045015045, + 0.06659545, + -0.026130881, + 0.008532056, + -0.00045929194, + 0.017110055, + -0.06073309, + -0.032286026, + 0.0014934636, + -0.034322187, + -0.083728336, + 0.06859927, + 0.038369313, + 0.07010073, + 0.0033788162, + -0.0128664365, + -0.07913289, + -0.04725289, + -0.039385278, + 0.023481516, + -0.029086247, + 0.067320675, + 0.12451372, + -0.028017303, + 0.036124624, + 0.013133795, + 0.008215629, + 0.059157945, + 0.0030263092, + -0.012367379, + -0.034128156, + 0.03490755, + 0.047604892, + 0.008263147, + 0.0022418934, + -0.04281037, + 0.007698608, + -0.012741323, + 0.006137873, + 0.019026898, + -0.027803786, + -0.018056031, + 0.06762252, + 0.02744791, + -0.0352131, + -0.044931725, + -0.07372794, + 0.02997626, + -0.07610888, + 0.019982826, + 0.07436165, + -0.07193991, + 0.025494274, + 0.03235363, + 0.031534728, + 0.022636676, + -0.0055851312, + -0.0398378, + -0.06981347, + 0.02221736, + 0.09897387, + -0.09406188, + -0.09095904, + -0.094901204, + 0.011805468, + 0.0006828259, + 0.06842204, + 0.011328019, + -0.009800073, + 0.02732526, + 0.042588975, + -0.0049699764, + 0.0069869496, + -1.6672951e-08, + 0.006400124, + -0.008909364, + 0.006461362, + 0.082072794, + 0.026836326, + 0.039794065, + -0.022391766, + -0.007853053, + -0.036337033, + -0.04923066, + 0.03148229, + -0.026368985, + -0.09314845, + -0.08545302, + 0.034173954, + -0.028906666, + 0.077192605, + 0.06751202, + -0.06524724, + -0.048700843, + 0.039455824, + -0.006923446, + -0.0025343136, + 0.051478203, + -0.034010187, + 0.028947832, + 0.029549884, + 0.06183748, + 0.025608867, + 0.11934708, + 0.10484976, + 0.08736667, + -0.010165297, + -0.009555697, + -0.019218681, + -0.018595073, + 0.037189815, + 0.020784399, + 0.02202641, + 0.060297336, + -0.05238963, + 0.0077030538, + -0.019185953, + -0.003553766, + 0.020160092, + -0.055704053, + 0.096336596, + -0.039617542, + -0.008140912, + 0.006712462, + -0.07394944, + 0.024357047, + 0.07899572, + 0.043920882, + 0.0071198526, + 0.035673812, + 0.019155473, + 0.048716854, + -0.03848996, + 0.0188379, + 0.022161776, + -0.051058814, + -0.074823424, + -0.015351548 + ], + "index": 0, + "object": "embedding" + }, + { + "embedding": [ + -0.03343721, + 0.049560912, + 0.047050487, + 0.043978658, + 0.035338175, + -0.011890714, + 0.04245718, + 0.031470045, + 0.04293622, + -0.044294365, + -0.06597325, + 0.032940995, + -0.0247847, + 0.056306385, + -0.019261496, + 0.077105775, + 0.0033309048, + -0.14142057, + -0.04281739, + 0.093726546, + -0.067536496, + 0.013504435, + 0.065051645, + 0.053081397, + -0.071122356, + 0.003918916, + 0.10802933, + 0.032548733, + 0.040249683, + -0.118329026, + -0.06955132, + 0.10413009, + -0.03137577, + -0.0287358, + 0.07667822, + 0.008311209, + 0.01329846, + -0.095602185, + 0.027722612, + -0.021009775, + 0.07278631, + -0.022486797, + -0.01850939, + 0.054257147, + 0.0406722, + 0.032246407, + 0.022768732, + 0.038984485, + 0.11382912, + 0.04124995, + -0.05496885, + -0.045736212, + -0.04908839, + -0.0597111, + 0.042826593, + 0.05140804, + -0.012110607, + -0.018417751, + 0.08427118, + -0.0055473596, + 0.015597289, + 0.02418129, + -0.031249756, + 0.020387262, + 0.11433708, + -0.051274013, + -0.0386925, + 0.016713846, + -0.08449619, + 0.0370792, + -0.005756356, + -0.004907058, + 0.027494607, + -0.03673422, + -0.008244491, + 0.040472392, + -0.009735739, + 0.0011943391, + 0.1142877, + -0.008102284, + -0.050180648, + -0.0053849323, + -0.039576985, + 0.029380586, + -0.024390329, + 0.04567972, + -0.0053372276, + 0.03033303, + 0.0012185968, + -0.021535054, + -0.05335558, + 0.037134368, + 0.017302368, + -0.02755907, + 0.04263198, + 0.030098636, + -0.033609867, + -0.037845384, + -0.061982516, + 0.1910882, + 0.07157646, + 0.05589665, + -0.042736474, + 0.032838497, + 0.0062692524, + -0.04605748, + -0.056851376, + 0.052537017, + -0.10145497, + -0.06655004, + 0.029921545, + -0.0047280397, + 0.024377555, + -0.025002962, + 0.062107224, + 0.080466576, + -0.0371604, + 0.097599484, + -0.032131996, + 0.035730097, + -0.016809976, + -0.036352117, + 0.031635497, + -0.012653352, + -0.045253426, + -0.0029212183, + 0.027009405, + -1.17418e-33, + 0.123992205, + 0.046342608, + 0.008559601, + 0.08004046, + 0.0017669292, + -0.007195786, + 0.04694784, + -0.027429387, + -0.021160621, + -0.015509837, + 0.033601534, + 0.07583885, + -0.05792184, + -0.012479701, + -0.021399997, + 0.059393596, + -0.033957504, + 0.073253185, + 0.01896546, + 0.00988916, + -0.02561772, + 0.037233494, + 0.05378261, + 0.08345076, + 0.030937353, + -0.047004256, + -0.034895707, + -0.102880456, + -0.014390994, + 0.0020541775, + 0.04525708, + -0.024543207, + 0.034396984, + 0.044495404, + 0.022777205, + -0.032906257, + 0.005113007, + -0.02360279, + -0.09544966, + 0.015483764, + -0.0070620324, + 0.028951883, + 0.040911917, + -0.0518465, + -0.030150011, + -0.026980001, + -0.024943676, + 0.031786792, + -0.027682098, + -0.057204265, + 0.012249942, + 0.014380534, + -0.11575076, + -0.032365136, + -0.06845665, + -0.021849087, + -0.04244301, + 0.062867135, + 0.046220545, + 0.0779571, + -0.010332656, + 0.06670813, + 0.026566902, + -0.08693371, + -0.10670888, + -0.062272597, + 0.020204814, + -0.049648978, + 0.060845267, + -0.053523622, + 0.04117337, + -0.039594717, + 0.06601946, + 0.06250075, + 0.004595632, + 0.0086026, + 0.0018772809, + 0.00048405523, + 0.009107358, + -0.026627311, + 0.07465299, + 0.017612034, + 0.058446344, + -0.05802014, + 0.03860909, + 0.050386902, + 0.048826773, + -0.01052452, + 0.0009781453, + -0.013527019, + -0.06439363, + 0.034368027, + 0.07011869, + 0.03524254, + -0.0837487, + 2.3193607e-33, + 0.09110093, + 0.023464995, + -0.17480665, + 0.046113294, + -0.040365938, + -0.024011146, + 0.056435388, + 0.016907558, + -0.12567072, + 0.031960107, + -0.0062446273, + -0.061454426, + 0.065167435, + 0.005247117, + 0.074547134, + -0.0567087, + 0.10225782, + 0.046171524, + -0.051690318, + 0.038285308, + -0.1145762, + 0.012512791, + -0.011550446, + 0.024934134, + -0.048639935, + 0.051862657, + 0.00930002, + 0.06747382, + -0.052439213, + -0.041193396, + 0.040648684, + 0.026968153, + -0.06418471, + 0.00762661, + 0.036696862, + 0.073210746, + 0.028952941, + -0.035378844, + 0.010157242, + -0.048371132, + 0.014746441, + 0.05206198, + -0.049247157, + 0.08650532, + 0.025151266, + -0.07410052, + -0.0077393763, + 0.072591476, + -0.0033177028, + 0.03872032, + -0.015706064, + -0.021085871, + -0.00062487193, + -0.0027980541, + -0.033041626, + -0.0828747, + 0.020620363, + -0.059320856, + 0.05761976, + 0.039191, + -0.10919506, + 0.04973389, + 0.018328683, + 0.014107853, + 0.040713586, + 0.015339457, + -0.073242456, + 0.012108583, + 0.0093227625, + -0.032315496, + -0.026866596, + -0.05125451, + 0.024359334, + -0.011217118, + 0.047117867, + 0.00033466535, + 0.010994259, + -0.060987946, + -0.030848341, + -0.02774884, + -0.050323945, + 0.01780588, + 0.038884122, + 0.0029080173, + -0.050115652, + -0.12608153, + 0.09675133, + 0.023315206, + 0.033652537, + -0.046950553, + -0.020049583, + 0.0145577025, + -0.08507165, + -0.020159263, + 0.0048846807, + -1.4254338e-08, + -0.030829625, + -0.022226596, + 0.014015447, + 0.045818005, + -0.00466287, + 0.010646387, + -0.04074163, + -0.017911622, + -0.015333984, + 0.036582693, + 0.05822764, + 0.09292506, + -0.061256517, + -0.01890862, + 0.011198966, + -0.026512727, + 0.007474336, + 0.032824352, + -0.033287942, + -0.026444035, + -0.024530197, + 0.044718876, + 0.045766443, + 0.00498525, + 0.0858161, + 0.0005709976, + -0.09247468, + 0.0851635, + 0.032044463, + 0.054132145, + 0.009075579, + 0.11062079, + -0.10246274, + -0.027978186, + -0.037963714, + -0.009799522, + 0.07379462, + 0.07328145, + 0.017107535, + -0.06596038, + -0.03074957, + -0.06867525, + 0.009267378, + -0.08653143, + -0.050690625, + -0.03302789, + 0.008441075, + -0.042419374, + -0.05931559, + 0.0038107636, + -0.008925102, + -0.082826234, + 0.012707635, + 0.028753227, + 0.005821868, + -0.016774626, + 0.026027977, + -0.015453672, + -0.044195093, + -0.023212919, + 0.034165725, + 0.052767526, + 0.049792286, + 0.04779771 + ], + "index": 1, + "object": "embedding" + }, + { + "embedding": [ + -0.075523525, + 0.02527682, + 0.05967143, + -0.048702575, + -0.009999652, + -0.0127215395, + 0.077593714, + 0.03435327, + 0.012108688, + -0.029198525, + 0.08872028, + 0.083752885, + 0.009050396, + 0.006103784, + -0.033944063, + 0.0008475549, + -0.07999163, + -0.047501646, + -0.07466069, + 0.013129963, + -0.016166262, + -0.012555349, + 0.009951952, + 0.018700073, + -0.16587994, + 0.035660297, + 0.020247744, + -0.004851298, + 0.018916108, + -0.049223512, + -0.14940114, + 0.066037394, + 0.095587395, + -0.023433829, + 0.056383938, + -0.0002691792, + 0.003867362, + -0.08172911, + 0.07046757, + -0.018454568, + 0.0015881791, + -0.010290314, + 0.048989784, + 0.01762784, + 0.06936314, + 0.019082017, + 0.014352334, + -0.0015133243, + 0.056041166, + -0.004062598, + -0.088092774, + -0.0101555, + -0.07189387, + -0.00014898201, + 0.027720913, + 0.12817302, + -0.01666869, + -0.032651726, + 0.06956124, + -0.010005866, + 0.048692912, + 0.051343545, + 0.049818557, + 0.027778273, + 0.07503881, + -0.10384942, + -0.052882396, + 0.04831974, + -0.13253361, + 0.04823366, + -0.06355945, + -0.007815479, + 0.08426803, + 0.06839248, + -0.00089115696, + 0.0550307, + -0.03483323, + 0.044897463, + 0.05632448, + 0.040626705, + -0.018259693, + -0.017169427, + 0.023355052, + 0.0010599073, + -0.083920546, + -0.014824099, + 0.0019810472, + -0.008914795, + 0.05216931, + -0.013007552, + -0.06241765, + 0.088266425, + -0.020624625, + -0.010565186, + 0.03387624, + -0.032896634, + 0.027584162, + 0.06140176, + -0.05649953, + 0.13169001, + 0.03580055, + 0.034740195, + 0.00025404096, + -0.019271977, + 0.043521438, + -0.026385438, + -0.10464285, + 0.03479913, + -0.09097619, + -0.07121069, + 0.017202636, + 0.05367353, + 0.06784611, + 0.11754365, + 0.012266213, + 0.024174396, + -0.038576283, + 0.07442647, + -0.015460215, + -0.027320355, + 0.0053612017, + -0.07064376, + 0.043387093, + 0.06510215, + 0.067798555, + -0.025894808, + 0.032071106, + -3.916482e-33, + 0.04579921, + 0.12266688, + 0.023788335, + 0.09849639, + 0.009824968, + 0.05850631, + -0.06363229, + 0.013609335, + -0.021318363, + -0.005576027, + -0.050703783, + -0.030871525, + -0.038143754, + 0.006320834, + -0.017706675, + -0.0006155015, + -0.018226627, + 0.1072818, + 0.052017488, + -0.00057930633, + -0.007785786, + -0.03997464, + -0.007232867, + 0.059632022, + -0.006354158, + -0.023469966, + 0.021212451, + -0.08246642, + 0.019579455, + 0.007551619, + -0.10099897, + -0.06797174, + -0.010882899, + 0.06988909, + -0.02137188, + -0.07802906, + -0.088137604, + -0.006203687, + -0.035839535, + -0.0040390054, + 0.019918816, + -0.010801633, + -0.08162814, + -0.0032512245, + -0.040600386, + -0.08192742, + 0.0682926, + 0.06633641, + -0.0395632, + -0.0043761632, + -0.07984402, + -0.035650294, + -0.06232168, + -0.0242656, + -0.059556987, + -0.022764271, + -0.053822305, + 0.12793463, + 0.052975636, + 0.043549713, + 0.050708994, + 0.08166038, + -0.08327403, + -0.080381505, + -0.04120254, + -0.0030282405, + 0.047887556, + 0.0016836514, + -0.04663993, + 0.055887047, + 0.053726807, + -0.013926298, + 0.09405359, + -0.062233135, + 0.024512352, + 0.008496787, + 0.061213776, + 0.029902814, + 0.04837825, + 0.014272488, + 0.0072977017, + 0.0079299165, + 0.042296894, + -0.04521794, + 0.046605933, + 0.00024299505, + 0.022693006, + -0.010438793, + 0.08995921, + -0.015472325, + -0.126904, + 0.039331693, + 0.039659232, + -0.050487302, + -0.061920997, + 4.4642215e-33, + 0.10129766, + 0.027161466, + -0.059524115, + 0.07136239, + -0.013943489, + -0.03662881, + -0.052398663, + 0.021515815, + -0.049108166, + 0.006149372, + 0.0691721, + 0.06894283, + -0.037195116, + 0.005472846, + 0.07448842, + -0.049621485, + 0.05460389, + 0.013648674, + -0.10413393, + -0.04322616, + -0.10156234, + 0.026639054, + -0.024765702, + -0.03026698, + 0.0043362495, + 0.063877925, + 0.007930457, + 0.05244102, + -0.04413401, + -0.037697483, + -0.014808346, + 0.04740107, + -0.12069513, + 0.021242734, + 0.005062712, + 0.02754677, + 0.089413024, + -0.017842088, + -0.044801895, + 0.022731086, + -0.012965577, + 0.004509326, + -0.0013325807, + 0.04949399, + -0.009911497, + -0.011362206, + 0.054088496, + -0.027890686, + 0.07090775, + 0.0731208, + -0.0095167635, + 0.00246136, + -0.04014402, + 0.0013154474, + -0.0073115155, + -0.04271233, + -0.046457898, + -0.07000201, + -0.009631684, + 0.01803729, + -0.08605493, + -0.08164771, + -0.03272842, + 0.0011325047, + 0.08289893, + -0.030911505, + -0.024537822, + 0.055442885, + -0.040067412, + 0.013888838, + -0.07284885, + 0.0023484977, + -0.057206854, + 0.022467189, + -0.023729995, + 0.034355275, + -0.018349517, + -0.029528793, + -0.021843866, + 0.008032472, + -0.023357753, + 0.067088224, + 0.005294365, + -0.024430374, + -0.019369498, + -0.109176144, + -0.01490418, + 0.042795096, + -0.012001356, + 0.037037082, + -0.0672771, + 0.03180879, + 0.04468346, + 0.015854714, + 0.0032342928, + -1.6160763e-08, + 0.013496305, + 0.09897777, + -0.031063609, + 0.0028211512, + 0.032273874, + 0.023351071, + 0.03805213, + -0.062018104, + -0.034577433, + 0.043238945, + 0.0082845185, + 0.025489045, + -0.04456483, + 0.025501892, + 0.08934958, + 0.01234487, + -0.02929869, + -0.005623999, + 0.00687474, + 0.015289362, + -0.010576751, + -0.020772502, + 0.04376376, + 0.099957116, + 0.04056933, + 0.018252485, + -0.0063662603, + 0.08044274, + -0.007315223, + 0.010589869, + -0.018971821, + 0.10834696, + -0.04208067, + -0.051403604, + -0.007071271, + -0.06431493, + 0.053990707, + 0.00036957764, + 0.12660533, + -0.034871798, + -0.013751049, + 0.003618815, + 0.0409129, + 0.00097652036, + -0.030046517, + -0.046951715, + -0.000683113, + -0.0034426234, + -0.055673465, + -0.011067276, + 0.03669483, + 0.028998604, + 0.079799, + 0.061878074, + -0.048468277, + -0.0022916084, + -0.017985595, + 0.06437586, + -0.017347652, + 0.022508401, + 0.05077104, + 0.032550838, + -0.04261378, + 0.041284833 + ], + "index": 2, + "object": "embedding" + } + ], + "model": "all-minilm:l6-v2", + "object": "list", + "usage": { + "prompt_tokens": 10, + "total_tokens": 10 + } + } + }, + "is_streaming": false + }, + "id_normalization_mapping": {} +} diff --git a/tests/integration/batches/recordings/37b8d062efc39eaa4ac3438f5102044a29fd1e9b844ead2f066a1fb25c85672c.json b/tests/integration/batches/recordings/37b8d062efc39eaa4ac3438f5102044a29fd1e9b844ead2f066a1fb25c85672c.json new file mode 100644 index 000000000..4487ba042 --- /dev/null +++ b/tests/integration/batches/recordings/37b8d062efc39eaa4ac3438f5102044a29fd1e9b844ead2f066a1fb25c85672c.json @@ -0,0 +1,422 @@ +{ + "test_id": "tests/integration/batches/test_batches.py::TestBatchesIntegration::test_batch_e2e_embeddings[emb=ollama/all-minilm:l6-v2]", + "request": { + "method": "POST", + "url": "http://0.0.0.0:11434/v1/v1/embeddings", + "headers": {}, + "body": { + "model": "all-minilm:l6-v2", + "input": "Hello world", + "encoding_format": "float" + }, + "endpoint": "/v1/embeddings", + "model": "all-minilm:l6-v2" + }, + "response": { + "body": { + "__type__": "openai.types.create_embedding_response.CreateEmbeddingResponse", + "__data__": { + "data": [ + { + "embedding": [ + -0.034477483, + 0.030899182, + 0.0066526434, + 0.026075281, + -0.039411988, + -0.16037956, + 0.06692074, + -0.006511468, + -0.047467157, + 0.014774274, + 0.07094562, + 0.055527706, + 0.019183245, + -0.026297163, + -0.010018651, + -0.02694715, + 0.0223884, + -0.02220693, + -0.14977267, + -0.017530814, + 0.0075938613, + 0.054253556, + 0.0032258728, + 0.031724673, + -0.08466085, + -0.029342307, + 0.05155048, + 0.048105717, + -0.0032670307, + -0.05822795, + 0.041971523, + 0.022229431, + 0.1281518, + -0.022270948, + -0.011725874, + 0.06294936, + -0.032847952, + -0.09124354, + -0.031128692, + 0.05274829, + 0.047067728, + -0.08414196, + -0.029979317, + -0.020692566, + 0.00949804, + -0.0035992558, + 0.0074442336, + 0.03928378, + 0.09326073, + -0.0037437282, + -0.052663893, + -0.058101393, + -0.006925679, + 0.0052269334, + 0.08290669, + 0.019312402, + 0.0062818974, + -0.010331665, + 0.008930684, + -0.037712026, + -0.045175705, + 0.023950849, + -0.006926045, + 0.013429504, + 0.100098, + -0.0715888, + -0.021700105, + 0.031693522, + -0.05161389, + -0.08224763, + -0.06577986, + -0.009853981, + 0.005808086, + 0.07364217, + -0.034008067, + 0.024907362, + 0.014441484, + 0.02645124, + 0.009659713, + 0.030284341, + 0.052878983, + -0.07536944, + 0.009890014, + 0.029907802, + 0.017498897, + 0.02313779, + 0.0018918256, + 0.0013156217, + -0.047173936, + -0.011251131, + -0.11422648, + -0.019960148, + 0.040278148, + 0.0022633963, + -0.07986738, + -0.025357265, + 0.094500035, + -0.029062947, + -0.14495483, + 0.2309815, + 0.027703581, + 0.03208736, + 0.031073036, + 0.042917974, + 0.064246915, + 0.032118786, + -0.004844535, + 0.055775862, + -0.03756279, + -0.021487191, + -0.028432492, + -0.028887685, + 0.03842892, + -0.017359573, + 0.052465834, + -0.07493626, + -0.031175744, + 0.021936033, + -0.039823197, + -0.008681939, + 0.026978256, + -0.048551314, + 0.011414809, + 0.029628372, + -0.020587107, + 0.013077965, + 0.028824588, + -3.1978743e-33, + 0.06475607, + -0.018065408, + 0.05190019, + 0.12193858, + 0.028755108, + 0.008794777, + -0.07044016, + -0.016856866, + 0.040675826, + 0.04222898, + 0.025450956, + 0.035772353, + -0.049134083, + 0.0021395232, + -0.015527445, + 0.05065655, + -0.04814189, + 0.03586998, + -0.004134139, + 0.10165314, + -0.055980552, + -0.010677752, + 0.011231545, + 0.09068785, + 0.004311188, + 0.035094332, + -0.009658399, + -0.09383056, + 0.092755266, + 0.00799794, + -0.0077075018, + -0.052119244, + -0.01259255, + 0.0032277475, + 0.005989667, + 0.0075889886, + 0.010571857, + -0.08629758, + -0.06985891, + -0.002511263, + -0.091053724, + 0.0468712, + 0.05203361, + 0.0072902967, + 0.010906411, + -0.0052922186, + 0.013883815, + 0.021929385, + 0.0341257, + 0.060227357, + 0.00018942523, + 0.0146624865, + -0.07000342, + 0.028425341, + -0.027542787, + 0.01082086, + 0.03491755, + -0.022430921, + 0.0096813915, + 0.07725412, + 0.021618832, + 0.114911504, + -0.06805403, + 0.023872944, + -0.015999107, + -0.017794114, + 0.06442477, + 0.03206309, + 0.050293576, + -0.005988605, + -0.03376946, + 0.017821673, + 0.016567992, + 0.063335925, + 0.034753703, + 0.046586752, + 0.09789875, + -0.006560692, + 0.025039855, + -0.07780643, + 0.016878096, + -0.0010056288, + 0.02257608, + -0.0382721, + 0.09572481, + -0.005296001, + 0.010567662, + -0.11538674, + -0.013233586, + -0.010786205, + -0.083147496, + 0.073254965, + 0.049377624, + -0.009025328, + -0.0957893, + 3.3687185e-33, + 0.12494067, + 0.019226579, + -0.058172084, + -0.035952393, + -0.050862074, + -0.045700952, + -0.0826631, + 0.14819908, + -0.088347495, + 0.060315337, + 0.05109269, + 0.010308115, + 0.1411753, + 0.030833788, + 0.06101746, + -0.052806143, + 0.13661332, + 0.00917483, + -0.017295862, + -0.0128495265, + -0.007851698, + -0.051084496, + -0.05235087, + 0.0076632234, + -0.015217299, + 0.017015414, + 0.021324545, + 0.020506723, + -0.12004153, + 0.014523494, + 0.026743378, + 0.025221687, + -0.04270567, + 0.00676352, + -0.014453511, + 0.045142446, + -0.091383636, + -0.019459482, + -0.017806036, + -0.055010412, + -0.05270923, + -0.010370778, + -0.052053526, + 0.020918628, + -0.080037735, + -0.012147244, + -0.057777684, + 0.023249507, + -0.007838778, + -0.025807643, + -0.07987164, + -0.020683115, + 0.04888083, + -0.020459235, + -0.049192864, + 0.01407799, + -0.063744746, + -0.0077936463, + 0.016429903, + -0.025707569, + 0.013326097, + 0.026210392, + 0.009855086, + 0.06317218, + 0.0026150644, + -0.0065879063, + 0.0166049, + 0.032400407, + 0.038005095, + -0.036269873, + -0.0069020875, + 0.00019545198, + -0.0017537851, + -0.027427403, + -0.02801922, + 0.049696837, + -0.028842367, + -0.0023814398, + 0.01481421, + 0.00976869, + 0.0057697925, + 0.01341087, + 0.00551593, + 0.037237898, + 0.007291808, + 0.040068958, + 0.08141818, + 0.07197348, + -0.013163506, + -0.042782705, + -0.010938265, + 0.0049547236, + -0.00923014, + 0.035068717, + -0.051007, + -1.5708556e-08, + -0.088558294, + 0.02391312, + -0.016132735, + 0.03169382, + 0.027184812, + 0.052484553, + -0.047118798, + -0.058789898, + -0.063239954, + 0.040775288, + 0.049807984, + 0.106462926, + -0.07448737, + -0.012401869, + 0.018361589, + 0.039486438, + -0.024830224, + 0.014500051, + -0.03712332, + 0.020043189, + 8.399218e-05, + 0.009852795, + 0.024823224, + -0.05252818, + 0.02932855, + -0.0871494, + -0.01447227, + 0.025996566, + -0.018731978, + -0.07618361, + 0.03505914, + 0.10363578, + -0.0280213, + 0.012769872, + -0.076482065, + -0.018743375, + 0.024961015, + 0.08152011, + 0.06866303, + -0.06411612, + -0.08387694, + 0.061479986, + -0.03345598, + -0.10615398, + -0.040166635, + 0.032536518, + 0.076652974, + -0.07297006, + 0.00039833272, + -0.0409393, + -0.07580284, + 0.027465926, + 0.07468789, + 0.017779494, + 0.09106629, + 0.11033428, + 0.00065298256, + 0.051472265, + -0.01461242, + 0.033237122, + 0.023671487, + -0.022980422, + 0.038988944, + 0.030206418 + ], + "index": 0, + "object": "embedding" + } + ], + "model": "all-minilm:l6-v2", + "object": "list", + "usage": { + "prompt_tokens": 2, + "total_tokens": 2 + } + } + }, + "is_streaming": false + }, + "id_normalization_mapping": {} +} diff --git a/tests/integration/batches/test_batches.py b/tests/integration/batches/test_batches.py index d55a68bd3..2ff838bdd 100644 --- a/tests/integration/batches/test_batches.py +++ b/tests/integration/batches/test_batches.py @@ -323,3 +323,92 @@ class TestBatchesIntegration: if final_batch.error_file_id is not None: deleted_error_file = openai_client.files.delete(final_batch.error_file_id) assert deleted_error_file.deleted + + def test_batch_e2e_embeddings(self, openai_client, batch_helper, embedding_model_id): + """Run an end-to-end batch with embeddings requests including both string and list inputs.""" + batch_requests = [ + { + "custom_id": "success-1", + "method": "POST", + "url": "/v1/embeddings", + "body": {"model": embedding_model_id, "input": "Hello world", "encoding_format": "float"}, + }, + { + "custom_id": "success-2", + "method": "POST", + "url": "/v1/embeddings", + "body": { + "model": embedding_model_id, + "input": ["How are you?", "Good morning", "Have a great day"], + "encoding_format": "float", + }, + }, + ] + + with batch_helper.create_file(batch_requests) as uploaded_file: + batch = openai_client.batches.create( + input_file_id=uploaded_file.id, + endpoint="/v1/embeddings", + completion_window="24h", + metadata={"test": "e2e_embeddings_success"}, + ) + + final_batch = batch_helper.wait_for( + batch.id, + max_wait_time=3 * 60, + expected_statuses={"completed"}, + timeout_action="skip", + ) + + assert final_batch.status == "completed" + assert final_batch.request_counts is not None + assert final_batch.request_counts.total == 2 + assert final_batch.request_counts.completed == 2 + assert final_batch.output_file_id is not None + + output_content = openai_client.files.content(final_batch.output_file_id) + if isinstance(output_content, str): + output_text = output_content + else: + output_text = output_content.content.decode("utf-8") + + output_lines = output_text.strip().split("\n") + assert len(output_lines) == 2 + + # Check first result (string input) + result1 = json.loads(output_lines[0]) + assert result1["custom_id"] in ["success-1", "success-2"] + assert "response" in result1 + assert result1["response"]["status_code"] == 200 + + # Verify the response body contains embeddings data + response_body1 = json.loads(result1["response"]["body"]) + assert response_body1["object"] == "list" + assert "data" in response_body1 + assert len(response_body1["data"]) == 1 + assert "embedding" in response_body1["data"][0] + assert "index" in response_body1["data"][0] + assert response_body1["data"][0]["index"] == 0 + + # Check second result (list input) + result2 = json.loads(output_lines[1]) + assert result2["custom_id"] in ["success-1", "success-2"] + assert "response" in result2 + assert result2["response"]["status_code"] == 200 + + # Verify the response body contains embeddings data for list input + response_body2 = json.loads(result2["response"]["body"]) + assert response_body2["object"] == "list" + assert "data" in response_body2 + assert len(response_body2["data"]) == 3 # Three strings in the list + for i, embedding_data in enumerate(response_body2["data"]): + assert "embedding" in embedding_data + assert "index" in embedding_data + assert embedding_data["index"] == i + + deleted_output_file = openai_client.files.delete(final_batch.output_file_id) + assert deleted_output_file.deleted + + if final_batch.error_file_id is not None: + deleted_error_file = openai_client.files.delete(final_batch.error_file_id) + assert deleted_error_file.deleted diff --git a/tests/integration/common/recordings/02c93bb3c314427bae2b7a7a6f054792b9f22d2cb4522eab802810be8672d3dc.json b/tests/integration/common/recordings/02c93bb3c314427bae2b7a7a6f054792b9f22d2cb4522eab802810be8672d3dc.json index c7f787675..2b2afeee4 100644 --- a/tests/integration/common/recordings/02c93bb3c314427bae2b7a7a6f054792b9f22d2cb4522eab802810be8672d3dc.json +++ b/tests/integration/common/recordings/02c93bb3c314427bae2b7a7a6f054792b9f22d2cb4522eab802810be8672d3dc.json @@ -12,28 +12,10 @@ "body": { "__type__": "ollama._types.ProcessResponse", "__data__": { - "models": [ - { - "model": "llama3.2-vision:11b", - "name": "llama3.2-vision:11b", - "digest": "6f2f9757ae97e8a3f8ea33d6adb2b11d93d9a35bef277cd2c0b1b5af8e8d0b1e", - "expires_at": "2025-10-08T12:40:47.430429-07:00", - "size": 11765236384, - "size_vram": 11765236384, - "details": { - "parent_model": "", - "format": "gguf", - "family": "mllama", - "families": [ - "mllama" - ], - "parameter_size": "10.7B", - "quantization_level": "Q4_K_M" - } - } - ] + "models": [] } }, "is_streaming": false - } + }, + "id_normalization_mapping": {} } diff --git a/tests/integration/common/recordings/models-64a2277c90f0f42576f60c1030e3a020403d34a95f56931b792d5939f4cebc57-e660ee4a.json b/tests/integration/common/recordings/models-64a2277c90f0f42576f60c1030e3a020403d34a95f56931b792d5939f4cebc57-e660ee4a.json index cd856545f..1cb9f4b22 100644 --- a/tests/integration/common/recordings/models-64a2277c90f0f42576f60c1030e3a020403d34a95f56931b792d5939f4cebc57-e660ee4a.json +++ b/tests/integration/common/recordings/models-64a2277c90f0f42576f60c1030e3a020403d34a95f56931b792d5939f4cebc57-e660ee4a.json @@ -93,5 +93,6 @@ } ], "is_streaming": false - } + }, + "id_normalization_mapping": {} } diff --git a/tests/unit/providers/batches/test_reference.py b/tests/unit/providers/batches/test_reference.py index dfef5e040..89cb1af9d 100644 --- a/tests/unit/providers/batches/test_reference.py +++ b/tests/unit/providers/batches/test_reference.py @@ -213,7 +213,6 @@ class TestReferenceBatchesImpl: @pytest.mark.parametrize( "endpoint", [ - "/v1/embeddings", "/v1/invalid/endpoint", "", ], @@ -765,3 +764,12 @@ class TestReferenceBatchesImpl: await asyncio.sleep(0.042) # let tasks start assert active_batches == 2, f"Expected 2 active batches, got {active_batches}" + + async def test_create_batch_embeddings_endpoint(self, provider): + """Test that batch creation succeeds with embeddings endpoint.""" + batch = await provider.create_batch( + input_file_id="file_123", + endpoint="/v1/embeddings", + completion_window="24h", + ) + assert batch.endpoint == "/v1/embeddings"