-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
556 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ollama-from-scratch | ||
prompting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# Demo: use RAG to add Parakeet knowledge to LLMs | ||
> ask me anything about Parakeet | ||
> 🚧 wip |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/parakeet-nest/parakeet/content" | ||
"github.com/parakeet-nest/parakeet/embeddings" | ||
"github.com/parakeet-nest/parakeet/llm" | ||
) | ||
|
||
func main() { | ||
ollamaUrl := "http://localhost:11434" | ||
// if working from a container | ||
//ollamaUrl := "http://host.docker.internal:11434" | ||
//var embeddingsModel = "magicoder:latest" | ||
|
||
embeddingsModel := "all-minilm" | ||
|
||
store := embeddings.BboltVectorStore{} | ||
store.Initialize("../embeddings.db") | ||
|
||
// Parse all source code of the examples | ||
// Create embeddings from documents and save them in the store | ||
|
||
counter := 0 | ||
_, err := content.ForEachFile("../../examples", ".go", func(path string) error { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("📝 Creating embedding from:", path) | ||
counter++ | ||
embedding, err := embeddings.CreateEmbedding( | ||
ollamaUrl, | ||
llm.Query4Embedding{ | ||
Model: embeddingsModel, | ||
Prompt: string(data), | ||
}, | ||
strconv.Itoa(counter), // don't forget the id (unique identifier) | ||
) | ||
fmt.Println("📦 Created: ", len(embedding.Embedding)) | ||
|
||
if err != nil { | ||
fmt.Println("😡:", err) | ||
} else { | ||
_, err := store.Save(embedding) | ||
if err != nil { | ||
fmt.Println("😡:", err) | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatalln("😡:", err) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
🔎 searching for similarity... | ||
🎉 similarities 15 | ||
|
||
🤖 answer: |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package content | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestGetArrayOfContentFiles(t *testing.T) { | ||
|
||
content, err := GetArrayOfContentFiles("./contents-for-test", ".txt") | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fmt.Println("📝 content", content) | ||
|
||
if content[0] != "hello world" { | ||
t.Fatal("hello world not found") | ||
} | ||
if content[1] != "hey people" { | ||
t.Fatal("hey people not found") | ||
} | ||
|
||
if content[2] != "hello world" { | ||
t.Fatal("hello world not found") | ||
} | ||
if content[3] != "hey people" { | ||
t.Fatal("hey people not found") | ||
} | ||
|
||
} | ||
|
||
func TestGetMapOfContentFiles(t *testing.T) { | ||
|
||
content, err := GetMapOfContentFiles("./contents-for-test", ".txt") | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fmt.Println("📝 content", content) | ||
|
||
if content["contents-for-test/01/hello.txt"] != "hello world" { | ||
t.Fatal("hello world not found") | ||
} | ||
if content["contents-for-test/02/hey.txt"] != "hey people" { | ||
t.Fatal("hey people not found") | ||
} | ||
if content["contents-for-test/01/hello.txt"] != "hello world" { | ||
t.Fatal("hello world not found") | ||
} | ||
if content["contents-for-test/02/hey.txt"] != "hey people" { | ||
t.Fatal("hey people not found") | ||
} | ||
|
||
} | ||
|
||
func TestGenerateContextFromDocs(t *testing.T) { | ||
content, err := GetArrayOfContentFiles("./contents-for-test", ".txt") | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
context := GenerateContextFromDocs(content) | ||
|
||
fmt.Println("📝 context", context) | ||
|
||
if strings.Contains(context, "<doc>hello world</doc>") == false { | ||
t.Fatal("hello world not found") | ||
} | ||
if strings.Contains(context, "<doc>hey people</doc>") == false { | ||
t.Fatal("hey people not found") | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hey people |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hey people |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package content | ||
|
||
import "fmt" | ||
|
||
// GenerateContextFromDocs generates the context content from a slice of documents. | ||
// | ||
// Remarks: you can use the generated content to add context to a prompt for an LLM. | ||
// | ||
// Parameters: | ||
// - docs: a slice of strings representing the documents. | ||
// | ||
// Returns: | ||
// - string: the generated context content in XML format. | ||
func GenerateContextFromDocs(docs []string) string { | ||
|
||
documentsContent := "<context>\n" | ||
for _, doc := range docs { | ||
documentsContent += fmt.Sprintf("<doc>%s</doc>\n", doc) | ||
} | ||
documentsContent += "</context>" | ||
return documentsContent | ||
} | ||
/* | ||
This is a Go function called GenerateContextFromDocs that takes a slice of strings as input and returns a string in XML format. | ||
The function generates the context content from a slice of documents by iterating over each document in the slice and appending it to a string in the format <doc>document content</doc>. | ||
Finally, the function wraps the entire content in <context> tags and returns it. | ||
*/ | ||
|
||
// TODO: GenerateContextWithTags |
Oops, something went wrong.