Skip to content

Instantly share code, notes, and snippets.

@waf
waf / Program.cs
Last active July 21, 2024 13:30
Complete program that plays MineSweeper in the terminal in 100 non-whitespace lines of code. Ported from https://radanskoric.com/experiments/minesweeper-100-lines-of-clean-ruby
if (args.Length == 3)
{
Play(args.Select(int.Parse).ToArray());
}
else
{
Console.WriteLine("Usage: Minesweeper width height mineCount (e.g. Minesweeper 12 6 6)");
}
static void Play(params int[] args)
@adlumal
adlumal / goalchain_example.py
Last active May 26, 2024 09:07
GoalChain example
from goalchain import Field, ValidationError, Goal, GoalChain
import os
os.environ["OPENAI_API_KEY"] = "sk-ABC..." # SPECIFY OPENAI API KEY
def quantity_validator(value):
try:
value = int(value)
except (ValueError, TypeError):
raise ValidationError("Quantity must be a valid number")
@Cortexelus
Cortexelus / udio.py
Last active May 10, 2024 12:59
Automate Udio (2024-04-13)
# AUTOMATE UDIO
# by DADABOTS dadabots.com
# was working on 2024-04-13
# tldr; get your login cookie, use it to automate udio from python
import requests
import json
from time import sleep
import re
@ivanfioravanti
ivanfioravanti / gist:bcacc48ef68b02e9b7a4034161824287
Created January 25, 2024 00:01
Fine tuning dataset generation wiht Ollama python library
import json
import os
import ollama
def query_ollama(prompt, model='openhermes:7b-mistral-v2.5-q6_K', context=''):
response = ollama.generate(
model=model,
prompt=context + prompt)
return response['response'].strip()
@0xc1c4da
0xc1c4da / lmql_babyagi.py
Created August 19, 2023 11:27
Basic BabyAGI Implementation in LMQL
import lmql
from dataclasses import dataclass
from typing import List
# Data Structures
@dataclass
class Task:
task: str
# result: str
@zhibor
zhibor / main.py
Created August 8, 2023 23:10
QA Chatbot streaming with source documents example using FastAPI, LangChain Expression Language, OpenAI, and Chroma.
"""QA Chatbot streaming using FastAPI, LangChain Expression Language , OpenAI, and Chroma.
Features
--------
- Persistent Chat Memory:
Stores chat history in a local file.
- Persistent Vector Store:
Stores document embeddings in a local vector store.
- Standalone Question Generation:
Rephrases follow-up questions to standalone questions in their original language.
@JustMaier
JustMaier / example.md
Created August 4, 2023 15:58
ChatGPT contextual conversation starter prompt

You are an AI Prompt engineer at OpenAI and you have just found the best prompt for effectively starting conversations with ChatGPT, an AI language model and assistant. Write an effective beggining prompt that can be used to start a conversation with ChatGPT. The prompt should:

  1. start with a persona
  2. provide relevant context for that persona to be performing the requested function
  3. Briefly outline the task they've been requested to perform
  4. Request they follow a given format
  5. Describe the tone they should use
  6. Provide them a brief example of what you're looking for Use clear and concise language and write in a confident yet friendly tone. Use this request as an example:

"You are a senior product marketing manager at Apple and you just launched the latest Apple product, the Apple Car, and received 12,000 pre-orders, which is 200% higher than target. Write an email to your boss, Tim Cooke, sharing this positive news. The email should follow the exact same format as the one I will share below. Use c

import os
import openai
import time
os.environ["OPENAI_API_KEY"] = <your API key>
openai.api_key = os.getenv("OPENAI_API_KEY")
# Starting templates
INQUIRY_PERSONA_starting_template = """
Act as a {INQUIRY_PERSONA}. I {TASK}.
@xec-abailey
xec-abailey / README.md
Last active April 16, 2024 08:25
ChatGPT Research Assistance Prompt

Research Assistant Prompt

This prompt provides a really responsive, interactive research assistant that will give you markdown-formatted, concise responses with code examples and optional follow-up questions. At the end of every answer it will give a list of 5 questions to continue with the topic (by using command "continue: #") or you can prompt with a completely new question.

Variables

  • PERSONA - change this to modify what type of information you want the AI to be an expert in
  • LANGUAGE - change this to modify what language the code examples are in
  • NUM_SUGGESTIONS - change this to modify number of suggested followup questions
@anonymousmaharaj
anonymousmaharaj / chatgpt-stable-diffusion-generate-prompt
Created April 8, 2023 21:02
Prompt for ChatGPT to generate correct prompts to SD. You can leave comment to improve it.
I want you to help me make requests (prompts) for the Stable Diffusion neural network.
Stable diffusion is a text-based image generation model that can create diverse and high-quality images based on your requests. In order to get the best results from Stable diffusion, you need to follow some guidelines when composing prompts.
Here are some tips for writing prompts for Stable diffusion1:
1) Be as specific as possible in your requests. Stable diffusion handles concrete prompts better than abstract or ambiguous ones. For example, instead of “portrait of a woman” it is better to write “portrait of a woman with brown eyes and red hair in Renaissance style”.
2) Specify specific art styles or materials. If you want to get an image in a certain style or with a certain texture, then specify this in your request. For example, instead of “landscape” it is better to write “watercolor landscape with mountains and lake".
3) Specify specific artists for reference. If you want to get an image similar to the work of some