Skip to content

Commit

Permalink
Start From Zero (#1)
Browse files Browse the repository at this point in the history
* Chore Go Module

- [+] chore(go.mod): add go.mod file with required dependencies
- [+] chore(go.sum): add go.sum file with checksums of dependencies

* Feat [Terminal] Constants

- [+] feat(terminal): add constants for terminal package
- [+] feat(terminal): add constants for language

* Feat [Terminal] Chat Struct

- [+] feat(terminal/chat.go): add ChatHistory struct and methods for managing chat history

* Chore [Terminal] [Constants] Update Constants

- [+] chore(constant.go): add animated chars and model AI constants
- [+] docs(constant.go): add comments for animated chars and model AI constants

* Feat [Terminal] Initialize Generative AI

- [+] feat(terminal/genai.go): add PrintTypingChat function to print characters with a delay
- [+] feat(terminal/genai.go): add SendMessage function to send a message to the generative AI model and print the response with typing effect

* Feat [Terminal] Initialize Sessions of GenAI

- [+] feat(terminal/session.go): add Session struct and NewSession function
- [+] feat(terminal/session.go): add Start method to Session struct
- [+] feat(terminal/session.go): implement graceful shutdown handling in Start method
- [+] feat(terminal/session.go): handle user input and AI response in Start method

* Feat [Main Module] Constants

- [+] feat(constant.go): add constant for API_KEY and logFatal

* Feat [Main] Initialize Main

- [+] feat(main.go): add main package and import necessary dependencies
- [+] feat(main.go): add main function to start the application
- [+] feat(main.go): retrieve API key from environment variable
- [+] feat(main.go): create new session using API key
- [+] feat(main.go): start the session

* Docs [README] Update Documentation

- [+] docs(README.md): add features section with subject to add more in future
- [+] feat(README.md): add features of terminal-based interaction, session chat history, intelligent shutdown, and realistic typing animation

* Feat Github CI

- [+] feat(dependabot.yml): add basic dependabot.yml file for Go project using Go modules
- [+] feat(CodeQL.yml): add CodeQL workflow for CI/CD and unit testing

* Go Docs [Terminal] add documentation

- [+] feat(terminal): add terminal package with documentation
  • Loading branch information
H0llyW00dzZ authored Jan 2, 2024
1 parent 5a6b7e0 commit 4f6aaf5
Show file tree
Hide file tree
Showing 12 changed files with 565 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Basic dependabot.yml file for a Go project using Go modules

version: 2
updates:
# Maintain dependencies for Go modules
- package-ecosystem: "gomod" # for Go modules
directory: "/" # Location of the go.mod file
schedule:
interval: "weekly" # How often to check for updates

# Optional: Open pull requests only for the main branch
target-branch: "master"

# Optional: Limit the number of open pull requests Dependabot can have at any one time
# open-pull-requests-limit: 5

# Optional: Configure commit message options
# commit-message:
# prefix: "chore"
# include: "scope"
152 changes: 152 additions & 0 deletions .github/workflows/CodeQL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
############################
# Author : H0llyW00dzZ #
############################
name: "CI: CodeQL Unit Testing Advanced"

on:
push:
# modify this branch
branches:
- master
paths-ignore:
- '**.md'
- '.github/workflows/**'
pull_request:
branches:
- master
paths-ignore:
- '**.md'
- '.github/workflows/**'
types: [opened, reopened, synchronize]

schedule:
- cron: '0 0 * * *'

# allows you to run this workflow manually
# Adding an `inputs` section to the `workflow_dispatch` event to define a new input parameter called `branch`
workflow_dispatch:
inputs:
branch:
description: 'Branch to scan'
required: true
default: 'master'

jobs:
analyze:
name: Analyze
runs-on: ${{ matrix.language == 'swift' && 'macos-latest' || 'ubuntu-latest' }}
timeout-minutes: ${{ matrix.language == 'swift' && 120 || 360 }}

permissions:
actions: read
contents: read
pull-requests: write
deployments: read
security-events: write

strategy:
fail-fast: false
matrix:
# this can be modified example if your repo is only python then remove 'javascript', 'go'
language: ['go']

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- name: Detect repository language
id: detect-language
run: |
echo "languages=${{ matrix.language }}" >> $GITHUB_ENV
echo "fileExists=true" >> $GITHUB_ENV
- name: Set up Python
if: ${{ matrix.language == 'python' }}
uses: actions/setup-python@v4
with:
python-version: '3.x'
env:
NODE_VERSION: 18

- name: Install Python dependencies
if: ${{ matrix.language == 'python' && matrix.fileExists }}
run: python -m pip install --upgrade pip && pip install -r requirements.txt
# github need to fix this confusing alias javascript-typescript, because in the end are javascript LMAO
- name: Set up JavaScript/TypeScript
if: ${{ matrix.language == 'javascript' }}
uses: actions/setup-node@v4
with:
node-version: '18'
# note: this useless because in CodeQL about dependencies it's only for compiled language or python
- name: Install JavaScript/TypeScript dependencies
if: ${{ matrix.language == 'javascript' && matrix.fileExists }}
run: npm ci
# note: ignore that warning in `setup up go` because this repo are using standard library, so go.sum not really needed lol
- name: Set up Go
if: ${{ matrix.language == 'go' }}
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
env:
NODE_VERSION: 18

- name: Install Go dependencies
if: ${{ matrix.language == 'go' && matrix.fileExists }}
run: go mod download

# Get CodeQL config from gist
- name: Get config from gist
run: |
mkdir -p .github/codeql
curl -o .github/codeql/codeql-config.yml https://gist.githubusercontent.com/H0llyW00dzZ/230f3422c3be901915f2802d3a3314b1/raw/dbdae057dfeabc6af42d5322c948f563dc8277a1/codeql-config.yml
- name: Initialize CodeQL
id: InitCodeQL
uses: github/codeql-action/init@v2
with:
# Configuration for init codeQL
languages: ${{ env.languages }}
config-file: ./.github/codeql/codeql-config.yml

# Attempt to automatically build code for compiled languages
# Currently only for Go, but more can be added later
- name: Attempt to automatically build code for ${{ matrix.language }}
if: ${{ matrix.language == 'go' }}
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL-Security Analysis
if: ${{ env.languages != '' }}
id: CodeQL
uses: github/codeql-action/analyze@v2
with:
# disable default upload because using multiple method
upload: false
# snippets for SARIF file
add-snippets: true

- name: Upload ${{ matrix.language }} SARIF for Analysis Result
if: ${{ matrix.language && env.languages != '' }}
id: upload-Analysis_Result-sarif
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ runner.workspace }}/results/${{ matrix.language }}.sarif
category: "Analysis Result: ${{ matrix.language }}"

