Skip to content

Instantly share code, notes, and snippets.

View AIAnytime's full-sized avatar
👋
On vacation

AI Anytime AIAnytime

👋
On vacation
View GitHub Profile
@AIAnytime
AIAnytime / Modelfile.txt
Created August 25, 2024 06:19
Modelfile ollama
FROM ./Llama-3-ELYZA-JP-8B-q4_k_m.gguf
TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|>
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
{{ .Response }}<|eot_id|>"""
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from openai import OpenAI
from dotenv import load_dotenv
import os
load_dotenv()
app = FastAPI()
client = OpenAI()
@AIAnytime
AIAnytime / reader.py
Created April 15, 2024 18:20
Jina Reader API
import requests
# Base endpoint
base_url = "https://r.jina.ai/"
# Input URL to be appended
input_url = "https://www.stateof.ai/"
# Full URL with the input URL appended after a plus (+) sign
full_url = base_url + input_url
@AIAnytime
AIAnytime / sci.py
Created April 13, 2024 11:33
carbon sci
import streamlit as st
# App title
st.title('EcoOptimizer Carbon Footprint Calculator')
# Introduction
st.write('''
This tool calculates the Software Carbon Intensity (SCI) for EcoOptimizer,
an AI-powered energy management system for commercial buildings by EcoTech Solutions.
''')
@AIAnytime
AIAnytime / training_args.py
Created April 10, 2024 08:01
Training Arguments
training_arguments = TrainingArguments(
output_dir="./results",
per_device_train_batch_size=4,
per_device_eval_batch_size=4,
gradient_accumulation_steps=2,
optim="adamw_8bit",
logging_steps=50,
learning_rate=1e-4,
evaluation_strategy="steps",
do_eval=True,
@AIAnytime
AIAnytime / eval.py
Created March 23, 2024 12:58
Evaluation after FT LLM
## With Evaluation Harness
!pip install git+https://github.com/EleutherAI/lm-evaluation-harness.git
!pip install bitsandbytes
!pip install --upgrade transformers
!pip install auto-gptq optimum autoawq
!lm_eval --model hf --model_args pretrained=google/gemma-7b --tasks winogrande,hellaswag,arc_challenge --device cuda:0 --num_fewshot 1 --batch_size 8 --output_path ./eval_harness/gemma-7b
!lm_eval --model hf --model_args pretrained=google/gemma-7b --tasks winogrande,hellaswag,arc_challenge --device cuda:0 --num_fewshot 5 --batch_size 8 --output_path ./eval_harness/gemma-7b-5shot
@AIAnytime
AIAnytime / runpod.py
Created February 8, 2024 09:54
RunPod Code
import os
#set you runpod key as a environment variable
os.environ['RUNPOD_API_KEY'] = "your_runpod_api_key"
import runpod
from IPython.display import display, Markdown
runpod.api_key = os.getenv("RUNPOD_API_KEY", "your_runpod_api_key")
if runpod.api_key == "your_runpod_api_key":
@AIAnytime
AIAnytime / script.txt
Created November 8, 2023 10:53
Demo Script
Hello everyone, I am Sneha Roy, working as a full-stack AI Engineer and recently I have been working on Generative AI projects.
Today, I will be showcasing a solution that we have developed.........."GCC KB Chatbot".
it is an intelligent assistant tailored to simplify how call centers operate, in this case.. the GCC team.
GCC faces a significant challenge managing a high volume of tickets daily.
Each of these tickets is needing assistance, and each minute spent resolving one is critical.
Traditionally, our colleagues at GCC relied on a comprehensive but cumbersome Knowledge Base (KB) to find solutions,
which significantly contributed to longer turnaround times.
That's where our solution comes in... it drastically reduces the time taken to resolve tickets. Acting as a virtual agent,
@AIAnytime
AIAnytime / semantic_sim.py
Created October 30, 2023 10:02
semantic sim
import torch
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')
def encode(text):
tokens = tokenizer.tokenize(text)
tokens = ['[CLS]'] + tokens + ['[SEP]']
return tokenizer.convert_tokens_to_ids(tokens)
@AIAnytime
AIAnytime / top_p.text
Created October 30, 2023 08:09
top p top k thing
Nucleus sampling is a technique used in large language models to control the randomness and diversity of generated text. It works by sampling from only the most likely tokens in the model’s predicted distribution.
The key parameters are:
Temperature: Controls randomness, higher values increase diversity.
Top-p (nucleus): The cumulative probability cutoff for token selection. Lower values mean sampling from a smaller, more top-weighted nucleus.
Top-k: Sample from the k most likely next tokens at each step. Lower k focuses on higher probability tokens.