Provide implementations for HuggingFace 🤗 IChatCompletionService and TextEmbedding via Semantic Kernel? #753
Replies: 2 comments 2 replies
-
hi @jkone27 that's already possible, see |
Beta Was this translation helpful? Give feedback.
-
getting some errors, here is my sample ref. errors here: #659
// https://microsoft.github.io/kernel-memory/serverless #r "nuget: Microsoft.KernelMemory.SemanticKernelPlugin, 0.71.240820.1"
#r "nuget: Microsoft.KernelMemory.Core, 0.71.240820.1"
#r "nuget: Microsoft.SemanticKernel.Connectors.HuggingFace, 1.15.0-preview"
#r "nuget: Microsoft.SemanticKernel.Plugins.Memory, 1.15.0-alpha"
#r "nuget: SmartComponents.LocalEmbeddings.SemanticKernel, 0.1.0-preview10148"
open Microsoft.KernelMemory
open Microsoft.KernelMemory.SemanticKernelPlugin
open Microsoft.KernelMemory.Configuration
open Microsoft.KernelMemory.SemanticKernel
open Microsoft.SemanticKernel
open Microsoft.SemanticKernel.Connectors.HuggingFace
open System
open System.Threading.Tasks
open System.Linq
let config = new SemanticKernelConfig()
config.MaxTokenTotal <- 1000
let TEXT_MODEL = "microsoft/Phi-3-mini-4k-instruct"
let EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
let API_KEY = "TEST_KEY"
let ENDPOINT = "https://api-inference.huggingface.co/" |> Uri
let memory =
let chatConfig =
new HuggingFaceTextGenerationService(
TEXT_MODEL,
ENDPOINT,
API_KEY)
let embeddingConfig =
new HuggingFaceTextEmbeddingGenerationService(
EMBEDDING_MODEL,
ENDPOINT,
API_KEY)
(new KernelMemoryBuilder())
.WithSemanticKernelTextGenerationService(
service=chatConfig, config=config)
.WithSemanticKernelTextEmbeddingGenerationService(
service=embeddingConfig, config=config)
//.WithMemory(searchEndpoint, searchApiKey)
.Build<MemoryServerless>()
let results =
task {
let! _ = memory.ImportWebPageAsync(
"https://raw.githubusercontent.com/microsoft/kernel-memory/main/COMMUNITY.md",
documentId= "doc001")
let question = "How can I join Kernel Memory's Discord?"
Console.WriteLine($"\n\nQuestion: {question}")
let! answer = memory.AskAsync(question)
Console.WriteLine($"\nAnswer: {answer.Result}")
Console.WriteLine("\n\n Sources:\n")
for x in answer.RelevantSources do
Console.WriteLine(
$" - {x.SourceName} - {x.Link} [{x.Partitions.First().LastUpdate:D}]")
}
|> Async.AwaitTask
|> Async.RunSynchronously |
Beta Was this translation helpful? Give feedback.
-
would be nice and easy to use to add hugging face models via semantic kernel extensions
Microsoft.SemanticKernel.Connectors.HuggingFace
so people can experiment more with itwhich interfaces should be implemented to provide an huggingFace alternative to default openAI implementations?
this project seems really awesome, thank you
Beta Was this translation helpful? Give feedback.
All reactions