Skip to content

Instantly share code, notes, and snippets.

View decagondev's full-sized avatar

Tom Tarpey decagondev

  • Decagon Development
  • UK
View GitHub Profile

Step 1: Setting Up the Environment

First, we need to install Pygame if it's not already installed. You can do this by running:

pip install pygame

Step 2: Importing Required Modules

At the beginning of our script, we import necessary modules from Pygame:

Recommended Workflow for Python Project with Docker

1. Set Up Project Directory

mkdir my_project
cd my_project

2. Create Virtual Environment (Optional for Local Development)

Recommended Workflow for Python Project with Docker

1. Set Up Project Directory

mkdir my_project
cd my_project

2. Create Virtual Environment (Optional for Local Development)

Chat Agent with Persistent Conversations

To create a custom chat agent with persistent conversation contexts, you have several options for storing and managing the conversation data. Both SQL and graph databases can be used effectively, depending on your specific requirements and preferences. Here’s a detailed comparison and guidance on implementing persistence with each type:

SQL Database Implementation

A SQL database is a good choice if your data model is relatively simple and you prefer a structured, relational approach. Here’s how you could implement it:

1. Schema Design

  • Users Table: Stores user information.
  • Conversations Table: Stores conversation metadata, including a reference to the user.
@decagondev
decagondev / raggy.py
Created May 24, 2024 16:18
Rag example with llama index
import os
import fitz # PyMuPDF
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor, ServiceContext, Document
from llama_index.prompts import PromptTemplate
from ollama_llama import Llama
class PDFDirectoryReader(SimpleDirectoryReader):
def __init__(self, directory_path):
self.directory_path = directory_path

System Prompt vs. Constitutional Chain

System Prompt

  1. Definition:

    • A system prompt is an initial instruction or set of instructions given to an AI model to guide its behavior or responses. It sets the context for the interaction and can influence the tone, style, and focus of the generated content.
  2. Purpose:

    • To establish the framework within which the AI operates, ensuring responses are relevant and aligned with the desired objectives.
  • Examples include setting a conversational style (formal/informal), specifying the type of information to provide (technical/general), or instructing the AI to perform specific tasks.
@decagondev
decagondev / langchain_v_llama_index.md
Created May 21, 2024 01:25
Langchain Vs Llama Index

LangChain and LlamaIndex (formerly known as GPT Index) are both frameworks designed to facilitate working with large language models (LLMs) and building AI-driven applications. Each has its strengths, and the choice between them can depend on specific needs and use cases. Below are some comparative advantages of using LangChain over LlamaIndex:

Advantages of LangChain

  1. Comprehensive Tooling and Ecosystem:

    • LangChain provides a broad set of tools and modules that simplify the integration of LLMs into applications. This includes utilities for prompt management, chains (sequences of calls to LLMs), memory (storing and recalling information during interactions), and more.
    • It integrates well with various external tools and data sources, enhancing the model’s capabilities.
  2. Flexibility and Customization:

  • LangChain allows for highly customizable and flexible pipelines, enabling developers to create complex workflows involving multiple steps and decision points.
@decagondev
decagondev / openai_api_endpoints.md
Created May 21, 2024 01:19
Open AI Api Endpoints

OpenAI provides a variety of API endpoints for interacting with their models, including those for text generation, embeddings, fine-tuning, and more. Here are some key endpoints you can use:

  1. Completions: For generating text based on a prompt.
    • Endpoint: POST https://api.openai.com/v1/engines/{engine_id}/completions
    • Example:
      {
        "model": "text-davinci-003",
        "prompt": "Once upon a time,",

"max_tokens": 100,

@decagondev
decagondev / build.gradle
Created March 28, 2024 20:19
gcp firebase
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.6.1'
}
}
plugins {
{
"openapi": "3.0.0",
"info": {
"title": "Sample API",
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
"version": "0.1.9"
},
"servers": [
{
"url": "http://api.example.com/v1",