randydev commited on
Commit
cd8a222
1 Parent(s): 8ff06e0

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +14 -10
  2. models.py +2 -0
main.py CHANGED
@@ -628,7 +628,7 @@ def chatgpt_model(item: ChatgptModel):
628
  @app.post("/ryuzaki/chatgpt3-turbo", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
629
  def chatgpt3_turbo(item: Chatgpt3Texts):
630
  if item.is_openai_original:
631
- openai.api_key = ""
632
  openai.api_base = SOURCE_OPENAI_ACCESS_URL
633
  chat_completion = openai.ChatCompletion.create(
634
  model="gpt-3.5-turbo",
@@ -636,14 +636,16 @@ def chatgpt3_turbo(item: Chatgpt3Texts):
636
  stream=True
637
  )
638
  if isinstance(chat_completion, dict):
639
- print(chat_completion.choices[0].message.content)
 
640
  else:
641
  for token in chat_completion:
642
  content = token["choices"][0]["delta"].get("content")
643
  if content is not None:
 
644
  return SuccessResponse(
645
  status="True",
646
- randydev={"message": content}
647
  )
648
  else:
649
  url = "https://lexica.qewertyy.me/models"
@@ -663,7 +665,7 @@ def chatgpt4_turbo(
663
  item: OpenaiTexts,
664
  api_key: None = Depends(validate_api_key)
665
  ):
666
- openai.api_key = ""
667
  openai.api_base = SOURCE_OPENAI_ACCESS_URL
668
  chat_completion = openai.ChatCompletion.create(
669
  model="gpt-4-turbo",
@@ -671,15 +673,17 @@ def chatgpt4_turbo(
671
  stream=True
672
  )
673
  if isinstance(chat_completion, dict):
674
- print(chat_completion.choices[0].message.content)
 
675
  else:
676
  for token in chat_completion:
677
  content = token["choices"][0]["delta"].get("content")
678
- if content is not None:
679
- return SuccessResponse(
680
- status="True",
681
- randydev={"message": content}
682
- )
 
683
 
684
  @app.post("/ryuzaki/google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
685
  def v1beta3_google_ai(
 
628
  @app.post("/ryuzaki/chatgpt3-turbo", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
629
  def chatgpt3_turbo(item: Chatgpt3Texts):
630
  if item.is_openai_original:
631
+ openai.api_key = item.api_key
632
  openai.api_base = SOURCE_OPENAI_ACCESS_URL
633
  chat_completion = openai.ChatCompletion.create(
634
  model="gpt-3.5-turbo",
 
636
  stream=True
637
  )
638
  if isinstance(chat_completion, dict):
639
+ answer = chat_completion.choices[0].message.content
640
+ answer = ""
641
  else:
642
  for token in chat_completion:
643
  content = token["choices"][0]["delta"].get("content")
644
  if content is not None:
645
+ answer += content
646
  return SuccessResponse(
647
  status="True",
648
+ randydev={"message": answer}
649
  )
650
  else:
651
  url = "https://lexica.qewertyy.me/models"
 
665
  item: OpenaiTexts,
666
  api_key: None = Depends(validate_api_key)
667
  ):
668
+ openai.api_key = item.api_key
669
  openai.api_base = SOURCE_OPENAI_ACCESS_URL
670
  chat_completion = openai.ChatCompletion.create(
671
  model="gpt-4-turbo",
 
673
  stream=True
674
  )
675
  if isinstance(chat_completion, dict):
676
+ answer = chat_completion.choices[0].message.content
677
+ answer = ""
678
  else:
679
  for token in chat_completion:
680
  content = token["choices"][0]["delta"].get("content")
681
+ if content is not None:
682
+ answer += content
683
+ return SuccessResponse(
684
+ status="True",
685
+ randydev={"message": answer}
686
+ )
687
 
688
  @app.post("/ryuzaki/google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
689
  def v1beta3_google_ai(
models.py CHANGED
@@ -134,9 +134,11 @@ class AnimeStyled(BaseModel):
134
 
135
  class OpenaiTexts(BaseModel):
136
  query: str
 
137
 
138
  class Chatgpt3Texts(BaseModel):
139
  query: str
 
140
  is_openai_original: Optional[bool] = False
141
 
142
  class TextCustom(BaseModel):
 
134
 
135
  class OpenaiTexts(BaseModel):
136
  query: str
137
+ api_key: str
138
 
139
  class Chatgpt3Texts(BaseModel):
140
  query: str
141
+ api_key: str
142
  is_openai_original: Optional[bool] = False
143
 
144
  class TextCustom(BaseModel):