-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a27db7d
commit a6ebff0
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import re | ||
import json | ||
import openai | ||
from openai import OpenAI | ||
from .base_model import BaseLLMModel | ||
from .. import shared | ||
from ..config import retrieve_proxy | ||
|
||
|
||
class OpenAI_DALLE3_Client(BaseLLMModel): | ||
def __init__(self, model_name, api_key, user_name="") -> None: | ||
super().__init__(model_name=model_name, user=user_name) | ||
self.api_key = api_key | ||
|
||
def _get_dalle3_prompt(self): | ||
prompt = self.history[-1]["content"] | ||
if prompt.endswith("--raw"): | ||
prompt = "I NEED to test how the tool works with extremely simple prompts. DO NOT add any detail, just use it AS-IS:" + prompt | ||
return prompt | ||
|
||
@shared.state.switching_api_key | ||
def get_answer_at_once(self): | ||
prompt = self._get_dalle3_prompt() | ||
with retrieve_proxy(): | ||
client = OpenAI(api_key=openai.api_key) | ||
try: | ||
response = client.images.generate( | ||
model="dall-e-3", | ||
prompt=prompt, | ||
size="1024x1024", | ||
quality="standard", | ||
n=1, | ||
) | ||
except openai.BadRequestError as e: | ||
msg = str(e) | ||
match = re.search(r"'message': '([^']*)'", msg) | ||
return match.group(1), 0 | ||
return f'<img src="{response.data[0].url}"> {response.data[0].revised_prompt}', 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
"GPT4 Vision", | ||
"川虎助理", | ||
"川虎助理 Pro", | ||
"DALL-E 3", | ||
"GooglePaLM", | ||
"xmchat", | ||
"Azure OpenAI", | ||
|