Wednesday, August 30, 2023

Semantic Kernel Tutorial for Beginners

 This guide shows you how to create semantic function in semantic kernel in Python with code example and explain the concepts in simple language.




Commands Used:


!pip install semantic-kernel !pip install torch !pip install transformers !pip install sentence-transformers !pip install huggingface_hub from huggingface_hub import notebook_login notebook_login() import semantic_kernel as sk import semantic_kernel.connectors.ai.hugging_face as sk_hf kernel = sk.Kernel() kernel.add_text_completion_service( "gpt2", sk_hf.HuggingFaceTextCompletion("gpt2", task="text-generation") ) prompt = """ {{$input}} Summarize the content above in less than 100 characters. """ summary_function = kernel.create_semantic_function(prompt_template = prompt, description="Summary example of SK", max_tokens=200, temperature=0.1, top_p=0.5) print("Semantic Function Created."); text = """ Oracle Database is the world's most popular database. Available on cloud and on-premise platforms, Oracle Database 19c is the most recent long term release, with an extended support window. Oracle Database 21c is the latest innovation release, initially available on Oracle cloud through Autonomous Database Free Tier and Database Cloud Service. Oracle Cloud is a cloud computing service offered by Oracle Corporation providing servers, storage, network, applications and services through a global network of Oracle Corporation managed data centers. The company allows these services to be provisioned on demand over the Internet. Oracle Cloud Infrastructure (OCI) is a set of complementary cloud services that enable you to build and run a range of applications and services in a highly available hosted environment. OCI provides high-performance compute capabilities (as physical hardware instances) and storage capacity in a flexible overlay virtual network that is securely accessible from your on-premises network. """; summary_result = summary_function(text) print("### Summary=> " + str(summary_result))


# Text Source is Oracle Docs

No comments: