Skip to content

Commit

Permalink
feat: enables a custom model (#10)
Browse files Browse the repository at this point in the history
make model configurable
  • Loading branch information
elliotBraem authored Jan 29, 2024
1 parent 7b96d13 commit 955b1fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion api/openai.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const token = process.env.OPENAI_TOKEN;
const DEFAULT_MODEL = 'gpt-3.5-turbo';

export const config = {
runtime: 'edge',
Expand Down Expand Up @@ -73,7 +74,7 @@ export default async (request) => {
'content-type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
model: input.model || DEFAULT_MODEL,
messages: input.messages
})
}).then(r => r.json());
Expand Down
3 changes: 2 additions & 1 deletion api/openaistream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const token = process.env.OPENAI_TOKEN;
const DEFAULT_MODEL = 'gpt-3.5-turbo';

export const config = {
runtime: 'edge',
Expand Down Expand Up @@ -76,7 +77,7 @@ export default async (request) => {
'content-type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-3.5-turbo',
model: input.model || DEFAULT_MODEL,
temperature: 0.5,
stream: true,
messages: input.messages
Expand Down
9 changes: 5 additions & 4 deletions client/nearopenaiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
explorerUrl: `https://explorer.${networkId}.near.org`
};

export async function create_ask_ai_request_body(messages) {
export async function create_ask_ai_request_body(messages, model) {
const near = await connect(config);

const account = await near.account(process.env.NEAR_ACCOUNT_ID);
Expand Down Expand Up @@ -52,13 +52,14 @@ export async function create_ask_ai_request_body(messages) {
signed_transaction: Buffer.from(signedTx.encode()).toString('base64'),
transaction_hash: nearApi.utils.serialize.base_encode(txHash),
sender_account_id: accountId,
messages: messages
messages: messages,
model: model
});
}

export async function ask_ai(messages) {
export async function ask_ai(messages, model) {
try {
const requestbody = await create_ask_ai_request_body(messages);
const requestbody = await create_ask_ai_request_body(messages, model);
const airesponse = await fetch('https://near-openai.vercel.app/api/openai', {
method: 'POST',
body: requestbody
Expand Down

1 comment on commit 955b1fe

@vercel
Copy link

@vercel vercel bot commented on 955b1fe Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.