Skip to content

Commit

Permalink
Change to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
nervousapps committed Feb 20, 2024
1 parent 2ab123c commit 48f249d
Show file tree
Hide file tree
Showing 23 changed files with 290 additions and 190 deletions.
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenAI stuff
KEYFILE="./openai_key.txt"
MODEL_NAME="lunademo"
LOCAL_AI_URL="http://localhost:8080/v1"
LOCAL_AI_URL=http://172.29.221.52:5000/v1/

# General
INTERACTIVE="no"
Expand Down
1 change: 1 addition & 0 deletions examples/webgpt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
WebGPT is an AI driven enterprise that develop website for its clients.
"""

import os
import openai
from gpt_enterprise.gpt_utils import (
Expand Down
1 change: 1 addition & 0 deletions python/gpt_enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
The scrum master will then create a sequence of tasks, each associated to an employee previously hired by the team leader.\n
At the end, all tasks result will be returned to the CEO.\n
"""

from .__main__ import main
5 changes: 2 additions & 3 deletions python/gpt_enterprise/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
GPTenterprise is an AI driven enterprise.
"""

import os
import sys
import asyncio
Expand All @@ -23,10 +24,8 @@ def main():

if local_ai_url:
# Change api url to LoacalAi one
openai.api_base = local_ai_url
openai.base_url = local_ai_url
openai.api_key = "sx-xxx"
OPENAI_API_KEY = "sx-xxx"
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
else:
# Initialize openai api_key
with open("./openai_key.txt", "r") as file:
Expand Down
1 change: 1 addition & 0 deletions python/gpt_enterprise/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Employee
\U0001F469
"""

import os
from typing import List, Tuple

Expand Down
1 change: 1 addition & 0 deletions python/gpt_enterprise/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Enterprise
\U0001F3E2
"""

import os

from gpt_enterprise.team_leader import TeamLeader
Expand Down
55 changes: 32 additions & 23 deletions python/gpt_enterprise/gpt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
GPT utils
\U0001F9E0
"""

import os
import openai
import requests
Expand All @@ -13,7 +14,10 @@


