-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sequential chain with QnA (#52)
* VectorStoreIndexCreator, error fixes, tweeking, Documents QnA test * changing Web and Pdf sources to use propper document * bugfixes and massive simplification of DocumentQnA test * bugfix * Sequential chain with QnA
- Loading branch information
Showing
3 changed files
with
137 additions
and
49 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
60 changes: 60 additions & 0 deletions
60
src/tests/LangChain.Providers.LLamaSharp.IntegrationTests/LLamaSharpTests.Helpers.cs
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,60 @@ | ||
using LangChain.Abstractions.Embeddings.Base; | ||
using LangChain.Databases.InMemory; | ||
using LangChain.Docstore; | ||
using LangChain.Indexes; | ||
using LangChain.Prompts; | ||
using LangChain.TextSplitters; | ||
|
||
namespace LangChain.Providers.LLamaSharp.IntegrationTests; | ||
|
||
public partial class LLamaSharpTests | ||
{ | ||
|
||
IEmbeddings CreateEmbeddings() | ||
{ | ||
var embeddings = new LLamaSharpEmbeddings(new LLamaSharpConfiguration | ||
{ | ||
PathToModelFile = ModelPath, | ||
Temperature = 0 | ||
}); | ||
return embeddings; | ||
|
||
} | ||
|
||
IChatModel CreateInstructionModel() | ||
{ | ||
var model = new LLamaSharpModelInstruction(new LLamaSharpConfiguration | ||
{ | ||
PathToModelFile = ModelPath, | ||
Temperature = 0 | ||
}); | ||
return model; | ||
|
||
} | ||
IChatModel CreateChatModel() | ||
{ | ||
var model = new LLamaSharpModelChat(new LLamaSharpConfiguration | ||
{ | ||
PathToModelFile = ModelPath, | ||
Temperature = 0 | ||
}); | ||
return model; | ||
|
||
} | ||
VectorStoreIndexWrapper CreateVectorStoreIndex(IEmbeddings embeddings, string[] texts) | ||
{ | ||
InMemoryVectorStore vectorStore = new InMemoryVectorStore(embeddings); | ||
var textSplitter = new CharacterTextSplitter(); | ||
VectorStoreIndexCreator indexCreator = new VectorStoreIndexCreator(vectorStore, textSplitter); | ||
var index = indexCreator.FromDocumentsAsync(texts.Select(x => new Document(x)).ToList()).Result; | ||
return index; | ||
} | ||
|
||
PromptTemplate CreatePromptTemplate() | ||
{ | ||
string prompt = "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n\n{context}\n\nQuestion: {question}\nHelpful Answer:"; | ||
var template = new PromptTemplate(new PromptTemplateInput(prompt, new List<string>() { "context", "question" })); | ||
return template; | ||
} | ||
|
||
} |
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