-
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 #352 from arc53/feature/aws-sagemaker-inference
sagemaker + llm creator class
- Loading branch information
Showing
5 changed files
with
57 additions
and
25 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
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,20 @@ | ||
from application.llm.openai import OpenAILLM, AzureOpenAILLM | ||
from application.llm.sagemaker import SagemakerAPILLM | ||
from application.llm.huggingface import HuggingFaceLLM | ||
|
||
|
||
|
||
class LLMCreator: | ||
llms = { | ||
'openai': OpenAILLM, | ||
'azure_openai': AzureOpenAILLM, | ||
'sagemaker': SagemakerAPILLM, | ||
'huggingface': HuggingFaceLLM | ||
} | ||
|
||
@classmethod | ||
def create_llm(cls, type, *args, **kwargs): | ||
llm_class = cls.llms.get(type.lower()) | ||
if not llm_class: | ||
raise ValueError(f"No LLM class found for type {type}") | ||
return llm_class(*args, **kwargs) |
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 @@ | ||
from application.llm.base import BaseLLM | ||
from application.core.settings import settings | ||
import requests | ||
import json | ||
|
||
class SagemakerAPILLM(BaseLLM): | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.url = settings.SAGEMAKER_API_URL | ||
|
||
def gen(self, model, engine, messages, stream=False, **kwargs): | ||
context = messages[0]['content'] | ||
user_question = messages[-1]['content'] | ||
prompt = f"### Instruction \n {user_question} \n ### Context \n {context} \n ### Answer \n" | ||
|
||
response = requests.post( | ||
url=self.url, | ||
headers={ | ||
"Content-Type": "application/json; charset=utf-8", | ||
}, | ||
data=json.dumps({"input": prompt}) | ||
) | ||
|
||
return response.json()['answer'] | ||
|
||
def gen_stream(self, model, engine, messages, stream=True, **kwargs): | ||
raise NotImplementedError("Sagemaker does not support streaming") |
833e183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs-gpt – ./frontend
docs-gpt-git-main-arc53.vercel.app
docs-gpt-arc53.vercel.app
docs-gpt-brown.vercel.app
833e183
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nextra-docsgpt – ./docs
docs.docsgpt.co.uk
nextra-docsgpt.vercel.app
nextra-docsgpt-git-main-arc53.vercel.app
nextra-docsgpt-arc53.vercel.app