Skip to content

Commit 37bec47

Browse files
authored
feat: add prompt registry support (#1)
1 parent 2ae29b1 commit 37bec47

File tree

14 files changed

+447
-0
lines changed

14 files changed

+447
-0
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
on:
3+
pull_request_target:
4+
types: [opened, synchronize]
5+
push:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: ["1.18", "1.19", "1.20", "1.21.x"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Setup Go ${{ matrix.go-version }}
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
- name: Install dependencies
23+
run: go get .
24+
- name: Build
25+
run: go build -v ./...
26+
- name: Test
27+
run: go test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
.vscode/

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/traceloop/go-openllmetry
2+
3+
go 1.21.4

go.work.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
2+
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
3+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
4+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5+
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
6+
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
7+
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
8+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

sample-app/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/traceloop/go-openllmetry/sample-app
2+
3+
go 1.21.4
4+
5+
require github.com/sashabaranov/go-openai v1.18.1

sample-app/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/sashabaranov/go-openai v1.18.1 h1:AnLoJrFaFtcUYWCtz+8V0zrlXxkiwqpWlAmCAZUnDNQ=
2+
github.com/sashabaranov/go-openai v1.18.1/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=

sample-app/main.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
openai "github.com/sashabaranov/go-openai"
9+
sdk "github.com/traceloop/go-openllmetry/traceloop-sdk"
10+
"github.com/traceloop/go-openllmetry/traceloop-sdk/config"
11+
)
12+
13+
func main() {
14+
traceloop := sdk.NewClient(config.Config{
15+
BaseURL: "https://api-staging.traceloop.com",
16+
APIKey: os.Getenv("TRACELOOP_API_KEY"),
17+
})
18+
19+
traceloop.Initialize()
20+
21+
request, err := traceloop.GetOpenAIChatCompletionRequest("eval-test", map[string]interface{}{ "a": "workout" })
22+
if err != nil {
23+
fmt.Printf("GetOpenAIChatCompletionRequest error: %v\n", err)
24+
return
25+
}
26+
27+
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
28+
resp, err := client.CreateChatCompletion(
29+
context.Background(),
30+
*request,
31+
)
32+
33+
if err != nil {
34+
fmt.Printf("ChatCompletion error: %v\n", err)
35+
return
36+
}
37+
38+
fmt.Println(resp.Choices[0].Message.Content)
39+
}

traceloop-sdk/config/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package config
2+
3+
import "time"
4+
5+
type BackoffConfig struct {
6+
MaxRetries uint64
7+
}
8+
9+
type Config struct {
10+
BaseURL string
11+
APIKey string
12+
PollingInterval time.Duration
13+
BackoffConfig BackoffConfig
14+
}

traceloop-sdk/dto/prompts_registry.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dto
2+
3+
import "github.com/traceloop/go-openllmetry/traceloop-sdk/model"
4+
5+
type PromptsResponse struct {
6+
Prompts []model.Prompt `json:"prompts"`
7+
Environment string `json:"environment"`
8+
}

traceloop-sdk/go.mod

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module github.com/traceloop/go-openllmetry/traceloop-sdk
2+
3+
go 1.21.4
4+
5+
require (
6+
github.com/cenkalti/backoff/v4 v4.2.1
7+
github.com/kluctl/go-jinja2 v0.0.0-20240108142937-8839259d2537
8+
github.com/sashabaranov/go-openai v1.18.1
9+
)
10+
11+
require (
12+
github.com/cenkalti/backoff v2.2.1+incompatible
13+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
14+
github.com/go-git/go-billy/v5 v5.5.0 // indirect
15+
github.com/go-git/go-git/v5 v5.11.0 // indirect
16+
github.com/gobwas/glob v0.2.3 // indirect
17+
github.com/hashicorp/errwrap v1.1.0 // indirect
18+
github.com/hashicorp/go-multierror v1.1.1 // indirect
19+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
20+
github.com/jinzhu/copier v0.4.0 // indirect
21+
github.com/kluctl/go-embed-python v0.0.0-3.11.6-20231002-1 // indirect
22+
github.com/rogpeppe/go-internal v1.11.0 // indirect
23+
github.com/sirupsen/logrus v1.9.3 // indirect
24+
golang.org/x/net v0.19.0 // indirect
25+
golang.org/x/sync v0.5.0 // indirect
26+
golang.org/x/sys v0.15.0 // indirect
27+
gopkg.in/warnings.v0 v0.1.2 // indirect
28+
)

0 commit comments

Comments
 (0)