From f56b8f794f269c852942da86752b16abfb2b172f Mon Sep 17 00:00:00 2001 From: Kye Date: Sat, 11 Nov 2023 20:01:24 -0500 Subject: [PATCH] openai migration Former-commit-id: 4c19da66aec2bd34b2f28da79264ebafc389a4cf --- dall3.py | 8 ++++++++ playground/models/gpt4_v.py => gpt4_v.py | 5 +---- pyproject.toml | 2 +- swarms/models/anthropic.py | 2 +- swarms/models/dalle3.py | 4 ++-- swarms/models/gpt4v.py | 3 ++- swarms/models/kosmos2.py | 4 ++-- swarms/models/openai_chat.py | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 dall3.py rename playground/models/gpt4_v.py => gpt4_v.py (79%) diff --git a/dall3.py b/dall3.py new file mode 100644 index 00000000..7a17400d --- /dev/null +++ b/dall3.py @@ -0,0 +1,8 @@ +from swarms.models import Dalle3 + +dalle3 = Dalle3( + openai_api_key="" +) +task = "A painting of a dog" +image_url = dalle3(task) +print(image_url) \ No newline at end of file diff --git a/playground/models/gpt4_v.py b/gpt4_v.py similarity index 79% rename from playground/models/gpt4_v.py rename to gpt4_v.py index 5e5d7c95..822ec726 100644 --- a/playground/models/gpt4_v.py +++ b/gpt4_v.py @@ -1,10 +1,7 @@ from swarms.models.gpt4v import GPT4Vision -api_key = "" -gpt4vision = GPT4Vision( - openai_api_key=api_key, -) +gpt4vision = GPT4Vision(openai_api_key="") img = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/VFPt_Solenoid_correct2.svg/640px-VFPt_Solenoid_correct2.svg.png" diff --git a/pyproject.toml b/pyproject.toml index 50476c8f..e98c5637 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.2.9" +version = "2.3.0" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/models/anthropic.py b/swarms/models/anthropic.py index 30ec22ce..edaae087 100644 --- a/swarms/models/anthropic.py +++ b/swarms/models/anthropic.py @@ -24,7 +24,7 @@ from langchain.callbacks.manager import ( CallbackManagerForLLMRun, ) from langchain.llms.base import LLM -from langchain.pydantic_v1 import Field, SecretStr, root_validator +from pydantic import Field, SecretStr, root_validator from langchain.schema.language_model import BaseLanguageModel from langchain.schema.output import GenerationChunk from langchain.schema.prompt import PromptValue diff --git a/swarms/models/dalle3.py b/swarms/models/dalle3.py index 45b80480..e6b345ae 100644 --- a/swarms/models/dalle3.py +++ b/swarms/models/dalle3.py @@ -1,3 +1,4 @@ + import concurrent.futures import logging import os @@ -5,7 +6,6 @@ import uuid from dataclasses import dataclass from io import BytesIO from typing import List - import backoff import openai import requests @@ -66,7 +66,7 @@ class Dalle3: size: str = "1024x1024" max_retries: int = 3 quality: str = "standard" - openai_api_key: str = None + openai_api_key: str = None or os.getenv("OPENAI_API_KEY") n: int = 1 save_path: str = "images" max_time_seconds: int = 60 diff --git a/swarms/models/gpt4v.py b/swarms/models/gpt4v.py index d1d5ce1f..8411cb14 100644 --- a/swarms/models/gpt4v.py +++ b/swarms/models/gpt4v.py @@ -1,3 +1,4 @@ +import os import asyncio import base64 import concurrent.futures @@ -64,7 +65,7 @@ class GPT4Vision: model: str = "gpt-4-vision-preview" backoff_factor: float = 2.0 timeout_seconds: int = 10 - openai_api_key: Optional[str] = None + openai_api_key: Optional[str] = None or os.getenv("OPENAI_API_KEY") # 'Low' or 'High' for respesctively fast or high quality, but high more token usage quality: str = "low" # Max tokens to use for the API request, the maximum might be 3,000 but we don't know diff --git a/swarms/models/kosmos2.py b/swarms/models/kosmos2.py index 2178c483..0e207e2e 100644 --- a/swarms/models/kosmos2.py +++ b/swarms/models/kosmos2.py @@ -1,7 +1,7 @@ from typing import List, Tuple from PIL import Image -from pydantic import BaseModel, root_validator, validator +from pydantic import BaseModel, model_validator, validator from transformers import AutoModelForVision2Seq, AutoProcessor @@ -11,7 +11,7 @@ class Detections(BaseModel): class_id: List[int] confidence: List[float] - @root_validator + @model_validator def check_length(cls, values): assert ( len(values.get("xyxy")) diff --git a/swarms/models/openai_chat.py b/swarms/models/openai_chat.py index f19c6aa1..46057a45 100644 --- a/swarms/models/openai_chat.py +++ b/swarms/models/openai_chat.py @@ -104,7 +104,7 @@ def _create_retry_decorator( openai.Timeout, openai.APIError, openai.APIConnectionError, - openai.error.RateLimitError, + openai.RateLimitError, openai.error.ServiceUnavailableError, ] return create_base_retry_decorator(