Skip to content

Commit

Permalink
Update server.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
shoushou1106 committed Dec 21, 2024
1 parent 9be2f79 commit 8c821c7
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,10 @@ router.post('/', async (request, env: Env) => {
);
}

await fetch(
`https://discord.com/api/v10/webhooks/${env.DISCORD_APPLICATION_ID}/${interaction.token}`,
{
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: 'Hi',
}),
}
);
return new Response();

// Stream the AI response and update the message
await streamFromAI(interaction, userPrompt, env);

return new Response();
}
default:
return new JsonResponse({ error: 'Unknown Type' }, { status: 400 });
Expand Down Expand Up @@ -167,7 +154,7 @@ async function streamFromAI(interaction: APIInteraction, prompt: string, env: En



/*try {
try {
const together = new Together({ apiKey: env.TOGETHER_API_KEY });

const stream = await together.chat.completions.create({
Expand All @@ -183,7 +170,7 @@ async function streamFromAI(interaction: APIInteraction, prompt: string, env: En

// Update the message with the current AI response
await fetch(
`https://discord.com/api/v10/webhooks/${env.DISCORD_APPLICATION_ID}/${interaction.token}/messages/@original`,
`https://discord.com/api/v10/webhooks/${interaction.application_id}/${interaction.token}/messages/@original`,
{
method: "PATCH",
headers: {
Expand All @@ -196,7 +183,7 @@ async function streamFromAI(interaction: APIInteraction, prompt: string, env: En
);
}
await fetch(
`https://discord.com/api/v10/webhooks/${env.DISCORD_APPLICATION_ID}/${interaction.token}/messages/@original`,
`https://discord.com/api/v10/webhooks/${interaction.application_id}/${interaction.token}/messages/@original`,
{
method: "PATCH",
headers: {
Expand All @@ -212,7 +199,7 @@ async function streamFromAI(interaction: APIInteraction, prompt: string, env: En

// Handle errors by updating the message
await fetch(
`https://discord.com/api/v10/webhooks/${env.DISCORD_APPLICATION_ID}/${interaction.token}/messages/@original`,
`https://discord.com/api/v10/webhooks/${interaction.application_id}/${interaction.token}/messages/@original`,
{
method: "PATCH",
headers: {
Expand All @@ -223,6 +210,6 @@ async function streamFromAI(interaction: APIInteraction, prompt: string, env: En
}),
}
);
}*/
}
}
export default server;

0 comments on commit 8c821c7

Please sign in to comment.