# since it public everyone can see in artifact about Analysis Result
# just for incase you can disable this later by block #

- name: Encrypt Analysis Result
if: ${{ matrix.language && env.languages != '' }}
id: Encrypt_Analysis
run: |
curl -sSL "https://github.com/${{ github.repository_owner }}.gpg" -o keyfile
gpg --import keyfile
gpg --encrypt --recipient "$(gpg --list-keys --keyid-format LONG | grep '^pub' | awk '{print $2}' | awk -F'/' '{print $2}')" --trust-model always "${{ runner.workspace }}/results/${{ matrix.language }}.sarif"
- name: Upload Analysis Result As Artifact
uses: actions/upload-artifact@v3
with:
name: Analysis_Result (SARIF + Encrypted)
path: ${{ runner.workspace }}/results/${{ matrix.language }}.sarif.gpg
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
## Why Continue Development?

Interesting to built it in terminal after touring journey through the Go programming language, plus exploring Google's AI capabilities (currently in beta with Gemini).

## Features (Subject to add more in future.)

- **Terminal-Based Interaction**: Experience AI chatting within the comfort of your terminal, with a focus on simplicity and efficiency.
- **Session Chat History**: Maintain a transcript of your dialogue, capturing both queries and AI responses for a continuous conversational flow.
- **Intelligent Shutdown**: Benefit from built-in signal handling for a smooth exit process, ensuring your session ends without disruption and with proper resource cleanup.
- **Realistic Typing Animation**: Enjoy a more lifelike interaction with a simulated typing effect that mimics human conversation timing.
6 changes: 6 additions & 0 deletions cmd/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

const (
aPi_Key = "API_KEY"
logFatal = "API_KEY environment variable is not set"
)
22 changes: 22 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"log"
"os"

"github.com/H0llyW00dzZ/GoGenAI-Terminal-Chat/terminal"
)

func main() {
apiKey := os.Getenv(aPi_Key)
if apiKey == "" {
log.Fatal(logFatal)
}

session, err := terminal.NewSession(apiKey)
if err != nil {
log.Fatal(err)
}

session.Start()
}
30 changes: 30 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module github.com/H0llyW00dzZ/GoGenAI-Terminal-Chat

go 1.21.5

require (
cloud.google.com/go/ai v0.3.0 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/generative-ai-go v0.5.0 // direct
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/api v0.149.0 // direct
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading

0 comments on commit 4f6aaf5

Please sign in to comment.