Skip to content

Commit

Permalink
remove non-stream request at this moment
Browse files Browse the repository at this point in the history
  • Loading branch information
ilsubyeega committed Sep 1, 2024
1 parent 2e7c49b commit 7e703d3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
47 changes: 1 addition & 46 deletions src/providers/sambanova/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import {
ErrorResponse,
ProviderConfig,
} from '../types';
import {
generateErrorResponse,
generateInvalidProviderResponseError,
} from '../utils';

export const SamvaNovaChatCompleteConfig: ProviderConfig = {
model: {
Expand All @@ -24,15 +20,14 @@ export const SamvaNovaChatCompleteConfig: ProviderConfig = {
default: 100,
min: 0,
},
// Currently FastAPI supports stream responses only.
stream: {
param: 'stream',
default: true,
},
stream_options: {
param: 'stream_options',
},
// todo: `temperature`, `top_p`, and etc does not exist on document but api-starter-kit have.
// todo: Current API supports only stream.
stop: {
param: 'stop',
},
Expand Down Expand Up @@ -72,46 +67,6 @@ export interface SamvaNovaStreamChunk {
} | null;
}

export const SamvaNovaChatCompleteResponseTransform: (
response: SamvaNovaChatCompleteResponse | SamvaNovaErrorResponse,
responseStatus: number
) => ChatCompletionResponse | ErrorResponse = (response, responseStatus) => {
if ('error' in response && responseStatus !== 200) {
return generateErrorResponse(
{
message: response.error.message,
type: response.error.type,
param: null,
code: response.error.code?.toString() || null,
},
SAMBANOVA
);
}

if ('choices' in response) {
return {
id: response.id,
object: response.object,
created: response.created,
model: response.model,
provider: SAMBANOVA,
choices: response.choices.map((c) => ({
index: c.index,
message: c.message,
logprobs: c.logprobs,
finish_reason: c.finish_reason,
})),
usage: {
prompt_tokens: response.usage?.prompt_tokens || 0,
completion_tokens: response.usage?.completion_tokens || 0,
total_tokens: response.usage?.total_tokens || 0,
},
};
}

return generateInvalidProviderResponseError(response, SAMBANOVA);
};

export const SamvaNovaChatCompleteStreamChunkTransform: (
response: string
) => string = (responseChunk) => {
Expand Down
3 changes: 0 additions & 3 deletions src/providers/sambanova/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { ProviderConfigs } from '../types';
import SambaNovaAPIConfig from './api';
import {
SamvaNovaChatCompleteConfig,
SamvaNovaChatCompleteResponseTransform,
SamvaNovaChatCompleteStreamChunkTransform,
} from './chatComplete';

const SambaNovaConfig: ProviderConfigs = {
chatComplete: SamvaNovaChatCompleteConfig,
api: SambaNovaAPIConfig,
responseTransforms: {
// todo: does not support non-stream request yet.
// chatComplete: SamvaNovaChatCompleteResponseTransform,
'stream-chatComplete': SamvaNovaChatCompleteStreamChunkTransform,
},
};
Expand Down

0 comments on commit 7e703d3

Please sign in to comment.