A Trace comprises a series of events executed within an LLM chain(workflow). Tracing enables Baserun to capture and display the LLM chain’s entire lifecycle, whether synchronous or asynchronous.Tracing LLM chains allows you to debug your application, monitor your LLM chains’ performance, and also collect user feedback.
At your application’s startup, define the environment in which you’d like to run Baserun. You can use Baserun in the development environment while iterating on your features, utilizing it for debugging and analysis, or in the production environment to monitor your application.
Copy
Ask AI
import baserunbaserun.init()
4
Decide what to trace
The function(s) to trace are ultimately dependent on your app. It could be a main() function, or it could be a handler for an API call.Note for TS/JS: Make sure to always call await baserun.init() before you instantiate OpenAI, Anthropic or Replicate.
Copy
Ask AI
# Decorate the function that you would like to trace:import baserun@baserun.tracedef get_response(message):...
import baserunimport openaidef get_activities(): response = openai.chat.completions.create( model="gpt-3.5-turbo", temperature=0.7, messages=[ { "role": "user", "content": "What are three activities to do on the Moon?" } ], ) return response.choices[0].message.content@baserun.tracedef find_best_activity(): moon_activities = get_activities() response = openai.chat.completions.create( model="gpt-3.5-turbo", temperature=0.7, messages=[ { "role": "user", "content": "Pick the best activity to do on the moon from the following, including a convincing reason to do so.\n + {moon_activities}" } ], ) return response.choices[0].message.contentif __name__ == "__main__": baserun.api_key = YOUR_BASERUN_API_KEY_HERE openai.api_key = YOUR_OPEANI_API_KEY_HERE baserun.init() print(find_best_activity())
Congrats, you are done! Now, you can navigate to the monitoring tab. Here is what you will see interact with your application:
Optionally, you can add metadata like trace name, user ID, and session ID to aid in debugging. Read Logging > Advanced tracing features for more details.