mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
feat: 初步支持绘图api
This commit is contained in:
@@ -15,9 +15,12 @@ class OpenAIInteract:
|
||||
|
||||
key_mgr = None
|
||||
|
||||
def __init__(self, api_key: str, api_params: dict):
|
||||
default_image_api_params = {
|
||||
"size": "256x256",
|
||||
}
|
||||
|
||||
def __init__(self, api_key: str):
|
||||
# self.api_key = api_key
|
||||
self.api_params = api_params
|
||||
|
||||
self.key_mgr = pkg.openai.keymgr.KeysManager(api_key)
|
||||
|
||||
@@ -28,12 +31,11 @@ class OpenAIInteract:
|
||||
|
||||
# 请求OpenAI Completion
|
||||
def request_completion(self, prompt, stop):
|
||||
logging.debug("请求OpenAI Completion, key:"+openai.api_key)
|
||||
response = openai.Completion.create(
|
||||
prompt=prompt,
|
||||
stop=stop,
|
||||
timeout=config.process_message_timeout,
|
||||
**self.api_params
|
||||
**config.completion_api_params
|
||||
)
|
||||
switched = self.key_mgr.report_usage(prompt + response['choices'][0]['text'])
|
||||
if switched:
|
||||
@@ -41,6 +43,15 @@ class OpenAIInteract:
|
||||
|
||||
return response
|
||||
|
||||
def request_image(self, prompt):
|
||||
response = openai.Image.create(
|
||||
prompt=prompt,
|
||||
n=1,
|
||||
**config.image_api_params if hasattr(config, "image_api_params") else self.default_image_api_params
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def get_inst() -> OpenAIInteract:
|
||||
global inst
|
||||
|
||||
Reference in New Issue
Block a user