Skip to content

Commit

Permalink
Add pipelines, Earthfile, linter
Browse files Browse the repository at this point in the history
Signed-off-by: mudler <[email protected]>
  • Loading branch information
mudler committed Mar 3, 2023
1 parent dc4d7df commit e2a0b87
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint
on:
pull_request:
push:

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run Lint
run: |
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm -t -v $(pwd):/workspace -v earthly-tmp:/tmp/earthly:rw earthly/earthly:v0.6.21 +lint
20 changes: 20 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unit tests
on:
pull_request:
push:

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run tests
run: |
docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock --rm -t -v $(pwd):/workspace -v earthly-tmp:/tmp/earthly:rw earthly/earthly:v0.6.21 --allow-privileged +test
- name: Codecov
uses: codecov/codecov-action@v2
with:
file: ./coverage.out
23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
run:
timeout: 5m
tests: false
linters:
enable:
- revive # replacement for golint
- dupl # check duplicated code
- goconst # check strings that can turn into constants
- gofmt # check fmt
- goheader # Check license headers, only checks files in current year
- goimports # check imports
- gocyclo # check complexity
- govet
- gosimple
- deadcode
- ineffassign
- unused
- varcheck
- staticcheck
- typecheck
- structcheck
- godot
- misspell
32 changes: 32 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
VERSION 0.6

ARG GO_VERSION=1.18
ARG GOLINT_VERSION=1.47.3

go-deps:
ARG GO_VERSION
FROM golang:$GO_VERSION
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
RUN apt-get update
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

test:
FROM +go-deps
ARG OPENAI_API_TOKEN
WORKDIR /build
RUN go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
COPY . .
RUN ginkgo run --race --fail-fast --slow-spec-threshold 30s --covermode=atomic --coverprofile=coverage.out -p -r ./
SAVE ARTIFACT coverage.out AS LOCAL coverage.out

lint:
ARG GO_VERSION
FROM golang:$GO_VERSION
ARG GOLINT_VERSION
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v$GOLINT_VERSION
WORKDIR /build
COPY . .
RUN golangci-lint run
2 changes: 1 addition & 1 deletion conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *Conversation) User(input string) (string, error) {
return c.converse(c.ctx, roleUser, input)
}

// Chat is syntax sugar. is equivalent to call User
// Chat is syntax sugar. is equivalent to call User.
func (c *Conversation) Chat(input string) (string, error) {
return c.User(input)
}
8 changes: 4 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/otiai10/openaigo"
)

// Option is the options for the conversation
// Option is the options for the conversation.
type Option func(c *Conversation) error

// WithInitialPrompt allow to load an initial prompt to guide your model's behavior throughout the conversation.
Expand All @@ -18,23 +18,23 @@ func WithInitialPrompt(s string) Option {
}
}

// WithModel allows to override the default model (gpt-3.5-turbo)
// WithModel allows to override the default model (gpt-3.5-turbo).
func WithModel(model string) Option {
return func(c *Conversation) error {
c.model = model
return nil
}
}

// WithHistory allows to inject an history in the conversation
// WithHistory allows to inject an history in the conversation.
func WithHistory(msg []openaigo.ChatMessage) Option {
return func(c *Conversation) error {
c.History = msg
return nil
}
}

// WithContext associate a context to the conversation
// WithContext associate a context to the conversation.
func WithContext(ctx context.Context) Option {
return func(c *Conversation) error {
c.ctx = ctx
Expand Down

0 comments on commit e2a0b87

Please sign in to comment.