-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GPT4All Java Bindings and supported models list (#216)
* Generic AI client and models with open-ai client impl from https://github.com/aallam/openai-kotlin * type LLM models based on their capabilities and type the operations * add token as parameter to `openAI` fn falling back to env variable * add config as optional parameter * remove old config * adapt to latest changes from main and new java module * have openai be its own module that depends on xef-core. kotlin, scala and java depends on openai module for defaults. xef core does not depend on open ai * fix bug in scala fn name for serialization * make AIClient : AutoCloseable * Rename enum cases * Rename to TEXT_EMBEDDING_ADA_002 * Fix AIClient close expectation * Progress with models * Refactor to have models typed and increase ergonomics * Loading embeddings and tokenizer from huggingface, dynamic loading of local models. Local models can be use in the AI DSL and interleaved with any model. * remove non used repositories * Fix functions model to GPT_3_5_TURBO_FUNCTIONS and example without AI block and manual component construction * remove unused import * GPT4All Java Bindings and supported models list + std out streaming support --------- Co-authored-by: Simon Vergauwen <[email protected]>
- Loading branch information
Showing
26 changed files
with
274 additions
and
341 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
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
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
43 changes: 19 additions & 24 deletions
43
examples/kotlin/src/main/kotlin/com/xebia/functional/xef/auto/gpt4all/Chat.kt
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
43 changes: 37 additions & 6 deletions
43
examples/kotlin/src/main/kotlin/com/xebia/functional/xef/auto/manual/NoAI.kt
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,16 +1,47 @@ | ||
package com.xebia.functional.xef.auto.manual | ||
|
||
import com.xebia.functional.gpt4all.GPT4All | ||
import com.xebia.functional.gpt4all.HuggingFaceLocalEmbeddings | ||
import com.xebia.functional.xef.auto.llm.openai.OpenAI | ||
import com.xebia.functional.gpt4all.huggingFaceUrl | ||
import com.xebia.functional.xef.auto.PromptConfiguration | ||
import com.xebia.functional.xef.pdf.pdf | ||
import com.xebia.functional.xef.vectorstores.LocalVectorStore | ||
import java.nio.file.Path | ||
|
||
suspend fun main() { | ||
val chat = OpenAI.DEFAULT_CHAT | ||
val huggingFaceEmbeddings = HuggingFaceLocalEmbeddings.DEFAULT | ||
val vectorStore = LocalVectorStore(huggingFaceEmbeddings) | ||
val results = pdf("https://www.europarl.europa.eu/RegData/etudes/STUD/2023/740063/IPOL_STU(2023)740063_EN.pdf") | ||
// Choose your base folder for downloaded models | ||
val userDir = System.getProperty("user.dir") | ||
|
||
// Specify the local model path | ||
val modelPath: Path = Path.of("$userDir/models/gpt4all/ggml-gpt4all-j-v1.3-groovy.bin") | ||
|
||
// Specify the Hugging Face URL for the model | ||
val url = huggingFaceUrl("orel12", "ggml-gpt4all-j-v1.3-groovy", "bin") | ||
|
||
// Create an instance of GPT4All with the local model | ||
val gpt4All = GPT4All(url, modelPath) | ||
|
||
// Create an instance of the OPENAI embeddings | ||
val embeddings = HuggingFaceLocalEmbeddings.DEFAULT | ||
|
||
// Create a LocalVectorStore and initialize it with OpenAI Embeddings | ||
val vectorStore = LocalVectorStore(embeddings) | ||
|
||
// Fetch and add texts from a PDF document to the vector store | ||
val results = pdf("https://arxiv.org/pdf/2305.10601.pdf") | ||
vectorStore.addTexts(results) | ||
val result: List<String> = chat.promptMessage("What is the content about?", vectorStore) | ||
|
||
// Prompt the GPT4All model with a question and provide the vector store for context | ||
val result: List<String> = gpt4All.use { | ||
it.promptMessage( | ||
question = "What is the Tree of Thoughts framework about?", | ||
context = vectorStore, | ||
promptConfiguration = PromptConfiguration { | ||
docsInContext(5) | ||
} | ||
) | ||
} | ||
|
||
// Print the response | ||
println(result) | ||
} |
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
Binary file removed
BIN
-696 KB
gpt4all-kotlin/src/commonMain/resources/darwin-aarch64/libllama.dylib
Binary file not shown.
Binary file removed
BIN
-648 KB
gpt4all-kotlin/src/commonMain/resources/darwin-aarch64/libllmodel.dylib
Binary file not shown.
Binary file removed
BIN
-696 KB
gpt4all-kotlin/src/commonMain/resources/darwin-x86-64/libllama.dylib
Binary file not shown.
Binary file removed
BIN
-648 KB
gpt4all-kotlin/src/commonMain/resources/darwin-x86-64/libllmodel.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.