Merge pull request #2195 from yytdfc/dev
Compatible with input and output processing in OpenAI API format for BYOC vllm on SageMaker
This commit is contained in:
commit
f7ee8b66b6
1 changed files with 37 additions and 12 deletions
|
|
@ -55,12 +55,24 @@ class SageMaker extends BaseLLM {
|
|||
let position;
|
||||
while ((position = buffer.indexOf("\n")) >= 0) {
|
||||
const line = buffer.slice(0, position);
|
||||
const data = JSON.parse(line.replace(/^data:/, ""));
|
||||
if ("choices" in data) {
|
||||
yield data.choices[0].delta.content;
|
||||
}
|
||||
else if ("token" in data) {
|
||||
yield data.token.text;
|
||||
try {
|
||||
const data = JSON.parse(line.replace(/^data:/, ''));
|
||||
let text = undefined;
|
||||
if ("choices" in data) {
|
||||
if ("delta" in data.choices[0]){
|
||||
text = data.choices[0].delta.content;
|
||||
}
|
||||
else{
|
||||
text = data.choices[0].text;
|
||||
}
|
||||
}
|
||||
else if ("token" in data) {
|
||||
text = data.token.text;
|
||||
}
|
||||
if (text !== undefined) {
|
||||
yield text;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
buffer = buffer.slice(position + 1);
|
||||
}
|
||||
|
|
@ -94,12 +106,24 @@ class SageMaker extends BaseLLM {
|
|||
let position;
|
||||
while ((position = buffer.indexOf("\n")) >= 0) {
|
||||
const line = buffer.slice(0, position);
|
||||
const data = JSON.parse(line.replace(/^data:/, ""));
|
||||
if ("choices" in data) {
|
||||
yield { role: "assistant", content: data.choices[0].delta.content };
|
||||
}
|
||||
else if ("token" in data) {
|
||||
yield { role: "assistant", content: data.token.text };
|
||||
try {
|
||||
const data = JSON.parse(line.replace(/^data:/, ''));
|
||||
let text = undefined;
|
||||
if ("choices" in data) {
|
||||
if ("delta" in data.choices[0]){
|
||||
text = data.choices[0].delta.content;
|
||||
}
|
||||
else{
|
||||
text = data.choices[0].text;
|
||||
}
|
||||
}
|
||||
else if ("token" in data) {
|
||||
text = data.token.text;
|
||||
}
|
||||
if (text !== undefined) {
|
||||
yield { role: "assistant", content: text };
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
buffer = buffer.slice(position + 1);
|
||||
}
|
||||
|
|
@ -189,6 +213,7 @@ class CompletionAPIToolkit implements SageMakerModelToolkit {
|
|||
): InvokeEndpointWithResponseStreamCommand {
|
||||
const payload = {
|
||||
inputs: prompt,
|
||||
prompt: prompt,
|
||||
parameters: this.sagemaker.completionOptions,
|
||||
stream: true,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue