Skip to content

Commit

Permalink
terminal based chatbot written in vint
Browse files Browse the repository at this point in the history
  • Loading branch information
tacheraSasi committed Nov 28, 2024
1 parent 5df1aa6 commit 5129843
Show file tree
Hide file tree
Showing 11 changed files with 613 additions and 17 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/charmbracelet/lipgloss v0.7.1
github.com/google/uuid v1.6.0
github.com/lrstanley/bubblezone v0.0.0-20230303230241-08f906ff62a9
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.5.2 h1:ALmeCk/px5FSm1MAcFBAsVKZjDuMVj8Tm7FFIlMJnqU=
github.com/yuin/goldmark v1.5.2/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
212 changes: 212 additions & 0 deletions knowledge_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"questions": [
{
"question": "hi",
"answer": "hello"
},
{
"question": "ho",
"answer": "yui"
},
{
"question": "hello",
"answer": "how are you?"
},
{
"question": "i love coding",
"answer": "Yes, me too."
},
{
"question": "hi how are you",
"answer": "I'm fine"
},
{
"question": "what's your name?",
"answer": "I'm a chatbot created to assist you."
},
{
"question": "what's the weather like?",
"answer": "I'm not able to check the weather currently."
},
{
"question": "tell me a joke",
"answer": "Why don't programmers like nature? It has too many bugs."
},
{
"question": "what's your favorite programming language?",
"answer": "I don't have preferences, but I can help you with many languages!"
},
{
"question": "who created you?",
"answer": "I was created by a team of developers."
},
{
"question": "what can you do?",
"answer": "I can answer your questions, chat with you, and provide information."
},
{
"question": "do you know any quotes?",
"answer": "Here's one: 'Code is like humor. When you have to explain it, it’s bad.' - Cory House"
},
{
"question": "how old are you?",
"answer": "I don't age like humans do. I'm always learning and improving."
},
{
"question": "what is AI?",
"answer": "AI stands for Artificial Intelligence, which is the simulation of human intelligence in machines."
},
{
"question": "what is your purpose?",
"answer": "My purpose is to assist and provide information to users."
},
{
"question": "what is JavaScript?",
"answer": "JavaScript is a versatile programming language commonly used in web development for creating interactive elements on websites."
},
{
"question": "what is Python?",
"answer": "Python is a high-level programming language known for its readability and wide range of applications, from web development to data analysis."
},
{
"question": "what is machine learning?",
"answer": "Machine learning is a subset of AI that involves training algorithms to make predictions or decisions based on data."
},
{
"question": "what is a framework?",
"answer": "A framework is a set of tools and libraries that help developers build applications more efficiently by providing structure and common functionality."
},
{
"question": "what is a library in programming?",
"answer": "A library is a collection of pre-written code that developers can use to perform common tasks without having to write code from scratch."
},
{
"question": "what is Git?",
"answer": "Git is a version control system that allows developers to track changes in their code and collaborate with others."
},
{
"question": "what is GitHub?",
"answer": "GitHub is a platform that hosts Git repositories and provides tools for collaboration, code review, and project management."
},
{
"question": "what is a database?",
"answer": "A database is an organized collection of data that can be easily accessed, managed, and updated."
},
{
"question": "what is SQL?",
"answer": "SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases."
},
{
"question": "what is an API?",
"answer": "An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate with each other."
},
{
"question": "what is a front-end developer?",
"answer": "A front-end developer is responsible for creating the visual and interactive aspects of a website or application using HTML, CSS, and JavaScript."
},
{
"question": "what is a back-end developer?",
"answer": "A back-end developer focuses on the server-side of an application, managing databases, server logic, and application integration."
},
{
"question": "what is full-stack development?",
"answer": "Full-stack development involves working on both the front-end and back-end aspects of an application."
},
{
"question": "what is HTML?",
"answer": "HTML (HyperText Markup Language) is the standard language used to create and structure content on the web."
},
{
"question": "what is CSS?",
"answer": "CSS (Cascading Style Sheets) is a language used to style and layout web pages, including the design, colors, and fonts."
},
{
"question": "what is a programming language?",
"answer": "A programming language is a formal language comprising a set of instructions that produce various kinds of output, used to create software and applications."
},
{
"question": "what is an IDE?",
"answer": "An IDE (Integrated Development Environment) is a software application that provides comprehensive facilities to programmers for software development, including code editor, debugger, and build tools."
},
{
"question": "what is debugging?",
"answer": "Debugging is the process of identifying, analyzing, and fixing bugs or errors in a software program."
},
{
"question": "what is an algorithm?",
"answer": "An algorithm is a step-by-step procedure or formula for solving a problem or performing a task."
},
{
"question": "what is a function in programming?",
"answer": "A function is a block of code designed to perform a particular task, which can be called upon and executed when needed."
},
{
"question": "what is open-source software?",
"answer": "Open-source software is software with source code that anyone can inspect, modify, and enhance."
},
{
"question": "what is cloud computing?",
"answer": "Cloud computing is the delivery of computing services over the internet, including storage, processing power, and software."
},
{
"question": "what is IoT?",
"answer": "IoT (Internet of Things) refers to the network of physical objects embedded with sensors, software, and other technologies to connect and exchange data with other devices and systems over the internet."
},
{
"question": "what is cybersecurity?",
"answer": "Cybersecurity is the practice of protecting systems, networks, and programs from digital attacks."
},
{
"question": "what is blockchain?",
"answer": "Blockchain is a distributed ledger technology that ensures data integrity and security through cryptographic hashing and decentralized storage."
},
{
"question": "what is a startup?",
"answer": "A startup is a young company founded to develop a unique product or service and bring it to market."
},
{
"question": "what is agile development?",
"answer": "Agile development is a software development methodology that promotes continuous iteration of development and testing throughout the software lifecycle."
},
{
"question": "what is DevOps?",
"answer": "DevOps is a set of practices that combines software development (Dev) and IT operations (Ops) to shorten the development lifecycle and deliver high-quality software continuously."
},
{
"question": "what is big data?",
"answer": "Big data refers to large and complex datasets that are difficult to process using traditional data processing techniques."
},
{
"question": "what is data science?",
"answer": "Data science is an interdisciplinary field that uses scientific methods, processes, algorithms, and systems to extract knowledge and insights from data."
},
{
"question": "what is artificial intelligence?",
"answer": "Artificial intelligence (AI) is the simulation of human intelligence processes by machines, especially computer systems."
},
{
"question": "what is deep learning?",
"answer": "Deep learning is a subset of machine learning that uses neural networks with many layers to analyze various types of data."
},
{
"question": "what is a neural network?",
"answer": "A neural network is a series of algorithms that attempts to recognize underlying relationships in a set of data through a process that mimics the way the human brain operates."
},
{
"question": "what is natural language processing?",
"answer": "Natural language processing (NLP) is a field of AI that gives machines the ability to read, understand, and derive meaning from human languages."
},
{
"question": "what is a chatbot?",
"answer": "A chatbot is an AI-based software application that simulates human conversation through voice commands or text chats."
},
{
"question": "what is fintech?",
"answer": "Fintech, or financial technology, refers to new tech that seeks to improve and automate the delivery and use of financial services."
},
{
"question": "what is a hackathon?",
"answer": "A hackathon is an event where programmers and others involved in software development collaborate intensively on projects over a short period of time."
}
]
}
51 changes: 38 additions & 13 deletions module/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package module

