Skip to content

Commit

Permalink
chore: add content type json default headers
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-bosman committed Jan 3, 2024
1 parent 3877e50 commit 4e4ba75
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type {
UseChatStreamOptions
} from '../hooks/useChatStream';

const DEFAULT_HEADERS = {
'Content-Type': 'application/json',
};

const mergeInputInOptions = (input: string, options: UseChatStreamOptions, method: UseChatStreamInputMethod) => {
options.query = options.query ?? {};
(options[method.type] as Record<string, unknown>)[method.key] = input;
Expand All @@ -18,7 +22,10 @@ export const getStream = async (input: string, options: UseChatStreamOptions, me

const response = await fetch(options.url + params, {
method: options.method,
headers: options.headers,
headers: {
...DEFAULT_HEADERS,
...options.headers
},
body: JSON.stringify(options.body, (_k, v) => v === null ? undefined : v)
});

Expand Down

0 comments on commit 4e4ba75

Please # to comment.