def generate_text(
system_prompt: str, user_prompt: str, temperature: float, model: str = os.getenv("MODEL_NAME", "gpt-3.5-turbo-16k")
system_prompt: str,
user_prompt: str,
temperature: float,
model: str = os.getenv("MODEL_NAME", "gpt-3.5-turbo-16k"),
) -> Generator:
"""
Expand All @@ -27,7 +31,7 @@ def generate_text(
Returns:
Generator: GPT response object
"""
response = openai.ChatCompletion.create(
response = openai.chat.completions.create(
model=model,
messages=[
# Initialize GPT with system prompt
Expand Down Expand Up @@ -67,39 +71,44 @@ def generate_image(
"""
# Ask ChatGPT a prompt to generate image with DALL-E
with open(os.path.join(EMPLOYEE_PROMPTS_PATH, "dall_e_prompter.txt"), "r") as file:
response = openai.ChatCompletion.create(
response = openai.chat.completions.create(
model=os.getenv("MODEL_NAME", "gpt-3.5-turbo-16k"),
messages=[
# Initialize ChatGPT to be a helpful assistant but that it remains the employee
{
"role": "system",
"content": f"{file.read()}"
+ f" You are also {system_prompt} But keep in mind that {file.read()}"
if system_prompt
else "",
"content": (
f"{file.read()}"
+ f" You are also {system_prompt} But keep in mind that {file.read()}"
if system_prompt
else ""
),
},
# Generate a subject
{"role": "user", "content": f"SUBJECT {user_prompt}"},
],
)

# Create images, troncate prompt to 70 characters
# to be sure it will be accepted by DALL-E
image_response = openai.Image.create(
prompt=response.choices[0].message.content[:70],
n=nb_image,
size="1024x1024",
)

generated_image_names = []

# Download images
for index, image in enumerate(image_response["data"]):
img_data = requests.get(image["url"]).content
img_name = f"{base_name}_{index}.jpg"
img_path = os.path.join(output_directory, img_name)
with open(img_path, "wb") as handler:
handler.write(img_data)
generated_image_names.append(f"./{img_name}")
try:
# Create images, troncate prompt to 70 characters
# to be sure it will be accepted by DALL-E
image_response = openai.Image.create(
prompt=response.choices[0].message.content[:70],
n=nb_image,
size="1024x1024",
)

# Download images
for index, image in enumerate(image_response["data"]):
img_data = requests.get(image["url"]).content
img_name = f"{base_name}_{index}.jpg"
img_path = os.path.join(output_directory, img_name)
with open(img_path, "wb") as handler:
handler.write(img_data)
generated_image_names.append(f"./{img_name}")
except Exception as error:
print(error)

return response.choices[0].message.content, generated_image_names
9 changes: 6 additions & 3 deletions python/gpt_enterprise/scrum_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Scrum Master
\U0001F3C2
"""

import os
import ast
import time
Expand Down Expand Up @@ -41,9 +42,11 @@ def __init__(
"""
with open(
os.path.join(
MANAGER_PROMPTS_PATH
if not os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
else os.getenv("CUSTOM_MANAGER_PROMPTS_PATH"),
(
MANAGER_PROMPTS_PATH
if not os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
else os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
),
"scrum_master.txt",
),
"r",
Expand Down
9 changes: 6 additions & 3 deletions python/gpt_enterprise/team_leader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Team leader
\U0001F57A
"""

import os
import ast
import json
Expand Down Expand Up @@ -37,9 +38,11 @@ def __init__(
"""
with open(
os.path.join(
MANAGER_PROMPTS_PATH
if not os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
else os.getenv("CUSTOM_MANAGER_PROMPTS_PATH"),
(
MANAGER_PROMPTS_PATH
if not os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
else os.getenv("CUSTOM_MANAGER_PROMPTS_PATH")
),
"team_leader.txt",
),
"r",
Expand Down
49 changes: 49 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "GPTenterprise"
version = "0.1.0b1"
authors = [
{name = "nervousapps (Achille Pénet)", email = "[email protected]"}
]
description = "Emulating an enterprise with OpenaAI GPT."
classifiers = [
"License :: OSI Approved :: MIT License",
]
readme = "README.md"
dependencies = [
"python-dotenv",
"openai",
"requests",
]
requires-python=">= 3.9"

[project.urls]
Source = "https://github.com/nervousapps/GPTenterprise"
Documentation = "https://nervousapps.github.io/GPTenterprise"

[project.optional-dependencies]
test = [
"pytest",
"pytest-mock",
"pytest-cov",
"pytest-asyncio",
]
doc = ["black", "pdoc"]

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
include = ['gpt_enterprise*']
exclude = ['tests']

[tool.setuptools.package-data]
"gpt_enterprise.prompts" = ["*.txt"]

[project.scripts]
GPTenterprise = "gpt_enterprise:main"


2 changes: 0 additions & 2 deletions python/requirements-docs.in

This file was deleted.

82 changes: 69 additions & 13 deletions python/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,84 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=./python/requirements-docs.txt ./python/requirements-docs.in
# pip-compile --extra=doc --output-file=./python/requirements-docs.txt ./python/pyproject.toml
#
black==23.3.0
# via -r ./python/requirements-docs.in
click==8.1.3
annotated-types==0.6.0
# via pydantic
anyio==4.2.0
# via
# httpx
# openai
black==23.12.1
# via GPTenterprise (python/pyproject.toml)
certifi==2023.11.17
# via
# httpcore
# httpx
# requests
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via black
jinja2==3.1.2
distro==1.9.0
# via openai
exceptiongroup==1.2.0
# via anyio
h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.26.0
# via openai
idna==3.6
# via
# anyio
# httpx
# requests
jinja2==3.1.3
# via pdoc
markupsafe==2.1.2
markupsafe==2.1.3
# via
# jinja2
# pdoc
mypy-extensions==1.0.0
# via black
packaging==23.1
openai==1.7.2
# via GPTenterprise (python/pyproject.toml)
packaging==23.2
# via black
pathspec==0.11.1
pathspec==0.12.1
# via black
pdoc==13.1.0
# via -r ./python/requirements-docs.in
platformdirs==3.2.0
pdoc==14.3.0
# via GPTenterprise (python/pyproject.toml)
platformdirs==4.1.0
# via black
pygments==2.15.1
pydantic==2.5.3
# via openai
pydantic-core==2.14.6
# via pydantic
pygments==2.17.2
# via pdoc
python-dotenv==1.0.0
# via GPTenterprise (python/pyproject.toml)
requests==2.31.0
# via GPTenterprise (python/pyproject.toml)
sniffio==1.3.0
# via
# anyio
# httpx
# openai
tomli==2.0.1
# via black
tqdm==4.66.1
# via openai
typing-extensions==4.9.0
# via
# anyio
# black
# openai
# pydantic
# pydantic-core
urllib3==2.2.1
# via requests
5 changes: 0 additions & 5 deletions python/requirements-tests.in

This file was deleted.

Loading

0 comments on commit 48f249d

Please sign in to comment.