Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2 - fix testing #8

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11.5"]
python-version: ["3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Copyright (c) 2023. All rights reserved.

Created: 25.08.2023
Last Modified: 12.09.2023
Last Modified: 17.10.2023

Description:
This file is init point for project-wide structure.
Expand All @@ -14,6 +14,9 @@
# Engines
from .openai_api.src.openai_api.chatgpt import ChatGPT # pylint: disable=unused-import
from .openai_api.src.openai_api.dalle import DALLE # pylint: disable=unused-import
from .leonardo_api.src.leonardo_api.leonardo_sync import Leonardo # pylint: disable=unused-import
from .leonardo_api.src.leonardo_api.leonardo_async import Leonardo as LeonardoAsync # pylint: disable=unused-import


# Utils
from .utils.tts import CustomTTS # pylint: disable=unused-import
Expand Down
20 changes: 11 additions & 9 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
Copyright (c) 2023. All rights reserved.

Created: 25.08.2023
Last Modified: 12.09.2023
Last Modified: 17.10.2023

Description:
This file is entry point for project-wide structure.
"""

# Engines
from openai_api.src.openai_api.chatgpt import ChatGPT # pylint: disable=unused-import
from openai_api.src.openai_api.dalle import DALLE # pylint: disable=unused-import
from .openai_api.src.openai_api.chatgpt import ChatGPT # pylint: disable=unused-import
from .openai_api.src.openai_api.dalle import DALLE # pylint: disable=unused-import
from .leonardo_api.src.leonardo_api.leonardo_sync import Leonardo # pylint: disable=unused-import
from .leonardo_api.src.leonardo_api.leonardo_async import Leonardo as LeonardoAsync # pylint: disable=unused-import

# Utils
from utils.tts import CustomTTS # pylint: disable=unused-import
from utils.transcriptors import CustomTranscriptor # pylint: disable=unused-import
from utils.translators import CustomTranslator # pylint: disable=unused-import
from utils.audio_recorder import AudioRecorder, record_and_convert_audio # pylint: disable=unused-import
from utils.logger_config import setup_logger # pylint: disable=unused-import
from utils.other import is_heroku_environment # pylint: disable=unused-import
from .utils.tts import CustomTTS # pylint: disable=unused-import
from .utils.transcriptors import CustomTranscriptor # pylint: disable=unused-import
from .utils.translators import CustomTranslator # pylint: disable=unused-import
from .utils.audio_recorder import AudioRecorder, record_and_convert_audio # pylint: disable=unused-import
from .utils.logger_config import setup_logger # pylint: disable=unused-import
from .utils.other import is_heroku_environment # pylint: disable=unused-import
12 changes: 12 additions & 0 deletions examples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
Filename: __init__.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 16.10.2023
Last Modified: 17.10.2023

Description:
This file is init file for examples package.
"""
12 changes: 12 additions & 0 deletions examples/image_generation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
Filename: __init__.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 16.10.2023
Last Modified: 17.10.2023

Description:
This file is init file for image_generation package.
"""
24 changes: 19 additions & 5 deletions examples/image_generation/dalle_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
# -*- coding: utf-8 -*-
"""
Filename: dalle_test.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 15.10.2023
Last Modified: 17.10.2023

Description:
This file contains testing procedures for DALLE experiments
"""
import asyncio

from examples.creds import oai_token, oai_organization
from openai_api.src.openai_api import DALLE
from creds import oai_token, oai_organization

from time import sleep

dalle = DALLE(auth_token=oai_token, organization=oai_organization)


async def main():
resp = await dalle.create_image_url('robocop (robot policeman, from 80s movie)')
"""Main function for testing DALLE."""
resp = await dalle.create_image_url("robocop (robot policeman, from 80s movie)")
print(resp)
resp = await dalle.create_variation_from_url(resp[0])
print(resp)

asyncio.run(main())

asyncio.run(main())
131 changes: 131 additions & 0 deletions examples/image_generation/gpt_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-
"""
Filename: gpt_functions.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 15.10.2023
Last Modified: 17.10.2023

Description:
This file contains testing functions for ChatGPT function calling using DALLE and Leonardo experiments
"""
import json
from io import BytesIO

import requests
from PIL import Image

from examples.creds import oai_token, oai_organization
from leonardo_api.src.leonardo_api.leonardo_sync import Leonardo
from openai_api.src.openai_api.dalle import DALLE


def get_weather(city, units):
"""
Get the weather for a given city.

:param city: The city to get the weather for.
:param units: The units to use for the weather.

:return: The weather for the given city.
"""
base_url = "http://api.openweathermap.org/data/2.5/weather"
params = {"q": city, "appid": "93171b03384f92ee3c55873452a49c7c", "units": units}
response = requests.get(base_url, params=params, timeout=30)
data = response.json()
return data


def get_current_weather(location, unit="metric"):
"""
Get the current weather in a given location

:param location: (str) The location to get the weather for.
:param unit: (str) The unit to use for the weather.
"""
owm_info = get_weather(location, units=unit)
weather_info = {
"location": location,
"temperature": owm_info["main"]["temp"],
"unit": unit,
"forecast": owm_info["weather"][0]["description"],
"wind": owm_info["wind"]["speed"],
}
return json.dumps(weather_info)


def draw_image_using_dalle(prompt):
"""
Draws image using user prompt. Returns url of image.

:param prompt: (str) Prompt, the description, what should be drawn and how
:return: (str) url of image
"""
dalle = DALLE(auth_token=oai_token, organization=oai_organization)
image = dalle.create_image_url(prompt)
url_dict = {"image_url": image[0]}
response = requests.get(image[0])
img = Image.open(BytesIO(response.content))
img.show()
return json.dumps(url_dict)


def draw_image(prompt):
"""
Draws image using user prompt. Returns url of image.

:param prompt: (str) Prompt, the description, what should be drawn and how
:return: (dict) dict with url of image
"""
leonardo = Leonardo(auth_token="a0178171-c67f-4922-afb3-458f24ecef1a")
leonardo.get_user_info()
response = leonardo.post_generations(
prompt=prompt,
num_images=1,
guidance_scale=5,
model_id="e316348f-7773-490e-adcd-46757c738eb7",
width=1024,
height=768,
)
response = leonardo.wait_for_image_generation(generation_id=response["sdGenerationJob"]["generationId"])
url_dict = {"image_url": response[0]["url"]}
response = requests.get(url_dict["image_url"])
img = Image.open(BytesIO(response.content))
img.show()
return json.dumps(url_dict)


gpt_functions = [
{
"name": "draw_image",
"description": "Draws image using user prompt. Returns url of image.",
"parameters": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "Prompt, the description, what should be drawn and how",
},
},
"required": ["prompt"],
},
},
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
]

gpt_functions_dict = {"get_current_weather": get_current_weather, "draw_image": draw_image}
37 changes: 27 additions & 10 deletions examples/image_generation/test_leonardo.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import json
# -*- coding: utf-8 -*-
"""
Filename: test_leonardo.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 15.10.2023
Last Modified: 17.10.2023

Description:
This file contains testing procedures for Leonardo experiments
"""
import asyncio
import json

from leonardo_api import LeonardoAsync as Leonardo
from leonardo_api.src.leonardo_api.leonardo_async import Leonardo


async def main():
leonardo = Leonardo(auth_token='a0178171-c67f-4922-afb3-458f24ecef1a')
"""Main function"""
leonardo = Leonardo(auth_token="a0178171-c67f-4922-afb3-458f24ecef1a")
response = await leonardo.get_user_info()
print(response)
response = await leonardo.post_generations(prompt="a beautiful necromancer witch resurrects skeletons against "
"the backdrop of a burning ruined castle", num_images=1,
negative_prompt='bright colors, good characters, positive',
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768,
guidance_scale=3)
response = await leonardo.post_generations(
prompt="a beautiful necromancer witch resurrects skeletons against " "the backdrop of a burning ruined castle",
num_images=1,
negative_prompt="bright colors, good characters, positive",
model_id="e316348f-7773-490e-adcd-46757c738eb7",
width=1024,
height=768,
guidance_scale=3,
)
print(response)
response = await leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId'])
print(json.dumps(response[0]['url']))
response = await leonardo.wait_for_image_generation(generation_id=response["sdGenerationJob"]["generationId"])
print(json.dumps(response[0]["url"]))


asyncio.run(main())
12 changes: 12 additions & 0 deletions examples/speak_and_hear/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""
Filename: __init__.py
Author: Iliya Vereshchagin
Copyright (c) 2023. All rights reserved.

Created: 16.10.2023
Last Modified: 17.10.2023

Description:
This file is init file for speak_and_hear package.
"""
Loading
Loading