diff --git a/api/openai.js b/api/openai.js index 583899d..b14f97b 100644 --- a/api/openai.js +++ b/api/openai.js @@ -1,4 +1,5 @@ const token = process.env.OPENAI_TOKEN; +const DEFAULT_MODEL = 'gpt-3.5-turbo'; export const config = { runtime: 'edge', @@ -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()); diff --git a/api/openaistream.js b/api/openaistream.js index a08ae1d..3f4b612 100644 --- a/api/openaistream.js +++ b/api/openaistream.js @@ -1,4 +1,5 @@ const token = process.env.OPENAI_TOKEN; +const DEFAULT_MODEL = 'gpt-3.5-turbo'; export const config = { runtime: 'edge', @@ -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 diff --git a/client/nearopenaiclient.js b/client/nearopenaiclient.js index 95047aa..dc2c623 100644 --- a/client/nearopenaiclient.js +++ b/client/nearopenaiclient.js @@ -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); @@ -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