Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevherro committed Apr 8, 2023
0 parents commit bbdfcc3
Show file tree
Hide file tree
Showing 15 changed files with 1,016 additions and 0 deletions.
139 changes: 139 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,139 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
GOPATH: ${{ github.workspace }}
WORKING_DIR: ./src/github.com/kevherro/bob/
jobs:
test-mac:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
strategy:
fail-fast: false
matrix:
go: ['1.20', 'tip']
os: ['macos-12']
xcode-version: ['13.1.0', '14.2.0']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@v4
if: matrix.go != 'tip'
with:
go-version: ${{ matrix.go }}

- name: Update Go version manually
if: matrix.go == 'tip'
working-directory: ${{ github.workspace }}
run: |
git clone https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
echo "RUN_STATICCHECK=false" >> $GITHUB_ENV
echo "RUN_GOLANGCI_LINTER=false" >> $GITHUB_ENV
echo "$HOME/gotip/bin:$PATH" >> $GITHUB_PATH
- name: Checkout the repo
uses: actions/checkout@v3
with:
path: ${{ env.WORKING_DIR }}

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode-version }}

- name: Fetch dependencies
run: |
# Do not let tools interfere with the main module's go.mod.
cd && go mod init tools
# TODO: Update to a specific version when https://github.com/dominikh/go-tools/issues/1362 is fixed.
go install honnef.co/go/tools/cmd/staticcheck@master
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
# Add PATH for installed tools.
echo "$GOPATH/bin:$PATH" >> $GITHUB_PATH
- name: Run the script
run: |
go version
./test.sh
- name: Check to make sure that tests also work in GOPATH mode
env:
GO111MODULE: off
run: |
go get -d .
go test -v ./...
- name: Code coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt

test-linux:
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
strategy:
fail-fast: false
matrix:
go: ['1.20', 'tip']
os: ['ubuntu-22.04', 'ubuntu-20.04']
steps:
- name: Update Go version using setup-go
uses: actions/setup-go@v4
if: matrix.go != 'tip'
with:
go-version: ${{ matrix.go }}

- name: Update Go version manually
if: matrix.go == 'tip'
working-directory: ${{ github.workspace }}
run: |
git clone https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV
echo "RUN_STATICCHECK=false" >> $GITHUB_ENV
echo "RUN_GOLANGCI_LINTER=false" >> $GITHUB_ENV
echo "$HOME/gotip/bin" >> $GITHUB_PATH
- name: Checkout the repo
uses: actions/checkout@v3
with:
path: ${{ env.WORKING_DIR }}

- name: Fetch dependencies
run: |
# Do not let tools interfere with the main module's go.mod.
cd && go mod init tools
# TODO: Update to a specific version when https://github.com/dominikh/go-tools/issues/1362 is fixed.
go install honnef.co/go/tools/cmd/staticcheck@master
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
# Add PATH for installed tools.
echo "$GOPATH/bin:$PATH" >> $GITHUB_PATH
- name: Run the script
run: |
go version
./test.sh
- name: Check to make sure that tests also work in GOPATH mode
env:
GO111MODULE: off
run: |
go get -d .
go test -v ./...
- name: Code coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
.DS_Store
*~
*.orig
*.exe
.*.swp
core
coverage.txt
vyx
.idea/
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Kevin Herro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
@@ -0,0 +1,19 @@
[![Github Action CI](https://github.com/kevherro/vyx/workflows/ci/badge.svg)](https://github.com/kevherro/vyx/actions)

# Introduction

# Building vyx

Prerequisites:

- Go development kit of a [supported version](https://golang.org/doc/devel/release.html#policy).
Follow [these instructions](http://golang.org/doc/code.html) to prepare
the environment.

To build and install it:

go install github.com/kevherro/vyx@latest

The binary will be installed `$GOPATH/bin` (`$HOME/go/bin` by default).

# Basic Usage
66 changes: 66 additions & 0 deletions driver/driver.go
@@ -0,0 +1,66 @@
// MIT License
//
// Copyright (c) 2023 Kevin Herro
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// Package driver provides an external entry point to the vyx driver.
package driver

import (
"io"

internaldriver "github.com/kevherro/vyx/internal/driver"
"github.com/kevherro/vyx/internal/plugin"
)

// Vyx ...
func Vyx(o *Options) error {
return internaldriver.Vyx(o.internalOptions())
}

func (o *Options) internalOptions() *plugin.Options {
return &plugin.Options{
Writer: o.Writer,
UI: o.UI,
}
}

// Options groups all the optional plugins into vyx.
type Options struct {
Writer Writer
UI UI
}

// Writer provides a mechanism to write data under a certain name,
// typically a file name.
type Writer interface {
Open(name string) (io.WriteCloser, error)
}

// A UI manages user interactions.
type UI interface {
// ReadLine returns a line of text (a command) read from the user.
// prompt is printed before reading the command.
ReadLine(prompt string) (string, error)

// Print shows a message to the user.
// It formats the text as fmt.Print would and
// adds a final \n if not already present.
// For line-based UI, Print writes to STDERR.
Print(...any)

// PrintErr shows a message to the user.
// It formats the text as fmt.Print would and
// adds a final \n if not already present.
// For line-based UI, Print writes to STDERR.
PrintErr(...any)
}
7 changes: 7 additions & 0 deletions go.mod
@@ -0,0 +1,7 @@
module github.com/kevherro/vyx

go 1.20

require github.com/chzyer/readline v1.5.1

require golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
8 changes: 8 additions & 0 deletions go.sum
@@ -0,0 +1,8 @@
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62 changes: 62 additions & 0 deletions internal/api/api.go
@@ -0,0 +1,62 @@
// MIT License
//
// Copyright (c) 2023 Kevin Herro
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// Package api implements models for the OpenAI API.
package api

type CompletionRequest struct {
Prompt string `json:"prompt"`
Model string `json:"model"`
MaxTokens int `json:"max_tokens"`
Temperature float64 `json:"temperature"`
}

type CompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
CreatedAt int64 `json:"created_at"`
Model string `json:"model"`
Choices []Choice `json:"choices"`
Completion Completion `json:"completion"`
Conversation Conversation `json:"conversation"`
}

type Choice struct {
Text string `json:"text"`
Index int `json:"index"`
LogProb float64 `json:"logproba"`
}

type Completion struct {
ID string `json:"id"`
CreatedAt int64 `json:"created_at"`
Model string `json:"model"`
Prompt string `json:"prompt"`
Choices []Choice `json:"choices"`
}

type Conversation struct {
ID string `json:"id"`
CreatedAt int64 `json:"created_at"`
Object string `json:"object"`
Messages []Message `json:"messages"`
}

type Message struct {
ID string `json:"id"`
CreatedAt int64 `json:"created_at"`
Type string `json:"type"`
Author string `json:"author"`
Body string `json:"body"`
}

0 comments on commit bbdfcc3

Please sign in to comment.