import (
"encoding/json"
"strings"

"github.com/ekilie/vint-lang/object"
)
Expand All @@ -11,6 +12,7 @@ var JsonFunctions = map[string]object.ModuleFunction{}
func init() {
JsonFunctions["decode"] = decode
JsonFunctions["encode"] = encode
JsonFunctions["stringify"] = encode //Experimental
JsonFunctions["pretty"] = pretty
JsonFunctions["merge"] = merge
JsonFunctions["get"] = get
Expand Down Expand Up @@ -78,21 +80,44 @@ func convertWhateverToObject(i interface{}) object.Object {
}

func encode(args []object.Object, defs map[string]object.Object) object.Object {
if len(defs) != 0 {
return &object.Error{Message: "This argument is not allowed"}
}

input := args[0]
i := convertObjectToWhatever(input)
data, err := json.Marshal(i)

if err != nil {
return &object.Error{Message: "Unable to convert data to JSON"}
}

return &object.String{Value: string(data)}
if len(defs) != 0 {
return &object.Error{Message: "This argument is not allowed"}
}

if len(args) < 1 || len(args) > 2 {
return &object.Error{Message: "Expect one or two arguments: data and optional indent"}
}

input := args[0]
i := convertObjectToWhatever(input)

// Default to no indentation
indent := ""
if len(args) == 2 {
if args[1].Type() != object.INTEGER_OBJ {
return &object.Error{Message: "Indent must be an integer"}
}
spaces := int(args[1].(*object.Integer).Value)
indent = strings.Repeat(" ", spaces)
}

var data []byte
var err error

if indent != "" {
data, err = json.MarshalIndent(i, "", indent)
} else {
data, err = json.Marshal(i)
}

if err != nil {
return &object.Error{Message: "Unable to convert data to JSON"}
}

return &object.String{Value: string(data)}
}


func convertObjectToWhatever(obj object.Object) interface{} {
switch v := obj.(type) {
case *object.Dict:
Expand Down
29 changes: 29 additions & 0 deletions module/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package module
import (
"strings"
"github.com/ekilie/vint-lang/object"
"github.com/xrash/smetrics" // A library for string metrics, like Levenshtein
)

var StringFunctions = map[string]object.ModuleFunction{}
Expand All @@ -18,6 +19,34 @@ func init() {
StringFunctions["substring"] = substring
StringFunctions["length"] = length
StringFunctions["indexOf"] = indexOf
StringFunctions["similarity"] = similarity
}

// similarity computes a similarity score between two strings
func similarity(args []object.Object, defs map[string]object.Object) object.Object {
if len(args) != 2 {
return &object.Error{Message: "We need two arguments: the first string and the second string"}
}

str1 := args[0].Inspect()
str2 := args[1].Inspect()

// Using Levenshtein distance to calculate similarity
distance := smetrics.WagnerFischer(str1, str2, 1, 1, 2)
maxLen := len(str1)
if len(str2) > maxLen {
maxLen = len(str2)
}

// Avoid division by zero
if maxLen == 0 {
return &object.Float{Value: 1.0} // Perfect match for empty strings
}

// Calculate similarity as 1 - (normalized distance)
similarityScore := 1.0 - float64(distance)/float64(maxLen)

return &object.Float{Value: similarityScore}
}

// trim removes leading and trailing whitespaces
Expand Down
7 changes: 6 additions & 1 deletion savegame.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"health":100,"inventory":["Mystic Key"],"location":"start","name":"Tach"}
{
"health": 100,
"inventory": ["Mystic Key"],
"location": "start",
"name": "Tach"
}
Loading

0 comments on commit 5129843

Please sign in to comment.