Querying the Foundation Model API with the OpenAI Python SDK

Querying the Foundation Model API with the OpenAI Python SDK#

The Databricks Foundation Model API is partially compatible with the OpenAI API, making it easy to switch from the OpenAI to the Databricks Foundation Model API without significant code changes. All we need to do is change a couple of environment variables:

  • we change OPENAI_BASE_URL to <databricks_workspace_url>/serving-endpoints

  • we change OPENAI_API_KEY to a Databricks PAT.

After defining these variables, you can use the OpenAI Python client to call on models accessible via the Databricks Foundation Model API.

While we generally recommend using the Foundation Model API Python SDK, using the OpenAI client provides a simple way to test open source foundation models in existing codebases that currently use OpenAI models via the OpenAI Python client. You can switch to the Foundation Model API with just a few small code changes.

%pip install --upgrade openai databricks-genai-inference
dbutils.library.restartPython()

Configure the OpenAI client#

As mentioned above, to use the foundation model API with the OpenAI Python Client, we have to change the OPENAI_BASE_URL and OPENAI_API_KEY environment variables.

from openai import OpenAI
import os

os.environ["OPENAI_BASE_URL"] = (
    "https://" + spark.conf.get("spark.databricks.workspaceUrl") + "/serving-endpoints/"
)

os.environ["OPENAI_API_KEY"] = (
    dbutils.notebook.entry_point.getDbutils()
    .notebook()
    .getContext()
    .apiToken()
    .getOrElse(None)
)

client = OpenAI()

Chat Completions with DBRX#

With these changes made, we can specify supported Foundation Model API models and call on them with the OpenAI client. Here, for example, we generate a chat completion with the databricks-dbrx-instruct model.

chat_completion = client.chat.completions.create(
    model="databricks-dbrx-instruct",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant",
        },
        {
            "role": "user",
            "content": "What is the relationship between Delta Lake and Parquet?",
        },
    ],
)

print(chat_completion.choices[0].message.content)
1. Delta Lake is an open-source storage layer that brings ACID transactions to Apache Spark and big data workloads. It provides schema enforcement, scalable metadata handling, and unifies streaming and batch data processing. Delta Lake is built on top of Apache Parquet, a columnar storage file format.

2. Parquet is a columnar storage file format that is optimized for use with big data processing frameworks like Apache Spark and Apache Hive. It is designed to handle complex data processing tasks and perform well with large datasets.

3. Delta Lake uses the Parquet file format to store data, taking advantage of its columnar storage and performance optimizations. Delta Lake builds on top of Parquet by adding features such as ACID transactions, scalable metadata handling, and unified batch and streaming processing.

4. Delta Lake can be thought of as an extension to Parquet that adds transactional capabilities and other features that are useful for managing large datasets in a distributed environment.

5. Delta Lake also uses Parquet's columnar storage format to provide performance optimizations, such as predicate pushdown and column pruning. These optimizations allow queries to skip over irrelevant data and only read the columns that are needed, resulting in faster query times.

In summary, Delta Lake is a storage layer that uses the Parquet file format to store data, while adding transactional capabilities and other features to make it easier to manage large datasets in a distributed environment.

Embeddings#

In this example, we embed the input text using the databricks-bge-large-en model.

