diff --git a/docs/content/config.md b/docs/content/config.md index d48199f0..d4d2f168 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -18,4 +18,11 @@ You need to set the `COHERE_API_KEY` environment variable to your Cohere API key You need to set the `HUGGING_FACE_HUB_TOKEN` environment variable to your Hugging Face API key. To get your API key refer to the [Hugging Face website](https://huggingface.co/). ## Nomic -You need to set the `NOMIC_API_KEY` environment variable to your Nomic API key. To get your API key refer to the [Nomic website](https://nomic.ai/). \ No newline at end of file +You need to set the `NOMIC_API_KEY` environment variable to your Nomic API key. To get your API key refer to the [Nomic website](https://nomic.ai/). + + +## Anthropic +You need to set the `ANTHROPIC_API_KEY` environment variable to your Anthropic API key. To get your API key refer to the [Anthropic website](https://anthropic.com/). + +## Voyage AI +You need to set the `VOYAGE_API_KEY` environment variable to your Voyage AI API key. To get your API key refer to the [Voyage AI website](https://www.voyageai.com/). \ No newline at end of file diff --git a/docs/content/reference/embedding.md b/docs/content/reference/embedding.md index 1016a16c..079291c1 100644 --- a/docs/content/reference/embedding.md +++ b/docs/content/reference/embedding.md @@ -17,6 +17,7 @@ LinGoose provides an interface for working with embeddings, allowing developers - [Ollama](https://ollama.ai) - [LocalAI](https://localai.io/) (_via OpenAI API compatibility_) - [Atlas Nomic](https://atlas.nomic.ai) +- [Voyage AI](https://www.voyageai.com/) ## Using Embeddings diff --git a/docs/content/reference/llm.md b/docs/content/reference/llm.md index f2ccd60d..fe885ebd 100644 --- a/docs/content/reference/llm.md +++ b/docs/content/reference/llm.md @@ -17,6 +17,7 @@ LinGoose supports the following LLM providers API: - [Ollama](https://ollama.ai) - [LocalAI](https://localai.io/) (_via OpenAI API compatibility_) - [Groq](https://groq.com/) +- [Anthropic](https://anthropic.com/) ## Using LLMs diff --git a/examples/chat/functions/main.go b/examples/chat/functions/main.go index 62d38e9b..98962a29 100644 --- a/examples/chat/functions/main.go +++ b/examples/chat/functions/main.go @@ -10,8 +10,8 @@ import ( "os" "github.com/henomis/lingoose/legacy/chat" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/chat/simple/main.go b/examples/chat/simple/main.go index 223a739c..c85b4151 100644 --- a/examples/chat/simple/main.go +++ b/examples/chat/simple/main.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/henomis/lingoose/legacy/chat" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" ) func main() { diff --git a/examples/embeddings/jsondb/main.go b/examples/embeddings/jsondb/main.go index 51e2ef46..a54c8276 100644 --- a/examples/embeddings/jsondb/main.go +++ b/examples/embeddings/jsondb/main.go @@ -8,9 +8,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" "github.com/henomis/lingoose/index/vectordb/jsondb" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/embeddings/knowledge_base/main.go b/examples/embeddings/knowledge_base/main.go index b1932919..64777e4b 100644 --- a/examples/embeddings/knowledge_base/main.go +++ b/examples/embeddings/knowledge_base/main.go @@ -12,9 +12,9 @@ import ( "github.com/henomis/lingoose/legacy/chat" "github.com/henomis/lingoose/index/vectordb/jsondb" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" "github.com/henomis/lingoose/types" ) diff --git a/examples/embeddings/milvus/main.go b/examples/embeddings/milvus/main.go index 04cd2a24..e97daad8 100644 --- a/examples/embeddings/milvus/main.go +++ b/examples/embeddings/milvus/main.go @@ -8,9 +8,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" milvusdb "github.com/henomis/lingoose/index/vectordb/milvus" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/embeddings/nomic/main.go b/examples/embeddings/nomic/main.go index b978f0af..9b683712 100644 --- a/examples/embeddings/nomic/main.go +++ b/examples/embeddings/nomic/main.go @@ -8,9 +8,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" "github.com/henomis/lingoose/index/vectordb/jsondb" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/embeddings/pinecone/main.go b/examples/embeddings/pinecone/main.go index 48e42270..2f84d8c3 100644 --- a/examples/embeddings/pinecone/main.go +++ b/examples/embeddings/pinecone/main.go @@ -8,9 +8,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" pineconedb "github.com/henomis/lingoose/index/vectordb/pinecone" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/embeddings/postgres/main.go b/examples/embeddings/postgres/main.go index 8d1fe783..19255953 100644 --- a/examples/embeddings/postgres/main.go +++ b/examples/embeddings/postgres/main.go @@ -9,9 +9,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" "github.com/henomis/lingoose/index/vectordb/postgres" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" // uncomment to use postgres // _ "github.com/lib/pq" diff --git a/examples/embeddings/qdrant/main.go b/examples/embeddings/qdrant/main.go index 546aaf41..a9f1182a 100644 --- a/examples/embeddings/qdrant/main.go +++ b/examples/embeddings/qdrant/main.go @@ -8,9 +8,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" qdrantdb "github.com/henomis/lingoose/index/vectordb/qdrant" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/embeddings/redis/main.go b/examples/embeddings/redis/main.go index dc6eb295..a224c41e 100644 --- a/examples/embeddings/redis/main.go +++ b/examples/embeddings/redis/main.go @@ -9,9 +9,9 @@ import ( "github.com/henomis/lingoose/index" indexoption "github.com/henomis/lingoose/index/option" "github.com/henomis/lingoose/index/vectordb/redis" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" "github.com/henomis/lingoose/loader" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/textsplitter" ) diff --git a/examples/llm/mock/main.go b/examples/llm/mock/main.go index fc59e302..307de907 100644 --- a/examples/llm/mock/main.go +++ b/examples/llm/mock/main.go @@ -3,8 +3,8 @@ package main import ( "context" + "github.com/henomis/lingoose/legacy/prompt" llmmock "github.com/henomis/lingoose/llm/mock" - "github.com/henomis/lingoose/prompt" ) func main() { diff --git a/examples/llm/openai/stream/chat/main.go b/examples/llm/openai/stream/chat/main.go index 44944d8f..44628ac8 100644 --- a/examples/llm/openai/stream/chat/main.go +++ b/examples/llm/openai/stream/chat/main.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/henomis/lingoose/legacy/chat" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" ) func main() { diff --git a/examples/pipeline/callbacks/main.go b/examples/pipeline/callbacks/main.go index 09233d52..5f6dc476 100644 --- a/examples/pipeline/callbacks/main.go +++ b/examples/pipeline/callbacks/main.go @@ -4,8 +4,8 @@ import ( "context" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/pipeline/chat/main.go b/examples/pipeline/chat/main.go index aaf6ef05..a8d9b9ba 100644 --- a/examples/pipeline/chat/main.go +++ b/examples/pipeline/chat/main.go @@ -9,8 +9,8 @@ import ( "github.com/henomis/lingoose/legacy/decoder" "github.com/henomis/lingoose/legacy/memory/ram" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/pipeline/history/main.go b/examples/pipeline/history/main.go index 782a51a8..bfd292ff 100644 --- a/examples/pipeline/history/main.go +++ b/examples/pipeline/history/main.go @@ -8,8 +8,8 @@ import ( "github.com/henomis/lingoose/history" "github.com/henomis/lingoose/legacy/chat" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/pipeline/memory/main.go b/examples/pipeline/memory/main.go index cfa49f36..237cedb0 100644 --- a/examples/pipeline/memory/main.go +++ b/examples/pipeline/memory/main.go @@ -8,8 +8,8 @@ import ( "github.com/henomis/lingoose/legacy/decoder" "github.com/henomis/lingoose/legacy/memory/ram" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" llmmock "github.com/henomis/lingoose/llm/mock" - "github.com/henomis/lingoose/prompt" ) func main() { diff --git a/examples/pipeline/openai/main.go b/examples/pipeline/openai/main.go index e5698d42..671e366a 100644 --- a/examples/pipeline/openai/main.go +++ b/examples/pipeline/openai/main.go @@ -7,8 +7,8 @@ import ( "github.com/henomis/lingoose/legacy/memory/ram" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/pipeline/simple/main.go b/examples/pipeline/simple/main.go index ade6db7b..2373a561 100644 --- a/examples/pipeline/simple/main.go +++ b/examples/pipeline/simple/main.go @@ -6,8 +6,8 @@ import ( "github.com/henomis/lingoose/legacy/decoder" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" llmmock "github.com/henomis/lingoose/llm/mock" - "github.com/henomis/lingoose/prompt" ) func main() { diff --git a/examples/pipeline/splitter/main.go b/examples/pipeline/splitter/main.go index a986fb8c..184237d8 100644 --- a/examples/pipeline/splitter/main.go +++ b/examples/pipeline/splitter/main.go @@ -7,8 +7,8 @@ import ( "github.com/henomis/lingoose/legacy/memory/ram" "github.com/henomis/lingoose/legacy/pipeline" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/llm/openai" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/prompt/chat/main.go b/examples/prompt/chat/main.go index 89d61756..ada9f802 100644 --- a/examples/prompt/chat/main.go +++ b/examples/prompt/chat/main.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/henomis/lingoose/legacy/chat" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" ) func main() { diff --git a/examples/prompt/hello/main.go b/examples/prompt/hello/main.go index c93e47a1..63b7b3ed 100644 --- a/examples/prompt/hello/main.go +++ b/examples/prompt/hello/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/types" ) diff --git a/examples/prompt/simple/main.go b/examples/prompt/simple/main.go index a5d756e9..9175000b 100644 --- a/examples/prompt/simple/main.go +++ b/examples/prompt/simple/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" ) func main() { diff --git a/examples/prompt/whisper/main.go b/examples/prompt/whisper/main.go index 30a6e348..1ad441ea 100644 --- a/examples/prompt/whisper/main.go +++ b/examples/prompt/whisper/main.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" ) func main() { diff --git a/legacy/chat/chat_test.go b/legacy/chat/chat_test.go index b1f72122..79e65db9 100644 --- a/legacy/chat/chat_test.go +++ b/legacy/chat/chat_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/types" ) diff --git a/legacy/pipeline/qa/qa.go b/legacy/pipeline/qa/qa.go index 819294e4..f8771a07 100644 --- a/legacy/pipeline/qa/qa.go +++ b/legacy/pipeline/qa/qa.go @@ -9,7 +9,7 @@ import ( indexoption "github.com/henomis/lingoose/index/option" "github.com/henomis/lingoose/legacy/chat" "github.com/henomis/lingoose/legacy/pipeline" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/types" ) diff --git a/legacy/pipeline/sql/sql.go b/legacy/pipeline/sql/sql.go index e4f7e5d3..b91f7c90 100644 --- a/legacy/pipeline/sql/sql.go +++ b/legacy/pipeline/sql/sql.go @@ -8,7 +8,7 @@ import ( "github.com/henomis/lingoose/legacy/decoder" "github.com/henomis/lingoose/legacy/pipeline" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/types" ) diff --git a/legacy/pipeline/summarize/summarize.go b/legacy/pipeline/summarize/summarize.go index a0e965e6..2308cd54 100644 --- a/legacy/pipeline/summarize/summarize.go +++ b/legacy/pipeline/summarize/summarize.go @@ -6,7 +6,7 @@ import ( "github.com/henomis/lingoose/document" "github.com/henomis/lingoose/legacy/pipeline" - "github.com/henomis/lingoose/prompt" + "github.com/henomis/lingoose/legacy/prompt" "github.com/henomis/lingoose/types" ) diff --git a/prompt/prompt.go b/legacy/prompt/prompt.go similarity index 100% rename from prompt/prompt.go rename to legacy/prompt/prompt.go diff --git a/prompt/template.go b/legacy/prompt/template.go similarity index 100% rename from prompt/template.go rename to legacy/prompt/template.go diff --git a/prompt/template_test.go b/legacy/prompt/template_test.go similarity index 100% rename from prompt/template_test.go rename to legacy/prompt/template_test.go diff --git a/prompt/whisper.go b/legacy/prompt/whisper.go similarity index 100% rename from prompt/whisper.go rename to legacy/prompt/whisper.go diff --git a/thread/thread.go b/thread/thread.go index 841b7d1a..f418c417 100644 --- a/thread/thread.go +++ b/thread/thread.go @@ -1,9 +1,10 @@ package thread import ( + "bytes" "strings" + "text/template" - "github.com/henomis/lingoose/prompt" "github.com/henomis/lingoose/types" ) @@ -205,12 +206,19 @@ func (c *Content) Format(input types.M) *Content { return c } - prompt := prompt.NewPromptTemplate(c.Data.(string)) - err := prompt.Format(input) + templateEngine, err := template.New("prompt"). + Option("missingkey=zero").Parse(c.Data.(string)) if err != nil { return c } - c.Data = prompt.String() + + var buffer bytes.Buffer + err = templateEngine.Execute(&buffer, input) + if err != nil { + return c + } + + c.Data = buffer.String() return c } diff --git a/thread/thread_test.go b/thread/thread_test.go new file mode 100644 index 00000000..4eaaeaec --- /dev/null +++ b/thread/thread_test.go @@ -0,0 +1,85 @@ +package thread + +import ( + "reflect" + "testing" + + "github.com/henomis/lingoose/types" +) + +func TestContent_Format(t *testing.T) { + type fields struct { + Type ContentType + Data any + } + type args struct { + input types.M + } + tests := []struct { + name string + fields fields + args args + want *Content + }{ + { + name: "Test 1", + fields: fields{ + Type: ContentTypeText, + Data: "Hello, World!", + }, + args: args{ + input: types.M{ + "key": "value", + }, + }, + want: &Content{ + Type: ContentTypeText, + Data: "Hello, World!", + }, + }, + { + name: "Test 2", + fields: fields{ + Type: ContentTypeText, + Data: "Hello, {{.key}}!", + }, + args: args{ + input: types.M{ + "key": "World", + }, + }, + want: &Content{ + Type: ContentTypeText, + Data: "Hello, World!", + }, + }, + { + name: "Test 3", + fields: fields{ + Type: ContentTypeText, + Data: "{{.text}}, {{.key}}!", + }, + args: args{ + input: types.M{ + "key": "World", + "text": "Hello", + }, + }, + want: &Content{ + Type: ContentTypeText, + Data: "Hello, World!", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &Content{ + Type: tt.fields.Type, + Data: tt.fields.Data, + } + if got := c.Format(tt.args.input); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Content.Format() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/transformer/hf-text-to-image.go b/transformer/hf-text-to-image.go index 1001e3f7..4deb64b3 100644 --- a/transformer/hf-text-to-image.go +++ b/transformer/hf-text-to-image.go @@ -13,6 +13,7 @@ import ( const ( hfDefaultTextToImageModel = "stabilityai/stable-diffusion-xl-base-1.0" + hfBearerPrefix = "Bearer " ) type HFTextToImage struct { @@ -80,7 +81,7 @@ func (h *HFTextToImage) hfTextToImageHTTPCall(ctx context.Context, input string) return nil, errors.New("nil request created") } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+h.token) + req.Header.Set("Authorization", hfBearerPrefix+h.token) resp, err := http.DefaultClient.Do(req) if err != nil {