This file contains hidden or 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
# uv add asyncio azure-identity dotenv-azd openai-agents | |
from openai import AsyncAzureOpenAI | |
from agents import Agent, Runner, set_default_openai_client, set_tracing_export_api_key | |
from azure.identity import DefaultAzureCredential, get_bearer_token_provider | |
from dotenv import load_dotenv | |
from dotenv_azd import load_azd_env | |
import asyncio | |
import os |
This file contains hidden or 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
#!/usr/bin/env python | |
import rich_click as click | |
import json | |
from pathlib import Path | |
from dotenv import load_dotenv | |
from sys import stdout | |
from patchdiff import diff as patch_diff | |
load_dotenv() |
This file contains hidden or 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
# print env vars | |
cat .azure/test/.env | xargs -i echo {} | |
# use for a command and merge into current env | |
env $(cat .azure/test/.env | xargs) env | |
# use as a docker run --env-file | |
docker run -it --env-file <(cat .azure/test/.env | xargs -i echo {}) ubuntu env |
This file contains hidden or 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
#!/usr/local/bin/python3.12 | |
# -*- coding: utf-8 -*- | |
import re | |
import sys | |
# LiteLLM doesn't support DefaultAzureCredential and get_bearer_token_provider | |
# There has been a discussion on the subject but no clear path forward: | |
# See https://github.com/BerriAI/litellm/issues/4417 | |
# This monkey patches LiteLLM to force it to use the DefaultAzureCredential and get_bearer_token_provider |
This file contains hidden or 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
#!/bin/bash | |
dedup_env() { | |
local -A env_ary | |
while IFS== read -r key value; do | |
value=$(echo "$value" | sed 's/^ *"//' | sed 's/" *$//') | |
env_ary[$key]=$value | |
done <<EOM | |
$(cat $*) | |
EOM |
This file contains hidden or 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
var deployments = [ | |
{ | |
name: 'text-embedding-ada-002' | |
format: 'OpenAI' | |
} | |
{ | |
name: 'llama' | |
format: 'serverless' | |
} | |
] |
This file contains hidden or 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
from typing import Any | |
def constant_hash(func): | |
""" | |
Wraps a function and changes its hashing behavior to a constant. | |
This allows Hugginface to only use functiona parameters for hashing and nothing else in | |
the function's captured context | |
""" | |
return ConstantHash(func) |
This file contains hidden or 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
# Those endpoints don't use the usual Azure OpenAI scheme, they use the OpenAI scheme. | |
# They also take the model field to route to the proper deployment, but I haven't verified this works | |
# Tested with openai 1.13.3 | |
from openai import OpenAI | |
import logging | |
logging.basicConfig(level=logging.DEBUG, | |
format='%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)d - %(message)s', |
This file contains hidden or 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
# Generate a UUID5 from a name using SHA-256 | |
def uuid5_sha256(namespace, name): | |
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" | |
if isinstance(name, str): | |
name = bytes(name, "utf-8") | |
from uuid import UUID | |
import hashlib | |
hash = hashlib.sha256(namespace.bytes + name).digest() | |
return UUID(bytes=hash[:16], version=5) |
This file contains hidden or 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
import os | |
import yaml | |
import logging.config | |
import logging | |
import coloredlogs | |
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'): | |
""" | |
| **@author:** Prathyush SP | |
| Logging Setup |
NewerOlder