openai migration

pull/84/head
Kye 1 year ago
parent a90c8187fb
commit 4c19da66ae

@ -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)

@ -1,10 +1,7 @@
from swarms.models.gpt4v import GPT4Vision from swarms.models.gpt4v import GPT4Vision
api_key = ""
gpt4vision = GPT4Vision( gpt4vision = GPT4Vision(openai_api_key="")
openai_api_key=api_key,
)
img = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/VFPt_Solenoid_correct2.svg/640px-VFPt_Solenoid_correct2.svg.png" img = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/VFPt_Solenoid_correct2.svg/640px-VFPt_Solenoid_correct2.svg.png"

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "2.2.9" version = "2.3.0"
description = "Swarms - Pytorch" description = "Swarms - Pytorch"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -24,7 +24,7 @@ from langchain.callbacks.manager import (
CallbackManagerForLLMRun, CallbackManagerForLLMRun,
) )
from langchain.llms.base import LLM 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.language_model import BaseLanguageModel
from langchain.schema.output import GenerationChunk from langchain.schema.output import GenerationChunk
from langchain.schema.prompt import PromptValue from langchain.schema.prompt import PromptValue

@ -1,3 +1,4 @@
import concurrent.futures import concurrent.futures
import logging import logging
import os import os
@ -5,7 +6,6 @@ import uuid
from dataclasses import dataclass from dataclasses import dataclass
from io import BytesIO from io import BytesIO
from typing import List from typing import List
import backoff import backoff
import openai import openai
import requests import requests
@ -66,7 +66,7 @@ class Dalle3:
size: str = "1024x1024" size: str = "1024x1024"
max_retries: int = 3 max_retries: int = 3
quality: str = "standard" quality: str = "standard"
openai_api_key: str = None openai_api_key: str = None or os.getenv("OPENAI_API_KEY")
n: int = 1 n: int = 1
save_path: str = "images" save_path: str = "images"
max_time_seconds: int = 60 max_time_seconds: int = 60

@ -1,3 +1,4 @@
import os
import asyncio import asyncio
import base64 import base64
import concurrent.futures import concurrent.futures
@ -64,7 +65,7 @@ class GPT4Vision:
model: str = "gpt-4-vision-preview" model: str = "gpt-4-vision-preview"
backoff_factor: float = 2.0 backoff_factor: float = 2.0
timeout_seconds: int = 10 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 # 'Low' or 'High' for respesctively fast or high quality, but high more token usage
quality: str = "low" quality: str = "low"
# Max tokens to use for the API request, the maximum might be 3,000 but we don't know # Max tokens to use for the API request, the maximum might be 3,000 but we don't know

@ -1,7 +1,7 @@
from typing import List, Tuple from typing import List, Tuple
from PIL import Image from PIL import Image
from pydantic import BaseModel, root_validator, validator from pydantic import BaseModel, model_validator, validator
from transformers import AutoModelForVision2Seq, AutoProcessor from transformers import AutoModelForVision2Seq, AutoProcessor
@ -11,7 +11,7 @@ class Detections(BaseModel):
class_id: List[int] class_id: List[int]
confidence: List[float] confidence: List[float]
@root_validator @model_validator
def check_length(cls, values): def check_length(cls, values):
assert ( assert (
len(values.get("xyxy")) len(values.get("xyxy"))

@ -104,7 +104,7 @@ def _create_retry_decorator(
openai.Timeout, openai.Timeout,
openai.APIError, openai.APIError,
openai.APIConnectionError, openai.APIConnectionError,
openai.error.RateLimitError, openai.RateLimitError,
openai.error.ServiceUnavailableError, openai.error.ServiceUnavailableError,
] ]
return create_base_retry_decorator( return create_base_retry_decorator(

Loading…
Cancel
Save