Skip to content

Instantly share code, notes, and snippets.

@pavlovmilen
pavlovmilen / query_by_text_async.cs
Last active April 8, 2024 16:09
Query ChromaDb call in c#
public async Task<ChromaDbResult> QueryByTextAsync(string queryText)
{
try
{
var payload = new { parameters = new { query_text = queryText, n_results = 2 } };
string jsonPayload = JsonConvert.SerializeObject(payload);
var requestContent = new StringContent(jsonPayload, System.Text.Encoding.UTF8, "application/json");
var response = await _client.PostAsync("query", requestContent);
@pavlovmilen
pavlovmilen / chat_completions_api.cs
Last active April 8, 2024 14:41
Chat completion api usage
var url = _configuration.GetValue<string>("AzureOpenAiApi:Endpoint");
var key = _configuration.GetValue<string>("AzureOpenAiApi:SubscriptionKey");
var openAIClient = new OpenAIClient(new Uri(url), new AzureKeyCredential(key));
Response<ChatCompletions> responseWithoutStream =
await openAIClient.GetChatCompletionsAsync(
new ChatCompletionsOptions()
{
Messages =
{
@pavlovmilen
pavlovmilen / azure_open_ai_client_code.cs
Created April 8, 2024 13:22
Azure Open AI client code
//https://youropenaiinstance.openai.azure.com/
//c#
// Note: The Azure OpenAI client library for .NET is in preview.
// Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5
using Azure;
using Azure.AI.OpenAI;
OpenAIClient client = new OpenAIClient(
new Uri("https://youropenaiinstance.openai.azure.com/"),
new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")));
@pavlovmilen
pavlovmilen / kubernetes_files.yaml
Created March 10, 2024 09:25
ChromaDb Kubernetes files
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: chromadb
spec:
replicas: 1
selector:
matchLabels:
app: chromadb
@pavlovmilen
pavlovmilen / Dockerfile
Created March 10, 2024 09:10
Dockerfile for chromadb app
# Use the official chromadb image
FROM chromadb/chroma:0.4.21
# Set environment variables
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_RUN_PORT=8000
# Set the working directory
WORKDIR /app
@pavlovmilen
pavlovmilen / app.py
Created March 10, 2024 09:06
Python flask app exposing ChromaDb operations as rest endpoints
from flask import Flask, request
from flask_restful import Api, Resource
import requests
import os
import json
import traceback
import chromadb
from openai import AzureOpenAI
import chromadb.utils.embedding_functions as embedding_functions
@pavlovmilen
pavlovmilen / readme.md
Last active August 10, 2023 16:24
Azure AKS add nginx ingress with Lets encrypt Cluster Issuer how to guide
  1. Create IP address az network public-ip create --resource-group resources_ml-aks-uks_ml-aks-uks --name pip-ml-aks-uks --sku Standard --allocation-method static --query publicIp.ipAddress -o ts

  2. Create a namespace for your ingress resources kubectl create namespace nginx-ingress

  3. Add the official stable repository helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo add stable https://charts.helm.sh/stable
    helm repo update

@pavlovmilen
pavlovmilen / kubectl_commands.txt
Created January 28, 2023 18:27
Kubectl cheatsheet
1. Set default context
kubectl config set-context --current --namespace=my-namespace
2. Exec in to pod
kubectl exec -it my-pod -- /bin/sh (may have to exec on cloud cli)
@pavlovmilen
pavlovmilen / Local-Kubernetes.md
Created January 21, 2022 09:06 — forked from dahlsailrunner/Local-Kubernetes.md
Helpful tips and snippets for Kubernetes within Docker Desktop

Using the K8s Dashboard Locally

Actual repo is here: https://github.com/kubernetes/dashboard

1. Install the Dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml

2. Create a Sample User Account that can Access the Dashboard via Token

kubectl apply -f https://gist.githubusercontent.com/dahlsailrunner/bbd453f3bb6259b66c08a70d0908283f/raw/5727723217e2df4b65d8933adf04d009cfb0fe3f/local-dashboard-account.yml
@pavlovmilen
pavlovmilen / AzureDependencyFilterTelemetryProcessor
Last active May 5, 2021 16:49
filters out dependencies like polling queues that are not attached to any larger operation.
/// filters out dependencies like polling queues that are not attached to any larger operation.
public class AzureDependencyFilterTelemetryProcessor : ITelemetryProcessor
{
private readonly ITelemetryProcessor _inner;
public AzureDependencyFilterTelemetryProcessor(ITelemetryProcessor inner)
{
_inner = inner;
}