Skip to content

Instantly share code, notes, and snippets.

View sergenes's full-sized avatar
🏠
Working from home

Sergey Nes sergenes

🏠
Working from home
View GitHub Profile
import anthropic_bedrock
from anthropic_bedrock import AnthropicBedrock
aws_access_key = os.getenv('AWS_ACCESS_KEY')
aws_secret_key = os.getenv('AWS_SECRET_KEY')
abclient = AnthropicBedrock(
# Authenticate by either providing the keys below or use the default AWS credential providers, such as
# using ~/.aws/credentials or the "AWS_SECRET_ACCESS_KEY" and "AWS_ACCESS_KEY_ID" environment variables.
aws_access_key=aws_access_key,
from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
anthropic_api_key = os.getenv('ANTHROPIC_API_KEY_1')
anthropic = Anthropic(api_key=anthropic_api_key)
def get_anthropic_completion(prompt, model="claude-2.1"):
completion = anthropic.completions.create(
model=model,
max_tokens_to_sample=1000,
temperature=0.2,
import requests
perplexity_api_key = os.getenv('PERPLEXITY_API_KEY_1')
purl = "https://api.perplexity.ai/chat/completions"
pheaders = {
"accept": "application/json",
"authorization": f'Bearer {perplexity_api_key}',
"Content-Type": "application/json"
}
@sergenes
sergenes / openai.alternatives.openai.py
Created December 10, 2023 15:08
Open AI API completion function
import openai
openai.api_key = os.getenv('OPENAI_API_KEY_1')
def get_open_ai_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
open_ai_response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0.2,
@sergenes
sergenes / openai.alternatives.setup.py
Last active December 10, 2023 15:04
Terminal commands to configure the environment for direct access and access through Amazon Bedrock
# Setup commands you'll need to configure the environment
conda activate ~/opt/anaconda3
~/opt/anaconda3/bin/conda install -p ~/opt/anaconda3 anthropic -y
pip install anthropic
pip install ai21
pip install openai
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
@sergenes
sergenes / PreviewLogger.swift
Last active December 11, 2023 04:50
SwiftUI Live Preview Logger
#pragma mark - Article: https://sergey-nes.medium.com/enhance-your-swiftui-live-preview-workflow-with-previewlogger-6c768e7362a5
import SwiftUI
#pragma mark - ContentView
struct ContentView: View {
@EnvironmentObject var previewLogger: PreviewLogger
var body: some View {
//first
dispatch_async(queue, ^{
dispatch_group_t group1 = dispatch_group_create();
// Tasks goes here
for (NSInteger i = 0; i < 3; i++) {
@sergenes
sergenes / lambda.js
Created October 11, 2022 20:10 — forked from phrozenra/lambda.js
Google in app purchase validation using AWS Lambda
import ApiBuilder from "claudia-api-builder";
import fetch from "node-fetch";
import FormData from "form-data";
let api = new ApiBuilder();
const verifyAndroidReceipt = req => {
// setup credentials
const config = {
client_id: "<fill in>",
fun done() { onAction(ListScreenActions.OnDone(state()))}
fun save(runBefore: () -> Unit) {
onAction(ListScreenActions.OnSave(state()), runBefore = runBefore)
}
fun backToPrevState() {
state().back?.let {
screenState.value = it
}
fun selectedRow(runAfter: () -> Unit) {
onAction(ListScreenActions.OnSelectRow, runAfter = runAfter)
}
fun editSelectedRow(){ onAction(ListScreenActions.OnSelectedRowChanged) }