Before you start logging you will have to create a LogRepository on the Maxim dashboard. To create a log repository,click on Logs and the
click on + icon on the sidebar. You can use the ID of that repository to push logs.
Initializing Maxim Go SDK import " github.com/maximhq/maxim-go/logging "
trace := logger. Trace ( & logging . TraceConfig {
Id: "trace-id" ,
Name: "trace-name" ,
Tags: map [ string ] string { "key" : "value" }
})
session := logger. Session ( & logging . SessionConfig {
Id: "session-id" ,
Name: "session-name" ,
Tags: map [ string ] string { "key" : "value" }
})
Once session
object is created, you can add multiple traces across the lifecycle of the conversation.
Create a Session and add a Trace to it import " github.com/maximhq/maxim-go/logging "
session := logger. Session ( & logging . SessionConfig {Id: "session-id" })
trace := session. Trace ( & logging . TraceConfig {Id: "trace-id" })
Using custom ids allows you to fetch a trace in any function using the same id. This can be useful in updating trace across your workflow.
Using custom ids for Traces import " github.com/maximhq/maxim-go/logging "
// ... in function 1
trace := logger. Trace ( & logging . TraceConfig {Id: "trace-id" })
// ... in function 2
trace := logger. Trace ( & logging . TraceConfig {Id: "trace-id" })
// it returns the same trace object
trace. AddTag ( "key" , "value" )
Using custom ids for Sessions import " github.com/maximhq/maxim-go/logging "
// ... in function 1
session := logger. Session ( & logging . SessionConfig {Id: "session-id" })
// ... in function 2
session := logger. Session ( & logging . SessionConfig {Id: "session-id" })
// it returns the same session object
session. AddTag ( "key" , "value" )
Once you have a trace
object, you can add
A Span (short for timespan), groups a bunch of items (Events, Retrieval, Generation, Feedback).
import " github.com/maximhq/maxim-go/logging "
span := trace. AddSpan ( & logging . SpanConfig {
Id: "span-id" ,
Name: "name" ,
Tags: map [ string ] string { "key" : "value" }
})
span. AddEvent ( "event-id" , "event-name" , map [ string ] string { "tag-key" : "tag-values" })
span. End ()
An Event is a point in time when something happened in the system.
Adding an Event to a Trace import " github.com/maximhq/maxim-go/logging "
trace. AddEvent ( "event-id" , "event name" , map [ string ] string { "key" : "value" })
A Retrieval is a special type of Span in Maxim, which represents a retrieval query to a knowledge base or vector database.
Adding a Retrieval to a Trace import " github.com/maximhq/maxim-go/logging "
retrieval := span. AddRetrieval ( & logging . RetrievalConfig {
Id: "retrieval-id" ,
Name: "name" ,
Metadata: map [ string ] string { "key" : "value" }
})
retrieval. SetInput ( "How many PTO days do I have?" )
retrieval. SetOutput ([] string { "doc1" , "doc2" })
retrieval. End ()
A Generation is a special type of Span in Maxim, which represents a call to an LLM.
generation.result expects result to be in OpenAI response format. Here is the reference to the OpenAI response
format
Adding a Generation to a Trace import " github.com/maximhq/maxim-go/logging "
generation := span. AddGeneration ( & logging . GenerationConfig {
Id: "generation-id" ,
Name: "name" ,
Provider: "openai" ,
Model: "gpt-3.5-turbo-16k" ,
ModelParameters: map [ string ] interface {}{ "temperature" : 3 },
Messages: [] logging . CompletionRequest {
{
Role: "system" ,
Content: "You are a helpful assistant" ,
},
},
})
generation. AddMessages ([] logging . CompletionRequest {
{
Role: "user" ,
Content: "Do this and that" ,
},
})
// This shows TextCompletionExample
generation. SetResult ( & logging . GenerationResult {
Id: "cmpl-uN1k3lnZkTlZg8GHt4Vtd1aB" ,
Object: "text_completion" ,
Created: 1718393286 ,
Model: "gpt-3.5-turbo-16k" ,
Choices: [] logging . Choice {
{
Index: 0 ,
Text: " \n Here is the response \n " ,
Logprobs: nil ,
FinishReason: "stop" ,
},
},
Usage: & logging . Usage {
PromptTokens: 7 ,
CompletionTokens: 105 ,
TotalTokens: 112 ,
},
})
A Feedback is a special type of Event in Maxim, which is a point in time when feedback was given in the system.
Adding a Feedback to a Trace import " github.com/maximhq/maxim-go/logging "
trace. SetFeedback ( & logging . Feedback {
Score: 0.5 ,
Comment: StrPtr ( "string feedback" ),
})