Skip to content

Instantly share code, notes, and snippets.

@maxim-saplin
maxim-saplin / reflection.txt
Created September 13, 2024 10:31
Reflection system prompt
You are an AI assistant designed to provide detailed, step-by-step responses. Your outputs should follow this structure:
1. Begin with a <thinking> section.
2. Inside the thinking section:
a. Briefly analyze the question and outline your approach.
b. Present a clear plan of steps to solve the problem.
c. Use a "Chain of Thought" reasoning process if necessary, breaking down your thought process into numbered steps.
3. Include a <reflection> section for each idea where you:
a. Review your reasoning.
b. Check for potential errors or oversights.
@maxim-saplin
maxim-saplin / falcon_mamaba_7b.py
Created August 20, 2024 12:00
Chat to Falcone Mamba 7B
# pip install -U git+https://github.com/huggingface/transformers.git
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
import torch
import time
def chat_with_ai(model, tokenizer):
"""
Function to simulate chatting with the AI model via the command line.
@maxim-saplin
maxim-saplin / test.py
Created December 10, 2023 21:01
Python, equality vs list membership
def is_special_number(number):
if number == 7:
return True
elif number == 18:
return True
else:
return False
def is_special_number_2 (number):
return number in [7, 18]
@maxim-saplin
maxim-saplin / functional.dart
Last active October 29, 2023 13:07
Example of functional style in Dart using features from version 3.1
// sealed classes are abstract (can't be instatiated) and can only be
// implemented in the same library (library in Dart is one file be default)
sealed class Message {
}
class TextMessage implements Message {
final String content;
TextMessage(this.content);
}
@maxim-saplin
maxim-saplin / julia.py
Last active May 19, 2024 09:20
Simple integration of Dart/Flutter and Python
# https://matplotlib.org/matplotblog/posts/animated-fractals/
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
x_start, y_start = -2, -2 # an interesting region starts here
width, height = 4, 4 # for 4 units up and right
density_per_unit = 80 # how many pixles per unit
@maxim-saplin
maxim-saplin / main.dart
Last active September 11, 2023 08:10
`main.dart` from Flutter-Pyhton Starter Kit with gRPC
import 'dart:math';
import 'dart:ui';
import 'package:app/grpc_generated/client.dart';
import 'package:app/grpc_generated/init_py.dart';
import 'package:app/grpc_generated/init_py_native.dart';
import 'package:app/grpc_generated/service.pbgrpc.dart';
import 'package:flutter/material.dart';
Future<void> pyInitResult = Future(() => null);
@maxim-saplin
maxim-saplin / openai_function_calling.ts
Created September 5, 2023 05:42
Open AI function calling to enforce LLM response structure/format
import dotenv from "dotenv";
const API_KEY = process.env.API_KEY;
const API_ENDPOINT = process.env.API_ENDPOINT; // ?api-version=2023-07-01-preview is required as of August 2023
const validate = async (name: string, project: string, role: string, category: string, feedback: string, summary: string): Promise<{ status: string, recommendations: string }> => {
var nominee = generateNomineeString(name, project, role, category, feedback, summary);
// Using function call capability of OpenAI API to ensure response is properly formatted JSON
// Before function calling I asked to reply via JSON, one of side effect was that in 'recomendations'
import 'dart:math';
const String h = 'kjddHjblwoopwedlradljljlkdfefldlkfdog dgdfgdf';
abstract class A {
String getMessage() => 'A';
}
class B {
String getMessage() => 'B';