client.embeddings.create(
    input="Your text string goes here", model="databricks-bge-large-en"
)
CreateEmbeddingResponse(data=[Embedding(embedding=[0.0018854141235351562, -0.005176544189453125, 0.0297088623046875, 0.0225982666015625, -0.006092071533203125, -0.04730224609375, 0.0394287109375, 0.0119476318359375, 0.045257568359375, 0.0215606689453125, -0.003971099853515625, 0.0191192626953125, -0.0080413818359375, -0.00624847412109375, -0.01488494873046875, -0.03778076171875, 0.0153350830078125, -0.0209503173828125, -0.056610107421875, 0.014892578125, -0.046051025390625, 0.0170135498046875, -0.1043701171875, -0.01270294189453125, -0.024322509765625, 0.0065155029296875, 0.022003173828125, -0.00426483154296875, 0.040252685546875, 0.0408935546875, -0.02923583984375, 0.046661376953125, 0.01485443115234375, -0.0196380615234375, -0.010833740234375, -0.010833740234375, 0.031402587890625, 0.0009326934814453125, -0.050537109375, -0.01299285888671875, -0.01013946533203125, -0.0038661956787109375, -0.0121612548828125, -0.01015472412109375, -0.049072265625, -0.0206298828125, -0.006557464599609375, 0.0214080810546875, 0.0162811279296875, -0.007343292236328125, 0.0038967132568359375, 0.007568359375, 0.0386962890625, 0.02691650390625, -0.006526947021484375, -0.0036716461181640625, -0.03533935546875, -0.00482940673828125, -0.03643798828125, 0.0095367431640625, 0.005207061767578125, 0.0576171875, 0.0105743408203125, -0.01377105712890625, 0.02349853515625, 0.00751495361328125, 0.0009450912475585938, -0.003376007080078125, 0.040802001953125, -0.00836181640625, -0.01305389404296875, 0.0266265869140625, 0.0137176513671875, -0.0199737548828125, -0.0235748291015625, 0.0260162353515625, -0.022369384765625, 0.015625, 0.01142120361328125, 0.05279541015625, -0.0413818359375, 0.056915283203125, 0.023040771484375, 0.031585693359375, -0.054656982421875, -0.037384033203125, 0.01219940185546875, 0.01727294921875, 0.00911712646484375, -0.005306243896484375, -0.00370025634765625, 0.037445068359375, -0.0246429443359375, 0.0063018798828125, 0.0182647705078125, 0.0572509765625, -0.0303192138671875, 0.002651214599609375, -0.006534576416015625, 0.00928497314453125, 0.029205322265625, 0.0027217864990234375, -0.03448486328125, 0.031036376953125, -0.006870269775390625, 0.0171356201171875, 0.0259552001953125, -0.0278778076171875, -0.0484619140625, -0.039581298828125, -0.0190887451171875, 0.012237548828125, 0.034942626953125, 0.004055023193359375, -0.010772705078125, 0.0347900390625, 0.01458740234375, 0.0279388427734375, -0.0284881591796875, -0.021209716796875, 0.041839599609375, -0.0190582275390625, 0.0028095245361328125, -0.0286712646484375, -0.0150299072265625, 0.005344390869140625, 0.004512786865234375, 0.037933349609375, -0.008331298828125, 0.01340484619140625, -0.001316070556640625, -0.029022216796875, 0.059356689453125, 0.020355224609375, -0.004062652587890625, 0.0274810791015625, -0.020477294921875, 0.0309600830078125, 0.0263519287109375, -0.0284423828125, 0.0224456787109375, -0.0067291259765625, -0.014495849609375, 0.06414794921875, 0.008544921875, 0.0113677978515625, 0.003170013427734375, 0.0028781890869140625, -0.048797607421875, 0.07208251953125, -0.0193634033203125, 0.0266265869140625, 0.0203399658203125, 0.0401611328125, -0.044036865234375, 0.0131683349609375, 0.0322265625, -0.0204315185546875, 0.00949859619140625, 0.04754638671875, -0.0103759765625, 0.015777587890625, -0.0250701904296875, -0.011260986328125, -0.016326904296875, 0.02520751953125, -0.01560211181640625, 0.0209197998046875, -0.0233306884765625, -0.0028476715087890625, -0.0181121826171875, -0.0138092041015625, 0.0232086181640625, 0.00672149658203125, 0.0408935546875, 0.043060302734375, 0.00777435302734375, 0.00650787353515625, 0.051055908203125, 0.014404296875, -0.061492919921875, 0.0303955078125, 0.01134490966796875, 0.01406097412109375, -0.007747650146484375, 0.00447845458984375, 0.017059326171875, 0.011322021484375, -0.060760498046875, -0.005802154541015625, 0.030029296875, 0.020782470703125, -0.048614501953125, 0.0189208984375, 0.002277374267578125, 0.01314544677734375, -0.0257110595703125, -0.0010366439819335938, -0.061920166015625, -0.041717529296875, -0.04638671875, -0.0276641845703125, 0.021087646484375, 0.0001220703125, -0.0372314453125, -0.041351318359375, 0.020263671875, 0.054656982421875, -0.0223846435546875, 0.013580322265625, 0.008544921875, -0.034149169921875, -0.044342041015625, 0.009552001953125, -0.00655364990234375, -0.022979736328125, -0.045684814453125, 0.044830322265625, 0.003025054931640625, 0.01227569580078125, -0.0299224853515625, 0.046844482421875, 0.0149383544921875, 0.035003662109375, -0.0025882720947265625, -1.0848045349121094e-05, 0.01395416259765625, 0.0130157470703125, -0.02655029296875, 0.0078125, 0.037200927734375, 0.016143798828125, 0.017242431640625, 0.0421142578125, -0.0221710205078125, 0.06988525390625, 0.0625, 0.031585693359375, -0.0026683807373046875, -0.023162841796875, -0.0161285400390625, 0.038482666015625, 0.026763916015625, 0.010345458984375, -0.020050048828125, 0.00893402099609375, 0.024749755859375, 0.004245758056640625, -0.0177154541015625, 0.0167236328125, -0.01544189453125, 0.03662109375, 0.03839111328125, 0.00817108154296875, -0.037506103515625, -0.040802001953125, 0.043975830078125, 0.038848876953125, -0.0692138671875, -0.036224365234375, 0.053802490234375, 0.046173095703125, -0.00504302978515625, 0.03399658203125, 0.01226806640625, -0.0214691162109375, 0.0286712646484375, -0.0082855224609375, -0.01299285888671875, -0.02740478515625, 0.0052947998046875, -0.0312042236328125, -0.049224853515625, 0.007415771484375, -0.0518798828125, -0.017120361328125, 0.041107177734375, -0.0259246826171875, 0.009246826171875, -0.0207977294921875, 0.0209808349609375, -0.07208251953125, -0.033477783203125, 0.03466796875, 0.01058197021484375, -0.013580322265625, -0.007778167724609375, -0.0070037841796875, -0.0210113525390625, 0.0241851806640625, -0.0447998046875, -0.0015211105346679688, 0.0215606689453125, -0.003086090087890625, -0.012481689453125, -0.002460479736328125, -0.01444244384765625, -0.01995849609375, -0.037811279296875, -0.0477294921875, 0.0009975433349609375, -0.01226043701171875, 0.0018682479858398438, -0.031707763671875, -0.00910186767578125, 0.00704193115234375, 0.052276611328125, -0.050384521484375, 0.02825927734375, 0.054107666015625, -0.0010585784912109375, 0.05731201171875, 0.033599853515625, -0.003780364990234375, -0.04766845703125, 0.02978515625, 0.022857666015625, 0.019561767578125, -0.0428466796875, -0.0240020751953125, -0.0216522216796875, 0.028564453125, -0.003963470458984375, -0.0096588134765625, -0.00905609130859375, 0.04193115234375, -0.007720947265625, -0.09356689453125, 0.0487060546875, -0.02423095703125, -0.0172882080078125, -0.0469970703125, 0.005550384521484375, 0.025848388671875, -0.0011653900146484375, 0.0229644775390625, -0.026458740234375, -0.00749969482421875, 0.034332275390625, -0.0024547576904296875, 0.059539794921875, -0.02886962890625, 0.00368499755859375, 0.034088134765625, -0.0145263671875, -0.0087890625, -0.0028324127197265625, -0.0222625732421875, -0.0068359375, -0.0011892318725585938, -0.01971435546875, 0.006923675537109375, 0.0205535888671875, 0.020965576171875, 0.0034942626953125, 0.0174713134765625, -0.00890350341796875, 0.0220947265625, 0.03460693359375, 0.0250091552734375, 0.034515380859375, 0.07489013671875, 0.00995635986328125, -0.036346435546875, -0.00984954833984375, -0.07684326171875, 0.01387786865234375, 0.0116424560546875, 0.023590087890625, -0.038787841796875, 0.056549072265625, -0.0147247314453125, -0.0230255126953125, 0.0214385986328125, -0.027587890625, -0.029876708984375, 0.036346435546875, -0.03631591796875, 0.027587890625, -2.4080276489257812e-05, 0.0047149658203125, 0.005741119384765625, -0.0012226104736328125, 0.0711669921875, 0.051788330078125, 0.06787109375, 0.0016736984252929688, 0.01800537109375, -0.0167388916015625, -0.00794219970703125, -0.0294952392578125, 0.018768310546875, 0.01192474365234375, -0.04058837890625, -0.02337646484375, -0.07159423828125, 0.035369873046875, 0.01336669921875, 0.016448974609375, 0.038177490234375, 0.014495849609375, -0.0007033348083496094, 0.0303802490234375, 0.0248870849609375, -0.0318603515625, 0.01050567626953125, -0.0246124267578125, 0.0130157470703125, 0.028778076171875, 0.0211029052734375, -0.021240234375, -0.0131683349609375, -0.03997802734375, 0.04498291015625, 0.01348114013671875, -0.0184326171875, -0.00917816162109375, -0.01529693603515625, 0.028564453125, 0.03582763671875, -0.026031494140625, -0.0029430389404296875, -0.0262298583984375, -0.01483917236328125, 0.049041748046875, -0.0224761962890625, -0.01415252685546875, -0.0080718994140625, 0.0197296142578125, 0.053009033203125, 0.004947662353515625, -0.049407958984375, -0.0264892578125, -0.017425537109375, -0.057891845703125, 0.035858154296875, 0.0217132568359375, -0.0195465087890625, 0.0438232421875, -0.06707763671875, 0.0218658447265625, 0.0212249755859375, 0.006011962890625, 0.006557464599609375, -0.0025463104248046875, -0.0236053466796875, 0.0162506103515625, 0.018768310546875, -0.050811767578125, -0.057525634765625, 0.031280517578125, -0.0736083984375, 0.0081787109375, -0.0206451416015625, 0.0189208984375, 0.0308837890625, -0.00890350341796875, 0.034210205078125, 0.0439453125, -0.020294189453125, 0.020843505859375, -0.0232391357421875, 0.01139068603515625, -0.01184844970703125, -0.040313720703125, 0.0504150390625, 0.01161956787109375, -0.0175933837890625, 0.0244140625, -0.00615692138671875, -0.0281524658203125, 0.0134124755859375, 0.0146942138671875, 0.0291290283203125, -0.015625, -0.0533447265625, 0.016998291015625, -0.038848876953125, -0.034576416015625, -0.02642822265625, -0.017730712890625, 0.018768310546875, -0.0487060546875, -0.06585693359375, -0.001323699951171875, -0.06329345703125, -0.005764007568359375, 0.0032196044921875, 0.0005431175231933594, -0.0022792816162109375, -0.021209716796875, -0.0019435882568359375, -0.0090789794921875, -0.0565185546875, 0.0233612060546875, 0.0203094482421875, -0.0008263587951660156, 0.014892578125, -0.0203857421875, 0.00809478759765625, 0.02691650390625, 0.0109405517578125, -0.07794189453125, 0.024505615234375, 0.026947021484375, 0.00501251220703125, -0.030029296875, -0.001529693603515625, -0.0268402099609375, -0.0206298828125, 0.01395416259765625, 0.01415252685546875, -0.0291748046875, 0.02496337890625, 0.0384521484375, 0.009002685546875, 0.00714111328125, 0.001728057861328125, -0.02740478515625, 0.01143646240234375, -0.0028514862060546875, -0.014495849609375, -0.01406097412109375, 0.0275421142578125, 0.01018524169921875, 0.0075531005859375, 0.031036376953125, -0.0023403167724609375, -0.032073974609375, -0.04071044921875, 0.01560211181640625, -0.005161285400390625, -0.01248931884765625, -0.0535888671875, -0.0071563720703125, -0.041229248046875, 0.01122283935546875, 0.0041961669921875, -0.059112548828125, -0.019378662109375, -0.0012693405151367188, 0.03424072265625, -0.054595947265625, 0.006526947021484375, -0.03009033203125, -0.01016998291015625, -0.021881103515625, 0.08563232421875, -0.019683837890625, 0.039886474609375, 0.016204833984375, -0.0037097930908203125, 0.01568603515625, 0.04510498046875, -0.05078125, -0.004650115966796875, 0.0182037353515625, -0.0105438232421875, 0.0006151199340820312, 0.0198516845703125, 0.004703521728515625, 0.03631591796875, -0.04144287109375, -0.001575469970703125, -0.0072174072265625, 0.002643585205078125, -0.0137786865234375, 0.011474609375, 0.00856781005859375, -0.0292816162109375, -0.040802001953125, -0.0391845703125, 0.08343505859375, -0.00353240966796875, 0.0051116943359375, -0.03082275390625, -0.045074462890625, -0.0281982421875, -0.0164337158203125, -0.004421234130859375, -0.04736328125, -0.0185089111328125, -0.0249176025390625, 0.01528167724609375, 0.036865234375, -0.04766845703125, 0.0384521484375, 0.08697509765625, 0.0258941650390625, 0.0254364013671875, -0.05889892578125, 0.04449462890625, 0.000667572021484375, -0.0556640625, -0.00481414794921875, 0.009063720703125, -0.03857421875, -0.020172119140625, 0.00536346435546875, -0.0265350341796875, -0.0631103515625, -0.005794525146484375, 0.07196044921875, 0.017303466796875, 0.045745849609375, 0.0236968994140625, -0.0579833984375, -0.0292816162109375, 0.0234832763671875, 0.020843505859375, -0.02288818359375, 0.045928955078125, 0.0274505615234375, 0.017303466796875, 0.00814056396484375, -0.04254150390625, -0.0010051727294921875, 0.01071929931640625, 0.052978515625, 0.0186614990234375, -0.0027751922607421875, 0.040130615234375, 0.035369873046875, -0.042724609375, -0.0193939208984375, -0.00634765625, -0.013885498046875, -0.03521728515625, -0.01396942138671875, -0.0151214599609375, -0.02447509765625, -0.0295257568359375, 0.0005884170532226562, 0.012420654296875, -0.011566162109375, 0.0440673828125, -0.02691650390625, -0.002696990966796875, -0.01177978515625, -0.0007600784301757812, 0.0243682861328125, 0.007038116455078125, 0.032928466796875, -0.04425048828125, 0.015777587890625, -0.03900146484375, 0.00511932373046875, 0.02593994140625, 0.03424072265625, -0.0029735565185546875, 0.03314208984375, 0.00829315185546875, 0.0400390625, 0.014434814453125, -0.0220794677734375, 0.0148162841796875, -0.0299224853515625, -0.0537109375, 0.01275634765625, 0.0256500244140625, 0.0096435546875, 0.0191192626953125, -0.02227783203125, 0.0164947509765625, -0.0089263916015625, 0.031402587890625, -0.016937255859375, -0.07952880859375, 0.0025501251220703125, -0.058563232421875, -0.03546142578125, -0.00519561767578125, -0.03704833984375, -0.002994537353515625, 0.0362548828125, -0.0177154541015625, -0.0401611328125, -0.036224365234375, 0.050018310546875, -0.003833770751953125, 0.0028476715087890625, 0.008270263671875, 0.035888671875, -0.00749969482421875, -0.04119873046875, -0.0164794921875, -0.00347900390625, 0.00798797607421875, -0.042236328125, -0.033111572265625, -0.00850677490234375, -0.0264434814453125, 0.020782470703125, 0.0187530517578125, 0.0248870849609375, -0.0203094482421875, 0.0063629150390625, 0.0211334228515625, -0.0004241466522216797, 0.018951416015625, 0.007568359375, 0.047698974609375, -0.00970458984375, -0.0146331787109375, -0.01922607421875, 0.019561767578125, -0.02337646484375, 0.04119873046875, -0.01207733154296875, -0.0025310516357421875, 0.0201416015625, -0.0190582275390625, -0.007904052734375, -0.04266357421875, -0.03271484375, -0.031280517578125, -0.003696441650390625, -0.01508331298828125, 0.0015697479248046875, 0.03253173828125, 0.0208282470703125, -0.0025177001953125, -0.0218658447265625, -0.031890869140625, 0.021697998046875, 0.05096435546875, 0.00376129150390625, 0.020721435546875, -0.0106658935546875, 0.04107666015625, -9.834766387939453e-05, -0.0225372314453125, 0.0078887939453125, -0.0155487060546875, 0.0182647705078125, -0.022308349609375, -0.0382080078125, -0.0445556640625, 0.0081634521484375, -0.0002593994140625, 0.0236053466796875, 0.0201416015625, -0.0438232421875, -0.0188751220703125, -0.0103302001953125, -0.006160736083984375, 0.04052734375, -0.0482177734375, -0.053955078125, 0.056884765625, -0.0058441162109375, 0.00028133392333984375, 0.005725860595703125, -0.039398193359375, 0.002910614013671875, -0.045745849609375, 0.004688262939453125, -0.02618408203125, 0.00353240966796875, 0.03216552734375, 0.0213623046875, -0.04937744140625, 0.0206298828125, -0.0090179443359375, 0.0208740234375, -0.061004638671875, -0.0185394287109375, -0.0082244873046875, -0.010528564453125, 0.0231781005859375, -0.0166168212890625, 0.00475311279296875, 0.006824493408203125, -0.029266357421875, 0.0268707275390625, 0.038055419921875, 0.036285400390625, -0.0498046875, -0.00302886962890625, -0.0301666259765625, 0.0186614990234375, -0.056976318359375, 0.0218048095703125, -0.0016241073608398438, 0.0159759521484375, 0.03875732421875, 0.051055908203125, 0.04669189453125, 0.0022602081298828125, 0.0190582275390625, -0.002300262451171875, 0.0167999267578125, 0.005405426025390625, -0.04095458984375, -0.00689697265625, 0.01250457763671875, 0.0816650390625, 0.02679443359375, -0.0249176025390625, 0.05078125, 0.0012187957763671875, -0.00376129150390625, -0.00421905517578125, 0.0253143310546875, 0.0089874267578125, 0.015411376953125, 0.0019397735595703125, -0.04150390625, -0.04339599609375, -0.007076263427734375, -0.035858154296875, 0.0014829635620117188, -0.03704833984375, -0.010955810546875, -0.06463623046875, -0.0308837890625, 0.03692626953125, 0.01506805419921875, 0.023345947265625, 0.0012960433959960938, -0.0413818359375, -0.032745361328125, 0.047393798828125, -0.00905609130859375, 0.014617919921875, 0.023651123046875, 0.0218353271484375, 0.032928466796875, 0.017333984375, 0.01406097412109375, 0.049407958984375, -0.035125732421875, -0.02471923828125, -0.0212860107421875, -0.0008521080017089844, -0.0028476715087890625, 0.001087188720703125, -0.062225341796875, 0.035491943359375, 0.03948974609375, 0.00867462158203125, 0.033966064453125, -0.01349639892578125, -0.0099639892578125, -0.03564453125, -0.00385284423828125, -0.021270751953125, 0.0078125, 0.07159423828125, -0.03009033203125, -0.0211181640625, 0.0458984375, -0.0034942626953125, 0.06268310546875, -0.040496826171875, 0.041595458984375, -0.006832122802734375, 0.029205322265625, 0.03411865234375, -0.047210693359375, -0.011566162109375, 0.015716552734375, 0.01171112060546875, -0.01108551025390625, 0.0017976760864257812, -0.023040771484375, -0.04083251953125, -0.040283203125, -0.00795745849609375, -0.047576904296875, 0.06036376953125, -0.02435302734375, -0.0445556640625, 0.0028324127197265625, 0.0073089599609375, -0.04644775390625, 0.05059814453125, 0.037322998046875, -0.0116424560546875, -0.01325225830078125, -0.042510986328125, -0.02783203125, 0.0235595703125, 0.01128387451171875, -0.034637451171875, -0.0121002197265625, -0.048919677734375, -0.022064208984375, -0.0029315948486328125, -0.0322265625, -0.0225372314453125, -0.01148223876953125, 0.0155181884765625, -0.057403564453125, 0.00508880615234375, 0.02197265625, -0.0008978843688964844, 3.516674041748047e-05, 0.0096435546875, 0.028167724609375, 0.01849365234375, 0.06005859375, 0.00417327880859375, 0.106689453125, 0.003017425537109375, -0.018524169921875, -0.0004439353942871094, -0.0340576171875, 0.041595458984375, 0.0128631591796875, -0.0063018798828125, -0.0222930908203125, 0.0284576416015625, -0.021728515625, -0.0264129638671875, -0.00754547119140625, 0.052947998046875, 0.004375457763671875, 0.01435089111328125, -0.0533447265625, 0.0013036727905273438, -0.0228271484375, -0.01123809814453125, -0.034332275390625, 0.044952392578125, -0.0271453857421875, 0.004085540771484375, 0.03375244140625, -0.080322265625, 0.2010498046875, 0.0198211669921875, 0.036529541015625, 0.018646240234375, 0.004383087158203125, 0.04364013671875, 0.0262603759765625, 0.00061798095703125, -0.04986572265625, -0.053070068359375, 0.043426513671875, -0.007640838623046875, 0.00551605224609375, 0.058685302734375, 0.01250457763671875, 0.03277587890625, -0.048797607421875, -0.013671875, 0.00580596923828125, -0.0201873779296875, -0.0521240234375, 0.03924560546875, 0.034027099609375, 0.055511474609375, 0.0191192626953125, -0.005611419677734375, 0.0180511474609375, -0.0357666015625, -0.033721923828125, -0.06512451171875, 0.08404541015625, -0.021453857421875, 0.0537109375, -0.004863739013671875, -0.057037353515625, 0.00833892822265625, 0.017486572265625, -0.0364990234375, -0.01181793212890625, 0.001049041748046875, -0.019256591796875, -0.048614501953125, 0.016693115234375, -0.01181793212890625, -0.0080718994140625, -0.0330810546875, -0.02227783203125, 0.053802490234375, 0.0017671585083007812, -0.0506591796875, 0.042449951171875, -0.0210723876953125, 0.048187255859375, -0.07861328125, -0.07177734375, 0.015899658203125, 0.021240234375, -0.0211334228515625, -0.02362060546875, 0.004764556884765625, 0.00807952880859375, 0.03692626953125, -0.0382080078125, -0.00829315185546875, -0.06121826171875, 0.017333984375, -0.0021457672119140625, 0.0560302734375, 0.0004360675811767578, -0.00746917724609375, -0.07525634765625, -0.01702880859375, -0.0009465217590332031, -0.059906005859375, 0.01934814453125, 0.045318603515625, -0.0243988037109375, 0.0321044921875, 0.0236663818359375, 0.0110321044921875, 0.0192718505859375, -0.021942138671875, 0.005924224853515625, 0.0087738037109375, 0.004077911376953125, 0.0919189453125, -0.0226287841796875, -0.0222015380859375, -0.036590576171875, 0.04022216796875, 0.04925537109375, 0.029876708984375, -0.00736236572265625, 0.004199981689453125, -0.02197265625], index=0, object='embedding')], model='bge-large-en-v1.5', object='list', usage=Usage(prompt_tokens=7, total_tokens=7), id='e32b6f6b-8baf-4de3-8e38-d97e3f29834a')

Completions#

In this example, we generate a text completion with the databricks-mpt-30b-instruct model.

client.completions.create(
    model="databricks-mpt-30b-instruct",
    prompt="Delta Lake offers ACID transactions. ACID means ",
)
Completion(id='d69e7502-ef5d-4aab-98eb-b4e34e3929ad', choices=[CompletionChoice(finish_reason='stop', index=0, logprobs=None, text='Atomicity, Consistency, Isolation, Durability')], created=None, model='mpt-30b-instruct', object='text_completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=13, prompt_tokens=38, total_tokens=51))

Conclusion#

You now know how to generate Databricks Foundation Model API completions using the OpenAI Python Client. This provides a straightforward way to test whether you can replace OpenAI models with Open Source models from the Databricks Foundation Model API in your Generative AI projects.