-
-
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.
- Loading branch information
Showing
13 changed files
with
141 additions
and
37 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
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
Binary file not shown.
Binary file not shown.
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,49 @@ | ||
from application.llm.base import BaseLLM | ||
import json | ||
import requests | ||
|
||
class DocsGPTAPILLM(BaseLLM): | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.endpoint = "https://llm.docsgpt.co.uk" | ||
|
||
|
||
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( | ||
f"{self.endpoint}/answer", | ||
json={ | ||
"prompt": prompt, | ||
"max_new_tokens": 30 | ||
} | ||
) | ||
response_clean = response.json()['a'].split("###")[0] | ||
|
||
return response_clean | ||
|
||
def gen_stream(self, model, engine, messages, stream=True, **kwargs): | ||
context = messages[0]['content'] | ||
user_question = messages[-1]['content'] | ||
prompt = f"### Instruction \n {user_question} \n ### Context \n {context} \n ### Answer \n" | ||
|
||
# send prompt to endpoint /stream | ||
response = requests.post( | ||
f"{self.endpoint}/stream", | ||
json={ | ||
"prompt": prompt, | ||
"max_new_tokens": 256 | ||
}, | ||
stream=True | ||
) | ||
|
||
for line in response.iter_lines(): | ||
if line: | ||
#data = json.loads(line) | ||
data_str = line.decode('utf-8') | ||
if data_str.startswith("data: "): | ||
data = json.loads(data_str[6:]) | ||
yield data['a'] | ||
|
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
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