What are the steps to query the databricks-dbrx-instruct model using the OpenAI client in a Databricks workspace?
1. Set up a Databricks workspace in a supported region for Foundation Model APIs pay-per-token.
2. Obtain a Databricks personal access token to query and access Databricks model serving endpoints using the OpenAI client.
3. Install the OpenAI client in your Databricks workspace.
4. Use the OpenAI client to query the databricks-dbrx-instruct model by populating the model field with the name of the model serving endpoint.
5. Use your personal access token to populate the DATABRICKS_TOKEN and your Databricks workspace instance to connect the OpenAI client to Databricks.
6. Run the query to get the response from the databricks-dbrx-instruct model.

Here is an example code snippet to query the databricks-dbrx-instruct model using the OpenAI client:

from openai import OpenAI import os DATABRICKS_TOKEN = os.environ.get("DATABRICKS_TOKEN") client = OpenAI( api_key=DATABRICKS_TOKEN, base_url='https://<workspace_id>.databricks.com/serving-endpoints', ) chat_completion = client.chat.completions.create( messages=[ { "role": "system", "content": "You are an AI assistant", }, { "role": "user", "content": "What is a mixture of experts model?", } ], model="databricks-dbrx-instruct", max_tokens=256 ) print(chat_completion.choices[0].message.content)