step 3 add ai model and chat with your app.md

For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs; this page is available as Markdown.

Add AI Model and chat with your data

Adding a Model Provider

  1. Navigate to Code tab.
  2. In Components sidebar, click Model Providers tab, and select OpenAI.
  3. Enter the Model name.
  4. Enter the Model ID, (e.g. gpt-4o).
  5. Set the OpenAI API Key secret
    1. API keys and other secrets are securely stored and encrypted.
  6. Insert tools: auto in the params section of the gpt-4o Model to automatically connect datasets to the model.
    The final Spicepod configuration in the editor should be as follows:
name: my-first-app
kind: Spicepod
version: v1beta1

datasets:
  - from: s3://spiceai-demo-datasets/taxi_trips/2024/
    name: samples.taxi_trips
    description: Taxi trips dataset from Spice.ai demo datasets.
    params:
      file_format: parquet

models:
  - from: openai:gpt-4o
    name: gpt-4o
    params:
      endpoint: https://api.openai.com/v1
      openai_api_key: ${secrets:OPENAI_API_KEY}
      tools: auto
  1. Click Save in the code toolbar and then Deploy in the popup card that appears in the bottom right to deploy the changes.
  2. Navigate to Playground and select AI Chat in the sidebar.
  3. Ask a question about the NYC Taxi Trips dataset in the chat. For example:
    • "What datasets are available?"
    • "What is the average fare amount of a taxi trip?"

[Optional] Call chat completions API using cURL

  1. Replace [API-KEY] in the sample below with the app API Key and execute in a terminal.
curl --request POST \
      --url 'https://data.spiceai.io/v1/chat/completions' \
      --header 'Content-Type: application/json' \
      --header 'X-API-KEY: 31393037|8f2f6125e7b8487f80964041c123d3c3' \
      --data '{ "messages": [{ "role": "user", "content": "Hello!" }], "model": "gpt-4o" }'

🎉 Congratulations, you've now added an OpenAI model and can use it to ask questions of the NYC Taxi Trips dataset.

Continue to Next Steps to explore use-cases to do more with the Spice.ai Cloud Platform.

Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the ask query parameter, and the optional goal query parameter:

GET https://docs.spice.ai/getting-started/get-started/step-3-add-ai-model-and-chat-with-your-app.md?ask=<question>&goal=<endgoal>

ask is the immediate question: it should be specific, self-contained, and written in natural language. goal is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.