Git Product home page Git Product logo

pycodeagi's Introduction

pyCodeAGI

A small AGI experiment to generate a Python app given what app the user wants to build. The project just started, so please keep an eye on the updates.

It's very early, but run the script to try out the AGI.

Of course, it uses LangChainAI. AGI concept adopted from @yoheinakajima's BabyAGI.

pycodeagi's People

Contributors

chakkaradeep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pycodeagi's Issues

Max token length exceeded error

Running pycodeagi.py, got a max token length exceeded error at the "APP CODE" step:

Traceback (most recent call last):
  File "pycodeagi.py", line 165, in <module>
    pycode_agi({"objective": objective})

openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens, however you requested 4170 tokens (1170 in your prompt; 3000 for the completion). Please reduce your prompt; or completion length.

TicTacToe

image
image

import streamlit as st
import sqlite3
import pandas as pd
import numpy as np
from random import choice

# Global state class to store game data
class GlobalState:
    def __init__(self):
        self.conn = sqlite3.connect("tictactoe.db")
        self.create_tables()

    def create_tables(self):
        cursor = self.conn.cursor()
        cursor.execute("""
            CREATE TABLE IF NOT EXISTS game_history (
                id INTEGER PRIMARY KEY,
                opponent TEXT,
                difficulty TEXT,
                result TEXT
            )
        """)
        self.conn.commit()

    def add_game(self, opponent, difficulty, result):
        cursor = self.conn.cursor()
        cursor.execute("""
            INSERT INTO game_history (opponent, difficulty, result)
            VALUES (?, ?, ?)
        """, (opponent, difficulty, result))
        self.conn.commit()

    def get_game_history(self):
        cursor = self.conn.cursor()
        cursor.execute("SELECT * FROM game_history")
        return pd.DataFrame(cursor.fetchall(), columns=["id", "opponent", "difficulty", "result"])


# Initialize global state
state = GlobalState()

# Game logic functions
def init_board():
    return np.full((3, 3), "")

def check_win(board):
    for row in board:
        if len(set(row)) == 1 and row[0] != "":
            return True
    for col in board.T:
        if len(set(col)) == 1 and col[0] != "":
            return True
    if len(set(board.diagonal())) == 1 and board[0, 0] != "":
        return True
    if len(set(np.fliplr(board).diagonal())) == 1 and board[0, 2] != "":
        return True
    return False

def check_draw(board):
    return not np.any(board == "")

def make_move(board, row, col, symbol):
    if board[row, col] == "":
        board[row, col] = symbol
        return True
    return False

def ai_move(board, difficulty):
    if difficulty == "easy":
        empty_cells = np.argwhere(board == "")
        return choice(empty_cells)
    elif difficulty == "medium":
        # Implement medium difficulty AI logic
        pass
    elif difficulty == "hard":
        # Implement hard difficulty AI logic
        pass
    return None

# Main app layout
st.title("TicTacToe Master")
st.write("Play the classic TicTacToe game against an AI opponent or another human player.")

opponent = st.sidebar.selectbox("Choose your opponent", ["AI", "Human"])
if opponent == "AI":
    difficulty = st.sidebar.selectbox("AI difficulty", ["easy", "medium", "hard"])
else:
    difficulty = None

if st.sidebar.button("Restart Game"):
    board = init_board()
else:
    board = state.board if hasattr(state, "board") else init_board()

for i in range(3):
    row_data = board[i]
    row_result = st.button(row_data[0], key=f"cell_0_{i}") or st.button(row_data[1], key=f"cell_1_{i}") or st.button(row_data[2], key=f"cell_2_{i}")
    if row_result:
        col = int(row_result.split("_")[1])
        row = int(row_result.split("_")[2])
        if opponent == "Human":
            symbol = "X" if state.turn == "X" else "O"
            if make_move(board, row, col, symbol):
                state.turn = "O" if state.turn == "X" else "X"
        else:
            if make_move(board, row, col, "X"):
                if not check_win(board) and not check_draw(board):
                    ai_row, ai_col = ai_move(board, difficulty)
                    make_move(board, ai_row, ai_col, "O")

if check_win(board):
    st.write("Game Over: Win")
    state.add_game(opponent, difficulty, "win")
elif check_draw(board):
    st.write("Game Over: Draw")
    state.add_game(opponent, difficulty, "draw")
else:
    st.write("Game in Progress")

game_history = state.get_game_history()
st.write("Game History")
st.write(game_history)

state.board = board



I asked him to build a tictactoe game, it doesn't work but the interface looks great. I guess it should try to test the interface and correct mistakes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.