Skip to content

Commit

Permalink
get rid of dto package
Browse files Browse the repository at this point in the history
  • Loading branch information
galkleinman committed Jan 24, 2024
1 parent c10f228 commit 2838543
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 64 deletions.
13 changes: 6 additions & 7 deletions sample-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/sashabaranov/go-openai"
tlp "github.com/traceloop/go-openllmetry/traceloop-sdk"
"github.com/traceloop/go-openllmetry/traceloop-sdk/dto"
)

func main() {
Expand Down Expand Up @@ -44,32 +43,32 @@ func main() {
fmt.Println(resp.Choices[0].Message.Content)


log := dto.PromptLogAttributes{
Prompt: dto.Prompt{
log := tlp.PromptLogAttributes{
Prompt: tlp.Prompt{
Vendor: "openai",
Mode: "chat",
Model: request.Model,
},
Completion: dto.Completion{
Completion: tlp.Completion{
Model: resp.Model,
},
Usage: dto.Usage{
Usage: tlp.Usage{
TotalTokens: resp.Usage.TotalTokens,
CompletionTokens: resp.Usage.CompletionTokens,
PromptTokens: resp.Usage.PromptTokens,
},
}

for i, message := range request.Messages {
log.Prompt.Messages = append(log.Prompt.Messages, dto.Message{
log.Prompt.Messages = append(log.Prompt.Messages, tlp.Message{
Index: i,
Content: message.Content,
Role: message.Role,
})
}

for _, choice := range resp.Choices {
log.Completion.Messages = append(log.Completion.Messages, dto.Message{
log.Completion.Messages = append(log.Completion.Messages, tlp.Message{
Index: choice.Index,
Content: choice.Message.Content,
Role: choice.Message.Role,
Expand Down
8 changes: 0 additions & 8 deletions traceloop-sdk/dto/prompts_registry.go

This file was deleted.

44 changes: 0 additions & 44 deletions traceloop-sdk/dto/tracing.go

This file was deleted.

8 changes: 6 additions & 2 deletions traceloop-sdk/prompt_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import (

"github.com/kluctl/go-jinja2"
"github.com/sashabaranov/go-openai"
"github.com/traceloop/go-openllmetry/traceloop-sdk/dto"
"github.com/traceloop/go-openllmetry/traceloop-sdk/model"
)

type PromptsResponse struct {
Prompts []model.Prompt `json:"prompts"`
Environment string `json:"environment"`
}

func (instance *Traceloop) populatePromptRegistry() {
resp, err := instance.fetchPathWithRetry(PromptsPath, instance.config.BackoffConfig.MaxRetries)
if err != nil {
Expand All @@ -20,7 +24,7 @@ func (instance *Traceloop) populatePromptRegistry() {
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)

var response dto.PromptsResponse
var response PromptsResponse
err = decoder.Decode(&response)
if err != nil {
fmt.Println("Failed to decode response", err)
Expand Down
5 changes: 2 additions & 3 deletions traceloop-sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
apitrace "go.opentelemetry.io/otel/trace"

semconvai "github.com/traceloop/go-openllmetry/semconv-ai"
"github.com/traceloop/go-openllmetry/traceloop-sdk/dto"
"github.com/traceloop/go-openllmetry/traceloop-sdk/model"
)

Expand Down Expand Up @@ -70,7 +69,7 @@ func (instance *Traceloop) initialize(ctx context.Context) error {
return nil
}

func setMessagesAttribute(span apitrace.Span, prefix string, messages []dto.Message) {
func setMessagesAttribute(span apitrace.Span, prefix string, messages []Message) {
for _, message := range messages {
attrsPrefix := fmt.Sprintf("%s.%d", prefix, message.Index)
span.SetAttributes(
Expand All @@ -80,7 +79,7 @@ func setMessagesAttribute(span apitrace.Span, prefix string, messages []dto.Mess
}
}

func (instance *Traceloop) LogPrompt(ctx context.Context, attrs dto.PromptLogAttributes) error {
func (instance *Traceloop) LogPrompt(ctx context.Context, attrs PromptLogAttributes) error {
spanName := fmt.Sprintf("%s.%s", attrs.Prompt.Vendor, attrs.Prompt.Mode)
_, span := (*instance.tracerProvider).Tracer(os.Args[0]).Start(ctx, spanName)

Expand Down

0 comments on commit 2838543

Please sign in to comment.