mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-12 00:36:03 +00:00
feat: 基本架构
This commit is contained in:
30
pkg/openai/manager.py
Normal file
30
pkg/openai/manager.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import openai
|
||||
|
||||
inst = None
|
||||
|
||||
|
||||
class OpenAIInteract:
|
||||
api_key = ''
|
||||
api_params = {}
|
||||
|
||||
def __init__(self, api_key: str, api_params: dict):
|
||||
self.api_key = api_key
|
||||
self.api_params = api_params
|
||||
|
||||
openai.api_key = self.api_key
|
||||
|
||||
global inst
|
||||
inst = self
|
||||
|
||||
def request_completion(self, prompt, stop):
|
||||
response = openai.Completion.create(
|
||||
prompt=prompt,
|
||||
stop=stop,
|
||||
**self.api_params
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def get_inst() -> OpenAIInteract:
|
||||
global inst
|
||||
return inst
|
||||
Reference in New Issue
Block a user