-
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
fc2938f
commit e99bd71
Showing
6 changed files
with
57 additions
and
15 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
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,27 @@ | ||
import openai | ||
from .base_model import BaseLLMModel | ||
from .. import shared | ||
from ..config import retrieve_proxy | ||
|
||
|
||
class OpenAI_Instruct_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_instruct_style_input(self): | ||
return "\n\n".join([item["content"] for item in self.history]) | ||
|
||
@shared.state.switching_api_key | ||
def get_answer_at_once(self): | ||
prompt = self._get_instruct_style_input() | ||
with retrieve_proxy(): | ||
response = openai.Completion.create( | ||
api_key=self.api_key, | ||
api_base=shared.state.openai_api_base, | ||
model=self.model_name, | ||
prompt=prompt, | ||
temperature=self.temperature, | ||
top_p=self.top_p, | ||
) | ||
return response.choices[0].text.strip(), response.usage["total_tokens"] |
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
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