-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from arc53/feat/premaillm
Add PremAI LLM implementation
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
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
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,33 @@ | ||
from application.llm.base import BaseLLM | ||
from application.core.settings import settings | ||
|
||
class PremAILLM(BaseLLM): | ||
|
||
def __init__(self, api_key): | ||
from premai import Prem | ||
|
||
self.client = Prem( | ||
api_key=api_key | ||
) | ||
self.api_key = api_key | ||
self.project_id = settings.PREMAI_PROJECT_ID | ||
|
||
def gen(self, model, engine, messages, stream=False, **kwargs): | ||
response = self.client.chat.completions.create(model=model, | ||
project_id=self.project_id, | ||
messages=messages, | ||
stream=stream, | ||
**kwargs) | ||
|
||
return response.choices[0].message["content"] | ||
|
||
def gen_stream(self, model, engine, messages, stream=True, **kwargs): | ||
response = self.client.chat.completions.create(model=model, | ||
project_id=self.project_id, | ||
messages=messages, | ||
stream=stream, | ||
**kwargs) | ||
|
||
for line in response: | ||
if line.choices[0].delta["content"] is not None: | ||
yield line.choices[0].delta["content"] |