- Set up your project with Splunk Agent Observability
- Create a basic RAG application
- Add logging with Splunk Agent Observability
- Run your app using an experiment
Get the code
Before you start
To complete this how-to, you will need:- An OpenAI API key
- A Splunk Agent Observability project
- An LLM integration configured to calculate LLM-as-a-judge evaluators
- Your Splunk Agent Observability API key
Install dependencies
To use Splunk Agent Observability, you need to install some package dependencies, and configure environment variables.Install Required Dependencies
Create a .env file, and add the following values
Create a basic RAG application
In this section you will create a basic RAG application. This will use tool calling to call a function that simulates a RAG system by returning some pre-defined documents.Create a file called app.py (Python)
Add imports
Add a RAG function
Add a tool to get the horoscope
Add code to interact with an LLM
Add a function to generate the horoscope using the LLM and tools
Add a main function
Run your code
Add logging with Splunk Agent Observability
You now have a basic AI application with a tool that uses RAG. Let’s add logging with Splunk Agent Observability.Add imports for Splunk Agent Observability
Create a session and trace
Use the Splunk Agent Observability OpenAI wrapper to log an LLM span
Log the RAG call as a retriever span
Log the tool call as a tool span
Run your code
Run your app using an experiment
Now that your app is running, let’s create an experiment file to run the app as an experiment. In this code you’ll create a new file to run as a test, but in the real world you would probably create this as a unit test using your preferred framework of choice.Create a file called experiment.py (Python)
Add code to run the experiment
Run your code