33import prisma from "@/lib/prisma" ;
44import { notFound } from "next/navigation" ;
55import Together from "together-ai" ;
6- // import { z } from "zod";
76import {
87 getMainCodingPrompt ,
98 screenshotToCodePrompt ,
@@ -16,7 +15,6 @@ export async function createChat(
1615 quality : "high" | "low" ,
1716 screenshotUrl : string | undefined ,
1817) {
19- console . log ( "-- CREATING CHAT" ) ;
2018 const chat = await prisma . chat . create ( {
2119 data : {
2220 model,
@@ -41,7 +39,6 @@ export async function createChat(
4139 const together = new Together ( options ) ;
4240
4341 async function fetchTitle ( ) {
44- console . log ( "-- FETCHING TITLE" ) ;
4542 const responseForChatTitle = await together . chat . completions . create ( {
4643 model : "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo" ,
4744 messages : [
@@ -61,7 +58,6 @@ export async function createChat(
6158 }
6259
6360 async function fetchTopExample ( ) {
64- console . log ( "-- FETCHING TOP EXAMPLE" ) ;
6561 const findSimilarExamples = await together . chat . completions . create ( {
6662 model : "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo" ,
6763 messages : [
@@ -147,7 +143,6 @@ export async function createChat(
147143 userMessage = prompt ;
148144 }
149145
150- console . log ( "-- UPDATING CHAT WITH MESSAGES" ) ;
151146 let newChat = await prisma . chat . update ( {
152147 where : {
153148 id : chat . id ,
@@ -177,8 +172,6 @@ export async function createChat(
177172 . at ( - 1 ) ;
178173 if ( ! lastMessage ) throw new Error ( "No new message" ) ;
179174
180- console . log ( "-- RESPONDING" ) ;
181- console . log ( { chatId : chat . id , lastMessageId : lastMessage . id } ) ;
182175 return {
183176 chatId : chat . id ,
184177 lastMessageId : lastMessage . id ,
@@ -209,73 +202,3 @@ export async function createMessage(
209202
210203 return newMessage ;
211204}
212-
213- export async function getNextCompletionStreamPromise (
214- messageId : string ,
215- model : string ,
216- ) {
217- console . log ( "getNextCompletionStreamPromise: start" ) ;
218- console . log ( { messageId, model } ) ;
219- let message ;
220- try {
221- message = await prisma . message . findUniqueOrThrow ( {
222- where : { id : messageId } ,
223- } ) ;
224- } catch ( error ) {
225- console . log ( "IN ERROR BLOCK" ) ;
226- console . log ( error ) ;
227- }
228- console . log ( "-- getNextCompletionStreamPromise: Found message " , message ?. id ) ;
229- // if (!message) notFound();
230-
231- // const messagesRes = await prisma.message.findMany({
232- // where: { chatId: message.chatId, position: { lte: message.position } },
233- // orderBy: { position: "asc" },
234- // });
235- // console.log("-- getNextCompletionStreamPromise: found messages");
236-
237- // let messages = z
238- // .array(
239- // z.object({
240- // role: z.enum(["system", "user", "assistant"]),
241- // content: z.string(),
242- // }),
243- // )
244- // .parse(messagesRes);
245- // console.log("-- getNextCompletionStreamPromise: parsed messages");
246-
247- // if (messages.length > 10) {
248- // messages = [messages[0], messages[1], messages[2], ...messages.slice(-7)];
249- // }
250-
251- // let options: ConstructorParameters<typeof Together>[0] = {};
252- // if (process.env.HELICONE_API_KEY) {
253- // options.baseURL = "https://together.helicone.ai/v1";
254- // options.defaultHeaders = {
255- // "Helicone-Auth": `Bearer ${process.env.HELICONE_API_KEY}`,
256- // "Helicone-Property-appname": "LlamaCoder",
257- // "Helicone-Session-Id": message.chatId,
258- // "Helicone-Session-Name": "LlamaCoder Chat",
259- // };
260- // }
261-
262- // console.log("getNextCompletionStreamPromise: creating together client");
263- // const together = new Together(options);
264-
265- // console.log("getNextCompletionStreamPromise: returning stream");
266- // return {
267- // streamPromise: new Promise<ReadableStream>(async (resolve) => {
268- // console.log("getNextCompletionStreamPromise: querying together");
269- // const res = await together.chat.completions.create({
270- // model,
271- // messages: messages.map((m) => ({ role: m.role, content: m.content })),
272- // stream: true,
273- // temperature: 0.2,
274- // max_tokens: 9000,
275- // });
276-
277- // console.log("getNextCompletionStreamPromise: resolving promise");
278- // resolve(res.toReadableStream());
279- // }),
280- // };
281- }
0 commit comments