Skip to content

Instantly share code, notes, and snippets.

View arafattehsin's full-sized avatar
🎯
Focusing

Arafat Tehsin arafattehsin

🎯
Focusing
View GitHub Profile
// Get embeddings of an riddle / landmark answer
public async Task<IList<ReadOnlyMemory<float>>> GetEmbeddings(string answer)
{
return await textEmbeddingGeneration.GenerateEmbeddingsAsync(new List<string> { answer });
}
// Calculate Cosine Similarity between two answers
public async Task<double> CalculateSimilarity(IList<ReadOnlyMemory<float>> origEmbedding, string guessedAnswer)
{
try
public async Task<Riddle> GetRiddle()
{
try
{
string skPrompt = @"Ask an interesting new riddle with its answer in a below json format. It should only contain a JSON message and nothing else. It should not have anything racist, unethical or targeted to certain group of people.
{
""Question"": """",
public bool SetSettingsToStorage(Settings settings)
{
Preferences.Default.Set(nameof(settings.Model), settings.Model);
Preferences.Default.Set(nameof(settings.EndpointKey), settings.EndpointKey);
Preferences.Default.Set(nameof(settings.IsUseOpenAI), settings.IsUseOpenAI);
Preferences.Default.Set(nameof(settings.EndpointURL), settings.EndpointURL);
Preferences.Default.Set(nameof(settings.EmbeddingModel), settings.EmbeddingModel);
Preferences.Default.Set(nameof(settings.OrgId), settings.OrgId);
return true;
}
public async Task<List<Country>> LoadCountries()
{
try
{
using var stream = await FileSystem.OpenAppPackageFileAsync("countries.json");
using var reader = new StreamReader(stream);
var contents = reader.ReadToEnd();
var countries = JsonSerializer.Deserialize<List<Country>>(contents);
return countries;
}
@arafattehsin
arafattehsin / Simulator.cs
Created October 31, 2022 12:13
This is a sample for the Simulator used for Azure Personalizer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Simulator
{
public class Simulator
{
@arafattehsin
arafattehsin / UserSimulator.cs
Created October 27, 2022 23:01
This is a sample User Simulator class for Azure Personalizer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Simulator
{
public class UserSimulator
{
@arafattehsin
arafattehsin / GetFlightDetails.cs
Created February 23, 2020 08:45
This is a sample Azure function without any real API implementation for Flight Tracker.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
@arafattehsin
arafattehsin / Immersive Reader (Cognitive Service) Controller
Created December 9, 2019 01:18
This is a sample Controller for obtaining a token for Immersive Reader Cognitive Service
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ImmersiveReaderDemo.Models;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
@arafattehsin
arafattehsin / VABot.cs
Created October 30, 2019 06:53
Excerpt from the main Bot class; for complete code, please refer to CognitiveRocket repo.
private async Task ProcessVABotAsync(ITurnContext<Microsoft.Bot.Schema.IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var token = await _botServices.VABotService.GetTokenAsync();
using (var directLineClient = new DirectLineClient(token))
{
var conversation = await directLineClient.Conversations.StartConversationAsync();
var conversationtId = conversation.ConversationId;
var response = await directLineClient.Conversations.PostActivityAsync(conversationtId, new Microsoft.Bot.Connector.DirectLine.Activity()
@arafattehsin
arafattehsin / BotServices.cs
Created October 30, 2019 06:46
Class to read configuration and assigning them to the respective language models and knowledge sources such as LUIS, QnA and Virtual Agent
public class BotServices : IBotServices
{
public BotServices(IConfiguration configuration)
{
// Read the setting for cognitive services (LUIS, QnA) from the appsettings.json
// If includeApiResults is set to true, the full response from the LUIS api (LuisResult)
// will be made available in the properties collection of the RecognizerResult
VABotDispatch = new LuisRecognizer(new LuisApplication(
configuration["LuisAppId"],
configuration["LuisAPIKey"],